OPenVZ实验配置过程

说明:这是本人在学习VPS做实验时的记录,也是本人第一次在51cto发表文章.不妥之处,欢迎交流.

二、安装OpenVZ

 NO1:

cd /etc/yum.repos.d

 [root@localhost ~]# wget http://download.openvz.org/openvz.repo
--2011-11-03 09:24:52-- http://download.openvz.org/openvz.repo
Resolving download.openvz.org... 64.131.90.11
Connecting to download.openvz.org|64.131.90.11|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2205 (2.2K) [text/plain]
Saving to: `openvz.repo'

100%[======================================================================================>] 2,205 --.-K/s in 0s

2011-11-03 09:24:53 (149 MB/s) - `openvz.repo' saved [2205/2205]

 然后根据你所使用的Linux版本,修改openvz.repo文件。
 

[openvz-kernel-rhel5]
name=OpenVZ RHEL5-based kernel
#baseurl=http://download.openvz.org/kernel/branches/rhel5-2.6.18/current/
mirrorlist=http://download.openvz.org/kernel/mirrors-rhel5-2.6.18
enabled=1
gpgcheck=1
gpgkey=http://download.openvz.org/RPM-GPG-Key-OpenVZ

 NO2:[root@localhost ~]# rpm -import http://download.openvz.org/RPM-GPG-Key-OpenVZ

 NO3.[root@localhost ~]# yum search vzkernel

 NO4.[root@localhost ~]# yum install ovzkernel

 NO5.执行安装后,会发现在grub.conf中多了一项引导:

title OpenVZ (2.6.18-274.3.1.el5.028stab094.3)
root (hd0,0)
kernel /vmlinuz-2.6.18-274.3.1.el5.028stab094.3 ro root=LABEL=/ rhgb quiet selinux=0
initrd /initrd-2.6.18-274.3.1.el5.028stab094.3.img

 vi /boot/grub/menu.lst //可以设置默认引导为OpenVZ (2.6.18-274.3.1.el5.028stab094.3)

 NO6.安装管理工具

 root@localhost ~]# yum install vzctl vzquota

 三、修改参数 Setting sysctl parameters

vim /etc/sysctl.conf

 # On Hardware Node we generally need

# packet forwarding enabled and proxy arp disabled

net.ipv4.ip_forward = 1

net.ipv4.conf.default.proxy_arp = 0

# Enables source route verification

net.ipv4.conf.all.rp_filter = 1

# Enables the magic-sysrq key

kernel.sysrq = 1

# TCP Explict Congestion Notification

#net.ipv4.tcp_ecn = 0

# we do not want all our interfaces to send redirects

net.ipv4.conf.default.send_redirects = 1

net.ipv4.conf.all.send_redirects = 0

net.ipv4.icmp_echo_ignore_broadcasts=1

net.ipv4.conf.default.forwarding=1

 

修改上面的文件后,执行# sysctl -p

 

四、配置OpenVZ

 1.vi /etc/vz/vz.conf

加入下面一行:

 NEIGHBOUR_DEVS=all

 2.关闭selinux

vi /etc/sysconfig/selinux

 3.重启计算机

不论是否修改了SELinux,OpenVZ安装后都需要重新启动,然后在Grub菜单中,选择“OpenVZ (2.6.18-274.3.1.el5.028stab094.3)”引导。

  

五、使用 OpenVZ

 1.到http://wiki.openvz.org/Download/template/precreated下载OS的模板文件,需要虚拟出什么类型的系统,就下载对应的模板。保存到/vz/template/cache

 cd /vz/template/cache

wget http://download.openvz.org/template/precreated/contrib/centos-5-i386-default.tar.gz

 2.创建VPS

#vzctl create 101 --ostemplate centos-5-i386-default --config vps.basic

 # vzctl create 101 --ostemplate centos-6-x86 --config vswap-256m

 说明:centos-6-x86为你所下载的模板文件的名称(我下载的为centos-6-x86.tar.gz)(除去末尾的.tar.gz);vswap-256m或vps.basic 为/etc/vz/conf中配置文件名称的一部分,如下:

 [root@localhost ~]# ls /etc/vz/conf/
0.conf ve-basic.conf-sample ve-unlimited.conf-sample ve-vswap-256m.conf-sample
101.conf ve-light.conf-sample ve-vswap-1024m.conf-sample ve-vswap-512m.conf-sample

 

#vzctl set 101 --onboot yes --save //设置开机启动

 #vzctl set 101 --hostname test.example.com --save //设置主机名

 #vzctl set 101 --ipadd 192.168.0.101 --save //设置IP

 #vzctl set 101 --numothersock 120 --save

 #vzctl set 101 --nameserver 192.168.0.101--save

 

#vzctl start 101

 

#vzctl enter 101 //在主机进入虚拟机

 

# vzctl set 101 --userpasswd root:test

 

Deleting Virtual Private Server

 

# vzctl destroy 101
VPS is currently mounted (umount first)
# vzctl stop 101
Stopping VPS ...
VPS was stopped
VPS is unmounted
# vzctl destroy 101
Destroying VPS private area: /vz/private/101
VPS private area was destroyed
# ls /etc/sysconfig/vz-scripts/101.*
/etc/sysconfig/vz-scripts/101.conf.destroyed
/etc/sysconfig/vz-scripts/101.mount.destroyed
/etc/sysconfig/vz-s
cripts/101.umount.destroyed # vzctl status 101
VPS 101 deleted unmounted down

 

# vzctl exec 101 /etc/init.d/sshd status

sshd is stopped # vzctl exec 101 /etc/init.d/sshd start

Starting sshd:[ OK ] # vzctl exec 101 /etc/init.d/sshd status

sshd (pid 26187) is running...

 

 提高

 

1.在创建vps时使用默认的参数(--ostemplate  --config )

修改/etc/vz/vz.conf,

用下面两行代替配置文件中相应项:

DEF_OSTEMPLATE="centos-6-x86"            //你所下载的模板文件名,除掉.tar.gz
CONFIGFILE="vswap-256m"                  /// /etc/vz/conf目录中,你所想用的sample文件中的一个,注意只取文件名去掉ve和conf-sample的部分。

 

# vzctl start 101
[This command starts VPS 101, if it is not started yet]
# vzctl exec 101 service sshd status
sshd is stopped # vzctl exec 101 service sshd start
Starting sshd: [ OK ]
# vzctl exec 101 service sshd status
sshd (pid 16036) is running...

你可能感兴趣的:(职场,休闲,cd)