lxc_manager_node/README.md

84 lines
2.4 KiB
Markdown

# lxc_manager_node
This has been tested on **clean** install of ubuntu 14.04 64bit.
## install
Update you system to the newest packages and reboot. You may need to do this several times:
```bash
sudo apt-get update && sudo apt-get upgrade && sudo reboot
```
Once there are no more updates, add the `virt` user:
```bash
sudo adduser virt
```
Make the password something strong, and remember it.
Now you can install the packages we need:
```bash
sudo apt-get install git nodejs npm lxc redis-server
```
remap `nodejs` to `node`:
```bash
sudo ln -s /usr/bin/nodejs /usr/bin/node
```
And install the node packages:
```bash
sudo npm install -g forever
```
give the `virt` user network access:
```bash
echo "virt veth lxcbr0 1024" | sudo tee -a /etc/lxc/lxc-usernet
```
lets set up the config file for the `virt` user, first switch users:
```bash
su virt
```
The lines below will add the proper config file:
```bash
mkdir -p ~/.config/lxc
echo "lxc.id_map = u 0 `grep -oP '^virt:\K\d+' /etc/subuid` `grep -oP '^virt:\d+:\K\d+' /etc/subuid`" > ~/.config/lxc/default.conf
echo "lxc.id_map = g 0 `grep -oP '^virt:\K\d+' /etc/subgid` `grep -oP '^virt:\d+:\K\d+' /etc/subgid`" >> ~/.config/lxc/default.conf
echo "lxc.network.type = veth" >> ~/.config/lxc/default.conf
echo "lxc.network.link = lxcbr0" >> ~/.config/lxc/default.conf
```
Its safer at this point to reboot the system, `exit` back to the privlaged user and `reboot`
**SSH or log dercily into the `virt` user!!!** this will not if you use su!
Now you can can create a test container:
```bash
lxc-create -t download -n test-ubuntu -- -d ubuntu -r trusty -a amd64
```
start and attach the container to make sure everthing is ok:
```bash
lxc-start -n test-ubuntu -d
lxc-attach -n test-ubuntu
```
If everything worked you can stop and delete the container
```bash
lxc-stop -n test-ubuntu
lxc-destroy -n test-ubuntu
```
```bash
sudo add-apt-repository ppa:ubuntu-lxc/daily
sudo add-apt-repository ppa:ubuntu-lxc/cgmanager-stable
```
# auto start
## crontab
```bash
@reboot forever start -c '/usr/bin/nodemon -e js,ejs' -a -o /home/virt/manager/proxy.out.log -e /home/virt/manager/proxy.err.log /home/virt/manager/bin/www
@reboot /usr/bin/forever start -o /home/virt/manager/proxy.out.log -e /home/virt/manager/proxy.err.log /home/virt/manager/app.js
```
##rc.local
```bash
sudo cgm create all virt
sudo cgm chown all virt $(id -u virt) $(id -g virt)
```