linux虚拟化之openvz

系统环境:

[root@openvz ~]# cat /etc/redhat-release
CentOS release 6.5 (Final)
[root@openvz ~]#  uname -a
Linux openvz 2.6.32-431.el6.x86_64 #1 SMP Fri Nov 22 03:15:09 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
[root@openvz ~]# lsb_release -a
LSB Version:    :base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch
Distributor ID: CentOS
Description:    CentOS release 6.5 (Final)
Release:    6.5
Codename:   Final

开始安装:

[root@openvz ~]# cd /etc/yum.repos.d/
[root@openvz yum.repos.d]# wget -P /etc/yum.repos.d/ http://ftp.openvz.org/openvz.repo
[root@openvz yum.repos.d]# rpm --import http://ftp.openvz.org/RPM-GPG-Key-OpenVZ
[root@openvz yum.repos.d]# yum install vzkernel
[root@openvz yum.repos.d]# echo "SELINUX=disabled" > /etc/sysconfig/selinux
[root@openvz yum.repos.d]# cat /etc/sysctl.conf |grep -v "#"|grep -v ^$
net.ipv4.ip_forward = 1
net.ipv6.conf.default.forwarding = 1
net.ipv6.conf.all.forwarding = 1
net.ipv4.conf.default.proxy_arp = 0
net.ipv4.conf.all.rp_filter = 1
net.ipv4.conf.default.send_redirects = 1
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
kernel.sysrq = 1
kernel.core_uses_pid = 1
net.ipv4.tcp_syncookies = 1
net.bridge.bridge-nf-call-ip6tables = 0
net.bridge.bridge-nf-call-iptables = 0
net.bridge.bridge-nf-call-arptables = 0
kernel.msgmnb = 65536
kernel.msgmax = 65536
kernel.shmmax = 68719476736
kernel.shmall = 4294967296
[root@openvz yum.repos.d]# sysctl -p
[root@openvz yum.repos.d]# yum install vzctl vzquota ploop
[root@openvz yum.repos.d]# reboot

openvz安装完成


下载系统模板

模板在这里http://openvz.org/Download/template/cache

[root@openvz ~]# uname -a
Linux openvz 2.6.32-042stab085.20 #1 SMP Fri Mar 21 19:07:05 MSK 2014 x86_64 x86_64 x86_64 GNU/Linux
[root@openvz ~]# cd /vz/template/cache/
[root@openvz cache]# wget http://download.openvz.org/template/precreated/centos-5-x86.tar.gz
[root@openvz cache]# vzctl create 1 --ostemplate centos-5-x86
[root@openvz cache]# vzctl set 1 --onboot yes --save
[root@openvz cache]# vzctl set 1 --ipadd 172.16.10.21 --save
[root@openvz cache]# vzctl set 1 --nameserver 114.114.114.114 --save
[root@openvz cache]# vzctl set 1 --hostname centos5.nowsafe.org --save
[root@openvz cache]# vzctl set 1 --diskspace 10G:10G --save
[root@openvz cache]# vzctl start 1     启动为1的虚拟机
Starting container...
Container is mounted
Adding IP address(es): 172.16.10.21
Setting CPU units: 1000
Container start in progress...
[root@openvz cache]# vzctl exec 1 passwd        修改序号为1的虚拟机ROOT密码
New UNIX password: redhat
BAD PASSWORD: it is based on a dictionary word
Retype new UNIX password: redhat
Changing password for user root.
passwd: all authentication tokens updated successfully.
[root@openvz cache]# vzlist                     查看序号为1的虚拟机
      CTID      NPROC STATUS    IP_ADDR         HOSTNAME
         1         21 running   172.16.10.21    centos5.nowsafe.org
             
[root@openvz cache]# vzcalc -v 1 查看序号1 占用的资源
[root@openvz cache]# ping 172.16.10.21
PING 172.16.10.21 (172.16.10.21) 56(84) bytes of data.
64 bytes from 172.16.10.21: icmp_seq=1 ttl=64 time=0.276 ms
64 bytes from 172.16.10.21: icmp_seq=2 ttl=64 time=0.041 ms
[root@openvz cache]# vzctl enter 1        进入 guest 相当于 xen 的 xm console ,不过从 guest 退出来不需特殊按键直接 exit 就可以退出
entered into CT 1
[root@centos5 /]# uname -a
Linux centos5.nowsafe.org 2.6.32-042stab085.20 #1 SMP Fri Mar 21 19:07:05 MSK 2014 i686 i686 i386 GNU/Linux
[root@centos5 /]# cat /etc/redhat-release
CentOS release 5.10 (Final)

OK大概先到这里

本文出自 “devops” 博客,谢绝转载!

你可能感兴趣的:(linux,VPN,openvz,vps)