在 CentOS 7 操作系统进行 OpenVZ 7 安装

/ 0评 / 0

今天带来关于OpenVZ 7 的安装博文,现使用虚拟硬件式技术的企业或个人都倾向于Vmware 或者微软的Hyper-V 使用容器式虚拟化技术的企业或个人都倾向于使用 Docker 、LXC 技术。OpenVZ 7 使用的虚拟化技术包含了 容器式与硬件式虚拟机技术,具体就是 OpenVZ 自家的容器式技术与KVM硬件式虚拟化技术,当然 Docker 也可允许在容器式虚拟机内。

1. 安装前准备

2. 一键安装脚本,包含了Fail2ban 对 SSH 22 端口的密码暴力破解保护。

<span class="hljs-meta">#!/bin/bash
</span>
<span class="hljs-comment"># Defined Var</span>
YUM=/usr/bin/yum
SED=/bin/sed
RPM=/bin/rpm
SYS=/usr/bin/systemctl

<span class="hljs-comment"># Add epel</span>

cat > /etc/yum.repos.d/epel.repo <<EOF
[epel]
name=Extra Packages <span class="hljs-keyword">for</span> Enterprise Linux 7 - \<span class="hljs-variable">$basearch</span>
<span class="hljs-comment">#baseurl=http://download.fedoraproject.org/pub/epel/7/\$basearch</span>
metalink=https://mirrors.fedoraproject.org/metalink?repo=epel-7&arch=\<span class="hljs-variable">$basearch</span>
failovermethod=priority
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7

[epel-debuginfo]
name=Extra Packages <span class="hljs-keyword">for</span> Enterprise Linux 7 - \<span class="hljs-variable">$basearch</span> - Debug
<span class="hljs-comment">#baseurl=http://download.fedoraproject.org/pub/epel/7/\$basearch/debug</span>
metalink=https://mirrors.fedoraproject.org/metalink?repo=epel-debug-7&arch=\<span class="hljs-variable">$basearch</span>
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=1

[epel-source]
name=Extra Packages <span class="hljs-keyword">for</span> Enterprise Linux 7 - \<span class="hljs-variable">$basearch</span> - Source
<span class="hljs-comment">#baseurl=http://download.fedoraproject.org/pub/epel/7/SRPMS</span>
metalink=https://mirrors.fedoraproject.org/metalink?repo=epel-source-7&arch=\<span class="hljs-variable">$basearch</span>
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=1
EOF

<span class="hljs-comment"># Add epel-testing</span>

cat > /etc/yum.repos.d/epel-testing.repo <<EOF
[epel-testing]
name=Extra Packages <span class="hljs-keyword">for</span> Enterprise Linux 7 - Testing - \<span class="hljs-variable">$basearch</span>
<span class="hljs-comment">#baseurl=http://download.fedoraproject.org/pub/epel/testing/7/\$basearch</span>
metalink=https://mirrors.fedoraproject.org/metalink?repo=testing-epel7&arch=\<span class="hljs-variable">$basearch</span>
failovermethod=priority
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7

[epel-testing-debuginfo]
name=Extra Packages <span class="hljs-keyword">for</span> Enterprise Linux 7 - Testing - \<span class="hljs-variable">$basearch</span> - Debug
<span class="hljs-comment">#baseurl=http://download.fedoraproject.org/pub/epel/testing/7/\$basearch/debug</span>
metalink=https://mirrors.fedoraproject.org/metalink?repo=testing-debug-epel7&arch=\<span class="hljs-variable">$basearch</span>
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=1

[epel-testing-source]
name=Extra Packages <span class="hljs-keyword">for</span> Enterprise Linux 7 - Testing - \<span class="hljs-variable">$basearch</span> - Source
<span class="hljs-comment">#baseurl=http://download.fedoraproject.org/pub/epel/testing/7/SRPMS</span>
metalink=https://mirrors.fedoraproject.org/metalink?repo=testing-source-epel7&arch=\<span class="hljs-variable">$basearch</span>
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=1
EOF

<span class="hljs-comment"># Import OpenVZ</span>

<span class="hljs-variable">$RPM</span> --import http://download.openvz.org/RPM-GPG-Key-OpenVZ
<span class="hljs-variable">$RPM</span> --import https://archive.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-7

<span class="hljs-variable">$YUM</span> install https://download.openvz.org/virtuozzo/releases/7.0/x86_64/os/Packages/o/openvz-release-7.0.8-4.vz7.x86_64.rpm -y

<span class="hljs-comment"># Yum Make Cache</span>

<span class="hljs-variable">$YUM</span> makecache

<span class="hljs-comment"># Yum Install Base</span>

<span class="hljs-variable">$YUM</span> install yum-plugin-priorities telnet <span class="hljs-built_in">bind</span>-utils vim-en* lrzsz wget iptables-services net-tools psmisc -y

<span class="hljs-comment"># Yum Update</span>
<span class="hljs-variable">$YUM</span> update -y 

<span class="hljs-comment"># startup network or postalias will complain error</span>
<span class="hljs-variable">$SED</span> -i <span class="hljs-string">'s/SELINUX=enforcing/SELINUX=disabled/g'</span> /etc/sysconfig/selinux
<span class="hljs-variable">$SED</span> -i <span class="hljs-string">'s/SELINUX=enforcing/SELINUX=disabled/g'</span> /etc/selinux/config

<span class="hljs-comment"># Clean UP Iptables</span>
<span class="hljs-built_in">echo</span> <span class="hljs-string">''</span> > /etc/sysconfig/iptables

<span class="hljs-comment"># Install OpenVZ</span>

<span class="hljs-variable">$YUM</span> install prlctl prl-disp-service vzkernel ploop prl-disk-tool -y

<span class="hljs-comment"># Install fail2ban</span>

<span class="hljs-variable">$YUM</span> install fail2ban fail2ban-systemd -y

<span class="hljs-comment"># Add fail2ban sshd.local</span>

cat > /etc/fail2ban/jail.d/sshd.local << EOF
[sshd]
enabled = <span class="hljs-literal">true</span>
filter = sshd
action = iptables[name=sshd-ban, port=ssh, protocol=tcp]
findtime =60
bantime = 600
maxretry = 3
EOF

<span class="hljs-variable">$SYS</span> <span class="hljs-built_in">enable</span> fail2ban

<span class="hljs-built_in">echo</span> <span class="hljs-string">"Now Reboot System"</span>
<span class="hljs-built_in">echo</span> -n <span class="hljs-string">"."</span>
sleep 1;
<span class="hljs-built_in">echo</span> -n <span class="hljs-string">"."</span>
sleep 1;
<span class="hljs-built_in">echo</span> -n <span class="hljs-string">"."</span>
sleep 1;
<span class="hljs-built_in">echo</span> -n <span class="hljs-string">"."</span>
sleep 1;
<span class="hljs-built_in">echo</span> -n <span class="hljs-string">"."</span>
sleep 1;
<span class="hljs-built_in">echo</span> -n <span class="hljs-string">"."</span>
sleep 1;
<span class="hljs-built_in">echo</span> -n <span class="hljs-string">"."</span>
sync;sync;sync;sync;
reboot

3. 简单而基本命令

UUID唯一标识                             状态         IP地址         类型 名称
UUID                                    STATUS       IP_ADDR         T  NAME
{4cc24118-b7a1-408a-9af8-caaf492e26c7}  running      192.168.1.164   CT 164
{bada9314-1050-4fe5-8865-4edf93c97c0f}  running      -               VM CentOS7
{c71d02d9-d0e4-42d0-bc1e-bcb3e8e97dc7}  stopped      -               VM MyVM
<span class="hljs-selector-tag">centos-6-x86_64</span>                    <span class="hljs-selector-tag">openvz-os</span>
<span class="hljs-selector-tag">centos-7-x86_64</span>                    <span class="hljs-selector-tag">openvz-os</span>
<span class="hljs-selector-tag">debian-7</span><span class="hljs-selector-class">.0-x86_64</span>                  <span class="hljs-selector-tag">openvz-os</span>
<span class="hljs-selector-tag">debian-8</span><span class="hljs-selector-class">.0-x86_64</span>                  <span class="hljs-selector-tag">openvz-os</span>
<span class="hljs-selector-tag">debian-9</span><span class="hljs-selector-class">.0-x86_64</span>                  <span class="hljs-selector-tag">openvz-os</span>
<span class="hljs-selector-tag">fedora-23-x86_64</span>                   <span class="hljs-selector-tag">openvz-os</span>
<span class="hljs-selector-tag">sles-11-x86_64</span>                     <span class="hljs-selector-tag">openvz-os</span>
<span class="hljs-selector-tag">sles-12-x86_64</span>                     <span class="hljs-selector-tag">openvz-os</span>
<span class="hljs-selector-tag">suse-42</span><span class="hljs-selector-class">.1-x86_64</span>                   <span class="hljs-selector-tag">openvz-os</span>
<span class="hljs-selector-tag">suse-42</span><span class="hljs-selector-class">.2-x86_64</span>                   <span class="hljs-selector-tag">openvz-os</span>
<span class="hljs-selector-tag">suse-42</span><span class="hljs-selector-class">.3-x86_64</span>                   <span class="hljs-selector-tag">openvz-os</span>
<span class="hljs-selector-tag">ubuntu-14</span><span class="hljs-selector-class">.04-x86_64</span>                <span class="hljs-selector-tag">openvz-os</span>
<span class="hljs-selector-tag">ubuntu-16</span><span class="hljs-selector-class">.04-x86_64</span>                <span class="hljs-selector-tag">openvz-os</span>
<span class="hljs-selector-tag">ubuntu-17</span><span class="hljs-selector-class">.10-x86_64</span>                <span class="hljs-selector-tag">openvz-os</span>
<span class="hljs-selector-tag">ubuntu-18</span><span class="hljs-selector-class">.04-x86_64</span>                <span class="hljs-selector-tag">openvz-os</span>

vzpkg install template centos-6-x86_64

vzpkg create cache centos-6-x86_64

prlctl create MyCT --vmtype ct

prlctl set MyCT --ostemplate centos-6-x86_64

prlctl set MyCT --cpus 8 --memsize 8G --swap 4G

prlctl set MyCT --ipadd 192.168.1.x

prlctl create MyVM --vmtype vm -d centos7

Windows Server 2016 、2012、2012 R2 2008 R2
CentOS 5、6、7 x86_64
Debian 8、9 x86_64
Ubuntu 14-18 x86_64

prlctl set MyVM --device-set cdrom0 --image /vz/iso/CentOS-7-x86_64-Minimal-1804.iso

prlctl set MyVM --cpus 8 --memsize 8G

prl_disk_tool resize --hdd /vz/vmprivate/c71d02d9-d0e4-42d0-bc1e-bcb3e8e97dc7/harddisk.hdd --size 30G

prlctl set MyVM --vnc-mode manual --vnc-port 5902 --vnc-passwd linseek --vnc-address 0.0.0.0 / 127.0.0.1

prlctl list --info MyVM

ID: {c71d02d9-d0e4<span class="hljs-number">-42</span>d0-bc1e-bcb3e8e97dc7}
EnvID: <span class="hljs-number">1193083609</span>
Name: MyVM
Description: 
Type: VM
State: stopped
OS: centos7
Template: <span class="hljs-literal">no</span>
Uptime: <span class="hljs-number">00</span>:<span class="hljs-number">00</span>:<span class="hljs-number">00</span> (since <span class="hljs-number">2018</span><span class="hljs-number">-09</span><span class="hljs-number">-10</span> <span class="hljs-number">11</span>:<span class="hljs-number">28</span>:<span class="hljs-number">59</span>)
Home: <span class="hljs-regexp">/vz/vmprivate/c71d02d9-d0e4-42d0-bc1e-bcb3e8e97dc7/</span>
Owner: root@.
GuestTools: state=not_installed
GuestTools autoupdate: <span class="hljs-literal">on</span>
Autostart: <span class="hljs-literal">off</span>
Autostop: shutdown
Autocompact: <span class="hljs-literal">off</span>
Boot order: hdd0 cdrom0 net0 
EFI boot: <span class="hljs-literal">off</span>
Allow select boot device: <span class="hljs-literal">off</span>
External boot device: 
On guest crash: restart
Remote display: mode=manual port=<span class="hljs-number">5902</span> address=<span class="hljs-number">127.0</span><span class="hljs-number">.0</span><span class="hljs-number">.1</span>
Remote display state: stopped
Hardware:
  cpu sockets=<span class="hljs-number">1</span> cpus=<span class="hljs-number">8</span> cores=<span class="hljs-number">8</span> VT-x accl=high mode=<span class="hljs-number">64</span> ioprio=<span class="hljs-number">4</span> iolimit=<span class="hljs-string">'0'</span>
  memory <span class="hljs-number">8192</span>Mb
  video <span class="hljs-number">32</span>Mb <span class="hljs-number">3</span>d acceleration=<span class="hljs-literal">off</span> vertical sync=<span class="hljs-literal">yes</span>
  memory_guarantee auto
  hdd0 (+) scsi:<span class="hljs-number">0</span> image=<span class="hljs-string">'/vz/vmprivate/c71d02d9-d0e4-42d0-bc1e-bcb3e8e97dc7/harddisk.hdd'</span> type=<span class="hljs-string">'expanded'</span> <span class="hljs-number">30720</span>Mb subtype=virtio-scsi
  cdrom0 (+) scsi:<span class="hljs-number">1</span> image=<span class="hljs-string">'/vz/iso/CentOS-7-x86_64-Minimal-1804.iso'</span> subtype=virtio-scsi
  usb (+)
  net0 (+) dev=<span class="hljs-string">'vme001c42cda633'</span> network=<span class="hljs-string">'Bridged'</span> mac=<span class="hljs-number">001</span>C42CDA633 card=virtio
SmartMount: (-)
Disabled Windows logo: <span class="hljs-literal">on</span>
Nested virtualization: <span class="hljs-literal">off</span>
Offline management: (-)

prlctl stop  MyCT / MyVM
prlctl start MyCT / MyVM
prlctl restart MyCT / MyVM
prlctl suspend MyCT / MyVM
prlctl resume MyCT / MyVM
prlctl mount MyCT / MyVM
prlclt umount MyCT / MyVM

发表评论