騰訊雲安裝openvz,高速搭建測試環境

CSDN送了騰訊雲的測試資格,準備拿來做爲cici的軟件公佈首頁,想在上面作個demo,無奈沒有設備環境,因而想要用openvz來虛擬一些vps:html

第一步:選擇騰訊雲的os模板,centos6.3python

第二步:安裝openvz           安裝方法參見:http://openvz.org/Quick_installationubuntu

第三步:下載os模板,建立4個vps,各自是ubutnu centos6.5 suse centos7.0centos

第四步:開啓vps網絡

這裏發現vps上不了網,預計是騰訊對nat的源地址作了限制,沒有網絡的vps可很差玩。因而在雲主機上作個nat,過程例如如下:tcp

一、新建一個網卡,配上本身的地址ui

 eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 52:54:00:3b:54:96 brd ff:ff:ff:ff:ff:ff
    inet x.x.x.x/22 brd 10.221.31.255 scope global eth0
    inet 192.168.100.100/24 brd 192.168.100.255 scope global eth0:0
    inet6 fe80::5054:ff:fe3b:5496/64 scope link 
       valid_lft forever preferred_lft forever

這裏是192.168.100.100/24,新建一個配置文件

[root@HN network-scripts]# cat ifcfg-eth0:0
DEVICE='eth0:0'
NM_CONTROLLED='yes'
ONBOOT='yes'
IPADDR='192.168.100.100'
NETMASK='255.255.255.0'

二、配置iptables

# Generated by iptables-save v1.4.7 on Fri Aug  8 11:51:29 2014
*nat
:PREROUTING ACCEPT [0:0]
:POSTROUTING ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
<strong>-A POSTROUTING -o eth0 -j MASQUERADE</strong>
COMMIT
# Completed on Fri Aug  8 11:51:29 2014
# Generated by iptables-save v1.4.7 on Fri Aug  8 11:51:29 2014
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [40:5190]
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
#-A INPUT -j REJECT --reject-with icmp-host-prohibited
#-A FORWARD -j REJECT --reject-with icmp-host-prohibited
<strong>-A FORWARD -i eth0:0 -j ACCEPT</strong>
COMMIT

vi /etc/sysctl.conf    將  net.ipv4.ip_forward = 1
創建nat假裝
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE    (eth0爲外網)
創建轉發:
iptables -A  FORWARD -i eth0:0  -j ACCEPT   (eth0爲內網網關)
保存iptables配置:
service iptables save


假設openvz是最新版本號,可能nat列表沒法初始化,解決的方法http://yzs.me/2222.htmlcentos7

改動/etc/modprobe.d/openvz.conf,code

把options nf_conntrack ip_conntrack_disable_ve0=1

改動爲:htm

options nf_conntrack ip_conntrack_disable_ve0=0


三、進入vps查看效果

建立vps: vzctl create 101 --ostemplate ubuntu-14.04-x86_64 --hostname ubu-101 --ipadd 192.168.100.101/24

vzctl start 101

vzctl enter 101

root@ubu-101:/# ping www.sina.com
PING ara.sina.com.cn (58.63.236.33) 56(84) bytes of data.
64 bytes from 58.63.236.33: icmp_seq=1 ttl=51 time=8.21 ms
64 bytes from 58.63.236.33: icmp_seq=2 ttl=51 time=8.27 ms
64 bytes from 58.63.236.33: icmp_seq=3 ttl=51 time=8.33 ms
64 bytes from 58.63.236.33: icmp_seq=4 ttl=51 time=8.25 ms
OK  可以上網了
相關文章
相關標籤/搜索