繼上篇,說明了OpenVZ如何安裝,但想必大家一定霧剎剎!
所以這篇就會拿OpenVZ這個VPS container管理程式來做一些較真實的事情囉~
繼續看下去吧~
基本操作
請參考 http://openvz.org/Basic_operations_in_OpenVZ_environment
[openvz]# vzctl create CTID --ostemplate osname
[openvz]# vzctl set CTID --ipadd a.b.c.d --save
[openvz]# vzctl set CTID --nameserver a.b.c.d --save
[openvz]# vzctl start CTID
Here CTID is the numeric ID for the container; osname is the name of the OS template for the container, and a.b.c.d is the IP address to be assigned to the container.
嗯,寫的再清楚不過了。
操作一次試試
[root@openvz vz]# vzctl create 101 --ostemplate ubuntu-12.04-x86
Creating container private area (ubuntu-12.04-x86)
Performing postcreate actions
CT configuration saved to /etc/vz/conf/101.conf
Container private area was created
[root@openvz vz]# vzctl set 101 --ipadd 10.1.2.3 --save
CT configuration saved to /etc/vz/conf/101.conf
[root@openvz vz]# vzctl set 101 --nameserver 10.0.2.1 --save
CT configuration saved to /etc/vz/conf/101.conf
[root@openvz vz]# vzctl start 101
Starting container...
Container is mounted
Adding IP address(es): 10.1.2.3
Setting CPU units: 1000
Container start in progress...
以上應該可以看出這一台101號GuestOS的設定檔是放在/etc/vz/conf/101.conf
進入該虛擬機器
[root@openvz vz]# vzctl enter 101
entered into CT 101
觀察一下,嗯,結果跟上面的設定檔內容很像!
root@openvz:/# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/simfs 2.0G 364M 1.7G 18% /
none 128M 4.0K 128M 1% /dev
none 26M 980K 25M 4% /run
none 5.0M 0 5.0M 0% /run/lock
none 128M 0 128M 0% /run/shm
root@openvz:/# mount
/vz/private/101 on / type simfs (rw,relatime)
proc on /proc type proc (rw,relatime)
sysfs on /sys type sysfs (rw,relatime)
none on /dev type devtmpfs (rw,nosuid,noexec,relatime,mode=755)
none on /dev/pts type devpts (rw,nosuid,noexec,relatime,mode=600,ptmxmode=000)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw,nosuid,nodev,noexec,relatime)
none on /run type tmpfs (rw,nosuid,noexec,relatime,size=26216k,mode=755)
none on /run/lock type tmpfs (rw,nosuid,nodev,noexec,relatime,size=5120k)
none on /run/shm type tmpfs (rw,relatime)
root@openvz:/# free
total used free shared buffers cached
Mem: 262144 27792 234352 0 0 16500
-/+ buffers/cache: 11292 250852
Swap: 524288 0 524288
離開該虛擬機器
root@openvz:/# exit
logout
exited from CT 101
另外還有這一些~
#vzctl stop 101
#vzctrl destory 101
看指令的參數應該不難看出來功能吧~
當然也可以用man去查指令的用法囉
#man vzctl
有一個比較特殊的地方,就是在沒有新增GuestOS(101)時,
vz服務在開機時不會自動啟動,所以要先手動開啟才能新增GuestOS(101)
而在新增完GuestOS(101)後,重開機後,發現vz服務會自動啟動。
另外CTID的值在manpage中有寫到,好像也不能用英文
Note that CT ID <= 100 are reserved for OpenVZ internal purposes.