当前位置:首页 > CN2资讯 > 正文内容

OPenVZ实验配置过程

3天前CN2资讯

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

二、安装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

  /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 --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...

    你可能想看:

    扫描二维码推送至手机访问。

    版权声明:本文由皇冠云发布,如需转载请注明出处。

    本文链接:https://www.idchg.com/info/19183.html

    分享给朋友:

    “OPenVZ实验配置过程” 的相关文章

    甲骨文注册流程详解:成功申请的关键步骤与技巧

    甲骨文(Oracle Cloud)的注册流程看似复杂,但只要事先做好准备,整个过程其实非常顺利。我自己在注册时感受到了这一点,以下就是我想和大家分享的步骤和经验。 申请前的准备工作 在我们开始注册之前,有几个准备工作是必须要做的。首先,创建一个国际邮箱是至关重要的。虽然国内的邮箱也可以使用,但我推荐...

    IEPL:企业国际以太网专线的优势与申请指南

    什么是IEPL 当我第一次接触IEPL(International Ethernet Private Line)时,我意识到它是一种为企业提供国际级别的网络连接服务,特别适合那些需要在不同国家和地区之间高效、安全传输数据的公司。这项服务一般由电信运营商提供,旨在帮助企业实现及时的信息交流和数据传输。...

    使用Win10一键安装脚本轻松安装SQLite数据库

    一键安装脚本的定义与作用 首先,Win10一键安装脚本是一个自动化脚本,用于在Windows 10操作系统中快速部署和安装程序。想象一下,平时我需要为新安装的系统配置各种软件和工具,单单是手动下载和安装每个程序就已经让我感到疲惫。通过一键安装脚本,我只需要运行一个脚本,就能完成一系列的安装任务。这种...

    腾讯云国际版:全球云服务的强者之选,满足您的业务需求

    腾讯云国际版概述 腾讯云国际版的定义与背景 腾讯云国际版是腾讯公司专为全球客户推出的一款云服务产品,旨在满足不同国家和地区用户的需求。它在功能上与国内版本相似,但根据国际市场的需求进行了优化,以确保服务的稳定性和流畅性。作为一名用户,我发现腾讯云国际版特别注重数据隐私和合规性,这对于希望拓展海外市场...

    土耳其Netflix IP限制解析与绕过方法

    在今天的流媒体时代,Netflix已成为全球用户娱乐生活中不可或缺的一部分。尤其是在土耳其,Netflix的受欢迎程度如火如荼,越来越多的人选择在闲暇时观看各种影视作品。这种趋势不仅仅反映了高质量内容的吸引力,也显示出土耳其观众对多元文化的渴望。然而,尽管Netflix提供了丰富的选择,用户也频繁遭...

    KVM是什么?深入了解Kernel-based Virtual Machine的功能与应用

    在谈论KVM之前,我们有必要了解它的基本定义和起源。KVM,全称为Kernel-based Virtual Machine,这是一种虚拟化技术,可以让我们在一台物理机器上运行多个虚拟机。KVM的设计是基于Linux内核的,因此,它能够充分利用Linux的强大功能。它首次出现在2006年,随着Linu...