添加源

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

导入key后更新

wget http://ftp.openvz.org/debian/archive.key
apt-key add archive.key
apt update

配置内核参数

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

让修改立刻生效:

sysctl -p

安装

64位系统用这个

apt install -y linux-image-openvz-amd64 vzctl vzquota ploop vzstats

32位系统用这个

apt install -y linux-image-openvz-686 vzctl vzquota ploop vzstats

进入openvz内核

重启,在grub中选择"advance options for ubuntu"进入后可找到带着openvz的行(有可能不止一个,选第一个就是了)

使用

创建并初始化虚拟机

创建虚拟机需要下载系统模板,会用很多流量(多么痛的领悟~)

#创建虚拟机,编号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

创建的虚拟机可以用这个命令查看:

vzlist -a

启动

vzctl restart 102

关闭

vzctl stop 102

删除

vzctl destroy 102

查看资源占用

vzcalc -v 102

网络配置

#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

参考文章

http://blog.topspeedsnail.com/archives/3720

https://www.ahao.me/archives/1009

Ubuntu 14.4 安装OpenVZ的更多相关文章

  1. 在Ubuntu 14.04安装和使用Docker

    Docker是一个开源软件,它可以把一个Linux应用和它所依赖的一切(比如配置文件)都封装到一个容器.然而,Docker与虚拟机不同,它使用了沙箱机制,Docker容器不运行操作系统,它共享主机上的 ...

  2. [转]在Ubuntu 14.04安装和使用Docker

    在Ubuntu 14.04安装和使用Docker 作者:chszs,版权所有,未经同意,不得转载.博主主页:http://blog.csdn.net/chszs Docker是一个开源软件,它可以把一 ...

  3. Ubuntu 14.04 安装VMware 12

    /*********************************************************************** * Ubuntu 14.04 安装VMware 12 ...

  4. Ubuntu 14 编译安装 PHP 5.4.45 + Nginx 1.4.7 + MySQL 5.6.26 笔记

    Ubuntu 14 编译安装 PHP 5.4.45 + Nginx  1.8.0/1.4.7 + MySQL 5.6.26 笔记,主要是给自己的PC机安装,非生产环境! 一.下载必要的源码 1.1.下 ...

  5. Ubuntu 14.10安装SecureCRT 7.3

    Ubuntu 14.10下安装SecureCRT 7.3 1.软件准备 Ubuntu14.10 x64 SecureCRT7.3的版本:scrt-7.3.0-657.ubuntu13-64.x86_6 ...

  6. Ubuntu 14.04安装Chromium浏览器并添加Flash插件Pepper Flas

    转自Ubuntu 14.04安装Chromium浏览器并添加Flash插件Pepper Flash Player Chromium谷歌的开源浏览器将不再支持Netscape浏览器插件API,Adobe ...

  7. ubuntu 14.04 安装搜狗拼音输入法

    原文:ubuntu 14.04 安装搜狗拼音输入法 ubuntu桌面系统下终于有了好用的拼音法-搜狗拼音输入法,欲在ubuntu 14.04下安装搜狗拼音输入法相当的简单. 先到搜狗拼音官网下载对应的 ...

  8. ubuntu 14.04 安装torch及编译环境zbstudio

    ubuntu 14.04 安装torch及编译环境zbstudio torch zbstudio 本来是安装官网给的步骤安装torch的,可是碰到一系列的问题,后来参考网上的安装方法安装成功了 官网安 ...

  9. ubuntu 14.04 安装svn server (subversionedge )

    ubuntu 14.04 安装subversionedge 请仔细阅读安装包自带的readme文件! 1.先去官网,找安装包: http://subversion.apache.org/ http:/ ...

随机推荐

  1. 日志插件 log4net 的配置和使用

    文本格式说明 可以记载的日志类别包括:FATAL(致命错误).ERROR(一般错误).WARN(警告).INFO(一般信息).DEBUG(调试信息). 文本参数说明 %m(message):输出的日志 ...

  2. 常用gui软件使用技巧

    xmind powerdesinger notepad++ firefox office ========================================= win10企业版安装 xm ...

  3. js 数字数组按大小排序

    var num = [7,8,6,5,2] //倒序排列 num.sort((a,b)=>{return b-a}) //正序排列 num.sort((a,b)=>{return a-b} ...

  4. Python random模块sample、randint、shuffle、choice随机函数

    一.random模块简介 Python标准库中的random函数,可以生成随机浮点数.整数.字符串,甚至帮助你随机选择列表序列中的一个元素,打乱一组数据等. 二.random模块重要函数 1 ).ra ...

  5. chrome自定义ua(批处理文件方式)

    新建bat文件,输入如下代码: @echo off start chrome.exe --user-agent="你自定义的ua字符串" EXIT 保存后运行bat文件. 这个时候 ...

  6. RedHat6.5安装Spark单机

    版本号: RedHat6.5   RHEL 6.5系统安装配置图解教程(rhel-server-6.5) JDK1.8      http://blog.csdn.net/chongxin1/arti ...

  7. How to set up github to work with Visual Studio 2013

    http://michaelcrump.net/setting-up-github-to-work-with-visual-studio-2013-step-by-step/ 1. Create gi ...

  8. 下载goland解压错误

    把连接里面的 download.jetbrains.8686c.com 换成 download-cf.jetbrains.com

  9. 黄聪:PHP调试显示所有错误信息

    ini_set('display_errors',1); //错误信息 ini_set('display_startup_errors',1); //php启动错误信息 error_reporting ...

  10. PHP ==与===的区别

    PHP中==与===的区别 ===是恒等计算符 同时检查表达式的值与类型 ==是比较运算符号 不会检查条件式的表达式的类型