openVZ
山东大学 计算机科学与技术 学院
云计算技术 课程实验报告
学号:202000130199 | 姓名: 荆树吉 | 班级: 20数据 |
---|
实验题目:操作系统虚拟化 OpenVZ |
---|
实验学时:2 | 实验日期: 2023.4.18 |
---|
实验目的:在Linux环境下,熟悉OpenVZ虚拟化。 具体包括:自行了解OpenVZ虚拟化技术,完成实验环境及实验工具的熟悉,包括安装和配置OpenVZ,了解如何创建容器等,撰写实验报告。 |
---|
硬件环境: 联网的计算机一台 |
---|
软件环境:Linux |
---|
实验步骤与内容:
1.添加源
vim /etc/apt/sources.list.d/openvz.list
写入下面内容保存
如果需要,可以视情况改动注释.
deb http://download.openvz.org/debian wheezy main
# deb http://download.openvz.org/debian wheezy-test main
2.导入key后更新
wget http://ftp.openvz.org/debian/archive.key
apt-key add archive.key
apt update
3. 配置内核参数
vim /etc/sysctl.conf
配置这些项:
# On Hardware Node we generally need
# packet forwarding enabled and proxy arp disabled
net.ipv4.ip_forward = 1
net.ipv6.conf.default.forwarding = 1
net.ipv6.conf.all.forwarding = 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
# We do not want all our interfaces to send redirects
net.ipv4.conf.default.send_redirects = 1
net.ipv4.conf.all.send_redirects = 0
4.让修改立刻生效:
sysctl -p
5.安装64位系统用这个
apt install -y linux-image-openvz-amd64 vzctl vzquota ploop vzstats
6.进入openvz内核
重启,在grub中选择”advance options for ubuntu”进入后可找到带着openvz的行(有可能不止一个,选第一个就是了)
7.使用
① 创建并初始化虚拟机
创建虚拟机需要下载系统模板
#创建虚拟机,编号102 参数是:虚拟机编号 –ostemplate 系统模板
vzctl create 102 –ostemplate debian-7.0-x86-minimal
#设置主机名称
vzctl set 102 –hostname “vz102” –save
#限制CPU
vzctl set 102 –cpuunits 1000 –cpulimit 50 –save
#限制I/O
vzctl set 102 –iolimit 5M –save
#设置内存和swap
vzctl set 102 –ram 64M –swap 0G –save
#设置硬盘大小 参数:编号 –diskspace 软限制:硬限制 –save
vzctl set 102 –diskspace 64M:5G –save
#设置ip
vzctl set 102 –ipadd 192.168.0.2 –save
#设定dns服务器
vzctl set 102 –nameserver 8.8.8.8 –nameserver 8.8.4.4 –save
#设置root用户密码(需要Cgroup)
vzctl set 102 –userpasswd root:passwd
#主机开机时自动运行虚拟机,酌情使用
vzctl set 102 –onboot yes –save
② 启动
vzctl restart 102
③ 关闭
vzctl stop 102
④ 删除
vzctl destroy 102
⑤ 查看资源占用
vzcalc -v 102
8.网络配置
#Clear All configure
iptables -F
iptables -F -t nat
#let the computer can to forward data
iptables -A FORWARD -j ACCEPT
#这行是打通nat功能,让vps能通过host的ip发送数据到外网,外网也能返回数据,要改两个地方:网卡和最后的ip
iptables -t nat -A POSTROUTING -o eth0 -j SNAT –to 主机对外的ip
#这行是端口转发,把ssh端口打通一下
iptables -t nat -A PREROUTING -p tcp -m tcp –dport 10222 -j DNAT –to-destination 192.168.0.2:22
结论分析与体会:
优势:外面卖的这种类型,许可的内存都超大,CPU也强劲,而且卖家很多,可比性也很强。性价比超高。
劣势:超卖,没有不超卖的,导致各种石头盘,钻石盘。连带的cpu也被过度分割导致性能升值不如其标明的1/10。再有就是内存,基本上OpenVZ技术没有独占的,都是共享,别人多了你就少了,而且这种技术最大的劣势就是内存下来后直接就是当机。还有开设vpn各种不方便