Skip to content
Hirochika Asai edited this page Apr 23, 2015 · 19 revisions

Welcome to the OpenPaaS wiki!

How to use Linux Container

Install LXC on Ubuntu

# apt-get install lxc lxctl

# lxc-ls --fancy

Create a new instance (ubuntu)

# lxc-create -n <instance-name> -t ubuntu

The filesystem of the instance is located at /var/lib/lxc//rootfs. If you prefer to change the (pseudo) hardware configuration of an instance, you can edit /var/lib/lxc//config.

Default network configuration

If you prefer to use another network (bridge) for your network, you can edit the default configuration of LXC.

# edit /etc/lxc/default.conf

- lxc.network.link = lxcbr0
+ lxc.network.link = br0

List all instances

# lxc-ls --fancy

NAME       STATE    IPV4  IPV6  AUTOSTART  
-----------------------------------------
repository STOPPED  -     -     NO       

Start/Attach an instance

To start an instance, you can type: # lxc-start -n <instance-name> -d

-n option specifies the name of the instance, and -d means the started instance will be detached. If you do not specify -d option, Ctrl-C will halt the instance, so -d is recommended to be specified.

To attach the console of the instance, you can type: # lxc-console -n repository

Installation

PaaS node

# apt-get install lxc lxctl

# edit /etc/lxc/default.conf

- lxc.network.link = lxcbr0
+ lxc.network.link = br0

# lxc-checkconfig

# lxc-create -n repository -t ubuntu

# lxc-ls --fancy

NAME       STATE    IPV4  IPV6  AUTOSTART  
-----------------------------------------
repository STOPPED  -     -     NO       

# lxc-start -n repository -d

# lxc-console -n repository

$ passwd

# edit /etc/ssh/sshd_config

# service ssh restart

# edit /etc/network/interfaces

Repository

# apt-get install git gitolite

# apt-get install apache2 mysql-server mysql-client libmysqlclient-dev nodejs
# apt-get install ruby-passenger libapache2-mod-passenger
# apt-get install ruby ruby-dev make zlib1g-dev
# gem install rails


# git config --global push.default simple
# edit keydir/ins.pub
# git add keydir/ins.pub

# edit conf/gitolite.conf
repo    gitolite-admin
        RW+     =   admin

repo    testing
        RW+     =   admin
        R       =   ins

# visudo
Defaults env_keep +="OPLAT_GITOLITE_HOME"
Defaults env_keep +="OPLAT_GITOLITE_REPOSITORY"
Defaults env_keep +="OPLAT_GITOLITE_USER"
Defaults env_keep +="OPLAT_GIT_REPOSITORIES"
Defaults env_keep +="OPLAT_EXT_DATABASE_HOST"
Defaults env_keep +="OPLAT_EXT_DATABASE_USER"
Defaults env_keep +="OPLAT_EXT_DATABASE_PASSWORD"
www-data  ALL=(ALL:ALL) NOPASSWD: /path/to/repos/oplat/scripts/create_user.rb
www-data  ALL=(ALL:ALL) NOPASSWD: /path/to/repos/oplat/scripts/update_user.rb
www-data  ALL=(ALL:ALL) NOPASSWD: /path/to/repos/oplat/scripts/create_repository.rb
## Make sure that the Passenger or rails server process is launched by www-data

Template

# lxc-create -n template -t ubuntu
# lxc-start -n template -d
# lxc-console -n template
# useradd -m oplat -s /bin/bash -G sudo
# passwd oplat
# userdel ubuntu
# edit /etc/ssh/sshd_config
# service ssh restart

# apt-get install git mysql-client libmysqlclient-dev nodejs

# apt-get install ruby ruby-dev make
# gem update
# gem install rails

HTTP Load Balancer

# lxc-create -n httplb -t ubuntu
# lxc-start -n httplb -d
# lxc-console -n httplb
# useradd -m oplat -s /bin/bash -G sudo
# passwd oplat
# userdel ubuntu
# edit /etc/ssh/sshd_config
# service ssh restart

# apt-get install nginx
# edit /etc/nginx/proxy_params
proxy_set_header X-Real-IP $remote_addr;
+ proxy_set_header X-Real-Port $remote_port;

# service nginx start

Database

# lxc-create -n db -t ubuntu
# lxc-start -n db -d
# lxc-console -n db
# useradd -m oplat -s /bin/bash -G sudo
# passwd oplat
# userdel ubuntu
# edit /etc/ssh/sshd_config
# service ssh restart

# apt-get install mysql-server

mysql> grant all on *.* to oplat@'repository';
mysql> grant grant option on *.* to oplat@'repository';