Last active
November 10, 2021 21:26
-
-
Save bekce/ae822a53e6427872f2baabab10dd72d0 to your computer and use it in GitHub Desktop.
OpenVZ setup (legacy)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
yum update | |
yum -y update | |
yum -y install openssh-clients openssh-servers nano | |
yum -y install openssh-clients openssh-server nano | |
ifconfig | |
chkconfig sshd on | |
service sshd start | |
shutdown -h now | |
ifconfig | |
wget -P /etc/yum.repos.d/ http://ftp.openvz.org/openvz.repo | |
rpm --import http://ftp.openvz.org/RPM-GPG-Key-OpenVZ | |
yum -y instal vzkernel vzctl vzquota nano | |
yum -y install vzkernel vzctl vzquota nano | |
mkdir -p /vz/template/cache/ | |
cd /vz/template/cache/ | |
wget http://download.openvz.org/template/precreated/centos-6-x86_64.tar.gz | |
reboot | |
uname -a | |
ifconfig | |
vzctl create 101 --ostemplate centos-6-x86_64.tar.gz | |
vzctl create 101 --ostemplate centos-6-x86_64 | |
cd /vz/template/cache/ | |
ls | |
ll | |
rm centos-6-x86_64.tar.gz | |
ls | |
mv centos-6-x86_64.tar.gz.1 centos-6-x86_64.tar.gz | |
vzctl create 101 --ostemplate centos-6-x86_64 | |
vzctl set 101 --ipadd 10.1.2.3 --save | |
cat /etc/resolv.conf | |
vzctl set 101 --nameserver 10.106.112.12 --save | |
vzctl start 101 | |
vzctl enter 101 | |
/etc/init.d/iptables stop | |
vzctl enter 101 | |
ping 8.8.8.8 | |
vzctl enter 101 | |
cat /proc/sys/net/ipv4/ip_forward | |
iptables -t nat -A POSTROUTING -s src_net -o eth0 -j SNAT --to ip_address | |
ifconfig eth0 | |
nano /etc/sysconfig/network-scripts/ifcfg-eth0 | |
vzctl set 101 --ipdel 10.1.2.3 --save | |
cat /etc/vz/conf/101.conf | |
iptables -t nat -A POSTROUTING -s 192.168.2.0/25 -o eth0 -j SNAT --to 10.106.38.35 | |
/sbin/iptables -A RH-Firewall-1-INPUT -s 192.168.2.0/25 -j ACCEPT | |
vzctl exec 101 ping www.openvz.org | |
vzctl set 101 --ipadd 192.168.2.2 --save | |
vzctl exec 101 ping www.openvz.org | |
vzctl enter 101 | |
ssh 192.168.2.2 | |
pwd | |
iptables -t nat -A PREROUTING -p tcp -d 10.106.38.35 --dport 5022 -i eth0 -j DNAT --to-destination 192.168.2.2:22 | |
iptables | |
iptables --list | |
iptables-save --help | |
cat /etc/sysconfig/iptables | |
vzctl set 101 --hostname ct101 | |
vzctl set 101 --hostname ct101 --save | |
vzctl show | |
vzctl list | |
vzctl --help | |
vzlist | |
vzctl suspend 101 | |
vzctl stop 101 | |
tar zcf /vz/template/cache/centos-6-seb.tar.gz -C /vz/private/101/ . | |
cd /vz/template/cache/ | |
ls | |
ll | |
vzctl create 102 --ostemplate centos-6-seb | |
ls | |
cat > test <<InputComesFromHERE | |
/// | |
DEVICE=vmbr0 | |
BOOTPROTO=dhcp | |
IPV6INIT=no | |
ONBOOT=yes | |
TYPE=Bridge | |
DELAY=0 | |
MACADDR=XX:XX:XX:XX:XX:XX | |
InputComesFromHERE | |
ls | |
cat test | |
rm test | |
cat > test <<InputComesFromHERE | |
/// | |
DEVICE=vmbr0 | |
BOOTPROTO=dhcp | |
IPV6INIT=no | |
ONBOOT=yes | |
TYPE=Bridge | |
DELAY=0 | |
MACADDR=XX:XX:XX:XX:XX:XX | |
InputComesFromHERE | |
ls | |
cat test | |
rm test | |
nano /etc/yum.repos.d/openvz.repo | |
vzctl set 102 --ipadd 192.168.2.3 --hostname ct102 --save | |
cat /etc/vz/conf/102.conf | |
nano /etc/vz/conf/102.conf | |
vzctl start 102 | |
iptables -t nat -A PREROUTING -p tcp -d 10.106.38.35 --dport 5122 -i eth0 -j DNAT --to-destination 192.168.2.3:22 | |
iptables-save > /etc/sysconfig/iptables | |
vzctl enter 102 | |
nano /etc/vz/conf/101.conf | |
vzctl start 101 | |
iptables -t nat -A PREROUTING -p tcp -d 10.106.38.35 --dport 50075 -i eth0 -j DNAT --to-destination 192.168.2.2:50075 | |
iptables -t nat -A PREROUTING -p tcp -d 10.106.38.35 --dport 50010 -i eth0 -j DNAT --to-destination 192.168.2.2:50010 | |
iptables -t nat -A PREROUTING -p tcp -d 10.106.38.35 --dport 50100 -i eth0 -j DNAT --to-destination 192.168.2.2:50100 | |
shutdown -h now | |
vzctl enter 101 | |
cd /home/hduser/hadoop-1.2.1/conf | |
iptables -t nat -A PREROUTING -p tcp -d 10.106.38.35 --dport 50030 -i eth0 -j DNAT --to-destination 192.168.2.2:50030 | |
iptables -t nat -A PREROUTING -p tcp -d 10.106.38.35 --dport 50060 -i eth0 -j DNAT --to-destination 192.168.2.2:50060 | |
iptables -t nat -A PREROUTING -p tcp -d 10.106.38.35 --dport 50070 -i eth0 -j DNAT --to-destination 192.168.2.2:50070 | |
iptables -t nat -A PREROUTING -p tcp -d 10.106.38.35 --dport 50090 -i eth0 -j DNAT --to-destination 192.168.2.2:50090 | |
iptables -t nat -A PREROUTING -p tcp -d 10.106.38.35 --dport 60000 -i eth0 -j DNAT --to-destination 192.168.2.2:60000 | |
iptables -t nat -A PREROUTING -p tcp -d 10.106.38.35 --dport 60010 -i eth0 -j DNAT --to-destination 192.168.2.2:60010 | |
iptables -t nat -A PREROUTING -p tcp -d 10.106.38.35 --dport 60020 -i eth0 -j DNAT --to-destination 192.168.2.2:60020 | |
iptables -t nat -A PREROUTING -p tcp -d 10.106.38.35 --dport 60030 -i eth0 -j DNAT --to-destination 192.168.2.2:60030 | |
iptables -t nat -A PREROUTING -p tcp -d 10.106.38.35 --dport 2888 -i eth0 -j DNAT --to-destination 192.168.2.2:2888 | |
iptables -t nat -A PREROUTING -p tcp -d 10.106.38.35 --dport 3888 -i eth0 -j DNAT --to-destination 192.168.2.2:3888 | |
iptables -t nat -A PREROUTING -p tcp -d 10.106.38.35 --dport 2181 -i eth0 -j DNAT --to-destination 192.168.2.2:2181 | |
to-destination 192.168.2.2:50090 | |
iptables-save > /etc/sysconfig/iptables | |
ifconfig | |
date | |
yum install ntpd | |
ntpd | |
ntpdate 0.us.pool.ntp.org | |
service ntpd stop | |
ntpdate 0.us.pool.ntp.org | |
date | |
service ntpd start | |
iptables -L | |
iptables -h | |
iptables -S | |
iptables-save | |
service --status-all|grep running | |
cat /boot/grub/menu.lst | |
cd | |
ls | |
sh install-vz.sh | |
cat .bashrc | |
cat /etc/bashrc | |
sh install-vz.sh | |
echo $USER | |
uname | |
uname --help | |
uname -s | |
uname -m | |
sh install-vz.sh | |
nano /etc/yum.repos.d/openvz.repo | |
sh test.sh | |
ifconfig eth0 | |
ifconfig eth0 iet | |
ifconfig eth0 | |
ifconfig --help | |
ip addr show | |
ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}' | |
sh conf-vz.sh | |
ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}' | |
sh conf-vz.sh | |
sh test.sh | |
uname -v | |
uname --help | |
uname -r | |
uname -m | |
uname -p | |
uname -o | |
uname -i | |
uname -n | |
uname -r | |
wget --help | |
vzctl show | |
vzctl list | |
vzctl | |
hostname | |
hostname --help | |
hostname -s | |
hostname -a | |
hostname -d | |
sh test.sh | |
vzctl | |
sh conf-vz.sh | |
vzctl | |
vzlist | |
sh conf-vz.sh | |
ls /vz/template/cache/ | |
cat /etc/vz/conf/101.conf | |
cat /etc/vz/conf/102.conf | |
sh conf-vz.sh | |
vzctl enter 102 | |
sh conf-vz.sh | |
find -C /vz/template/cache/ . | |
find --help | |
ls /vz/template/cache/ | |
ls -1 /vz/template/cache/ | |
ls -l /vz/template/cache/ | |
cd /vz/template/cache/ | |
ls | |
rm ubuntu-12.04-x86_64.tar.gz | |
cd | |
ls | |
sh conf-vz.sh | |
cd | |
cd /etc | |
cd apt | |
yum update | |
shutdown | |
poweroff |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
#OpenVZ configure script | |
#author Selim Eren Bekce | |
echo "Configure VZ Script v1.2" | |
if [ ! "$USER" = "root" ]; then | |
echo "You need to be root." | |
exit 1 | |
fi | |
#You can check it from \"uname -r\" command. | |
echo "This script assumes OpenVZ is already installed and its kernel is running atm. " | |
hostip=`ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'` | |
echo "Enter host ip address (blank for $hostip):" | |
read hostip2 | |
if [ -n "$hostip2" ]; then hostip=$hostip2; fi; | |
options=("Configure NAT Network" "Download OS Template" "Create a CT" "Open Ports in NAT" "Create Template from a CT" "Quit") | |
select opt in "${options[@]}" | |
do | |
case $opt in | |
"Configure NAT Network") | |
echo "You should only do this per CT0 (host node). " | |
subnetcidr="192.168.2.0/25" | |
echo "Enter desired Subnet CIDR for Containers (blank for $subnetcidr):" | |
read subnetcidr2 | |
if [ -n "$subnetcidr2" ]; then subnetcidr=$subnetcidr2; fi; | |
echo "iptables -t nat -A POSTROUTING -s $subnetcidr -o eth0 -j SNAT --to $hostip" | |
echo "Confirm? (ENTER/CTRL+C)" | |
read val1 | |
iptables -t nat -A POSTROUTING -s $subnetcidr -o eth0 -j SNAT --to $hostip | |
if [ $? -ne 0 ]; then echo "An error occured. Exiting. 10"; exit 10; fi; | |
iptables-save > /etc/sysconfig/iptables | |
if [ $? -ne 0 ]; then echo "An error occured. Exiting. 11"; exit 11; fi; | |
echo "NAT subnet \"$subnetcidr\" added. Configuration saved to /etc/sysconfig/iptables" | |
;; | |
"Download OS Template") | |
echo "Either centos-6-x86_64.tar.gz or ubuntu-12.04-x86_64 can be downloadable from here. "; | |
echo "This script will overwrite templates with the same name in /vz/template/cache/. " | |
echo "Enter 'centos' to download centos-6-x86_64.tar.gz or 'ubuntu' to download ubuntu-12.04-x86_64." | |
read val1 | |
if [ "$val1" = "centos" ]; then | |
wget -P /vz/template/cache/ http://download.openvz.org/template/precreated/centos-6-x86_64.tar.gz | |
if [ $? -ne 0 ]; then echo "An error occured. Exiting. 12"; exit 12; fi; | |
echo "Centos 6 template downloaded under /vz/template/cache/." | |
elif [ "$val1" = "ubuntu" ]; then | |
wget -P /vz/template/cache/ http://download.openvz.org/template/precreated/ubuntu-12.04-x86_64.tar.gz | |
if [ $? -ne 0 ]; then echo "An error occured. Exiting. 13"; exit 13; fi; | |
echo "Ubuntu 12.04 template downloaded under /vz/template/cache/." | |
else | |
echo "Invalid input" | |
fi | |
;; | |
"Create a CT") | |
echo "Enter CTID of your new CT (ex: 101, 102, etc). (Do NOT enter an existing ctid): " | |
read ctid | |
if [ -z "$ctid" ]; then echo "Invalid CTID. "; continue; fi | |
templatelist=$(ls -1 /vz/template/cache/) | |
targz=".tar.gz" | |
select template in $templatelist; do | |
template=${template%$targz} | |
break | |
done | |
echo "Enter CT ip address (ex: 192.168.2.101)" | |
read ctip | |
if [ -z "$ctip" ]; then echo "Invalid ctip. "; continue; fi | |
cthost=`hostname -s`$ctid.`hostname -d` | |
echo "Enter CT hostname ($cthost)" | |
read cthost2 | |
if [ -n "$cthost2" ]; then cthost=$cthost2; fi; | |
echo "vzctl create $ctid --ostemplate $template --ipadd $ctip --hostname $cthost" | |
echo "Confirm? (ENTER/CTRL+C)" | |
read val1 | |
vzctl create $ctid --ostemplate $template --ipadd $ctip --hostname $cthost | |
if [ $? -ne 0 ]; then echo "An error occured. Exiting. 14"; exit 14; fi; | |
;; | |
"Open Ports in NAT") | |
echo "Enter CT ip:" | |
read ctip | |
if [ -z "$ctip" ]; then echo "Invalid ctip. "; continue; fi | |
while : | |
do | |
echo "Enter CT port (blank to break):" | |
read ctport | |
if [ -z "$ctport" ]; then break; fi | |
echo "Enter host port (blank for $ctport):" | |
read hostport | |
if [ -z "$hostport" ]; then hostport=$ctport; fi | |
echo "iptables -t nat -A PREROUTING -p tcp -d $hostip --dport $hostport -i eth0 -j DNAT --to-destination $ctip:$ctport" | |
echo "Confirm? (ENTER/CTRL+C)" | |
read val1 | |
iptables -t nat -A PREROUTING -p tcp -d $hostip --dport $hostport -i eth0 -j DNAT --to-destination $ctip:$ctport | |
if [ $? -ne 0 ]; then echo "An error occured. Exiting. 15"; exit 15; fi; | |
iptables-save > /etc/sysconfig/iptables | |
if [ $? -ne 0 ]; then echo "An error occured. Exiting. 16"; exit 16; fi; | |
echo "Redirect added. Configuration saved to /etc/sysconfig/iptables. Adding continues for same CT ip. " | |
done | |
;; | |
"Create Template from a CT") | |
echo "This will create a template from an existing CT installation." | |
echo "Enter CTID of target CT (ex: 101, 102, etc): " | |
read ctid | |
if [ -z "$ctid" ]; then echo "Invalid CTID. "; continue; fi | |
echo "Enter target template file name (without extension): " | |
read template | |
if [ -z "$template" ]; then echo "Invalid template name. "; continue; fi | |
echo "Confirm stopping CT $ctid? (ENTER/CTRL+C)" | |
read val1 | |
vzctl stop $ctid | |
if [ $? -ne 0 ]; then echo "An error occured. Exiting. 17"; exit 17; fi; | |
echo "tar zcf /vz/template/cache/$template.tar.gz -C /vz/private/$ctid/ ." | |
echo "Confirm? (ENTER/CTRL+C)" | |
read val1 | |
echo "Please wait" | |
tar zcf /vz/template/cache/$template.tar.gz -C /vz/private/$ctid/ . | |
if [ $? -ne 0 ]; then echo "An error occured. Exiting. 18"; exit 18; fi; | |
echo "Template $template created" | |
;; | |
"Quit") | |
echo "Bye" | |
break | |
;; | |
*) echo invalid option;; | |
esac | |
done | |
exit 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
#OpenVZ install script | |
#author Selim Eren Bekce | |
echo "Install OpenVZ script v1.2." | |
if [ ! "$USER" = "root" ]; then | |
echo "You need to be root." | |
exit 1 | |
fi | |
MACHINE_ARCH=`uname -m` | |
if [ ! "$MACHINE_ARCH" = "x86_64" ]; then | |
echo "This script only supports x86_64 architecture. Do manual installation." | |
exit 1 | |
fi | |
echo "Enter your centos version [5|6]:" | |
read CENTOS_VERSION; | |
if [ "$CENTOS_VERSION" = "5" ]; then | |
cat >/etc/yum.repos.d/openvz.repo <<HERE | |
[openvz-utils] | |
name=OpenVZ user-space utilities | |
#baseurl=http://download.openvz.org/current/ | |
mirrorlist=http://download.openvz.org/mirrors-current | |
enabled=1 | |
gpgcheck=1 | |
gpgkey=http://download.openvz.org/RPM-GPG-Key-OpenVZ | |
# In addition to the above repo, you have to enable at least one the the | |
# kernel repositories below. By default, openvz-kernel-rhel6 is enabled; | |
# you might want to change this. | |
## RHEL6-based OpenVZ kernels | |
[openvz-kernel-rhel6] | |
name=OpenVZ RHEL6-based stable kernels | |
#baseurl=http://download.openvz.org/kernel/branches/rhel6-2.6.32/current/ | |
mirrorlist=http://download.openvz.org/kernel/mirrors-rhel6-2.6.32 | |
enabled=0 | |
gpgcheck=1 | |
gpgkey=http://download.openvz.org/RPM-GPG-Key-OpenVZ | |
exclude=vzkernel-firmware | |
# Feel free to enable testing repo if you want newer testing kernels | |
[openvz-kernel-rhel6-testing] | |
name=OpenVZ RHEL6-based testing kernels | |
#baseurl=http://download.openvz.org/kernel/branches/rhel6-2.6.32-testing/current/ | |
mirrorlist=http://download.openvz.org/kernel/mirrors-rhel6-2.6.32-testing | |
enabled=0 | |
gpgcheck=1 | |
gpgkey=http://download.openvz.org/RPM-GPG-Key-OpenVZ | |
exclude=vzkernel-firmware | |
# You might need to enable debuginfo, if asked by developers | |
[openvz-kernel-rhel6-debuginfo] | |
name=OpenVZ RHEL6-based testing kernel debuginfo rpms | |
baseurl=http://download.openvz.org/kernel/branches/rhel6-2.6.32-testing/debuginfo | |
enabled=0 | |
gpgcheck=1 | |
gpgkey=http://download.openvz.org/RPM-GPG-Key-OpenVZ | |
## RHEL5-based OpenVZ kernels. Come on, switch to RHEL6 already! | |
[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 | |
[openvz-kernel-rhel5-testing] | |
name=OpenVZ RHEL5-based testing kernel | |
#baseurl=http://download.openvz.org/kernel/branches/rhel5-2.6.18-testing/current/ | |
mirrorlist=http://download.openvz.org/kernel/mirrors-rhel5-2.6.18-testing | |
enabled=0 | |
gpgcheck=1 | |
gpgkey=http://download.openvz.org/RPM-GPG-Key-OpenVZ | |
## Development branches | |
# ....none at this point | |
HERE | |
if [ $? -ne 0 ]; then echo "An error occured. Exiting. 10"; exit 10; fi; | |
rpm --import http://ftp.openvz.org/RPM-GPG-Key-OpenVZ | |
if [ $? -ne 0 ]; then echo "An error occured. Exiting. 11"; exit 11; fi; | |
yum -y install ovzkernel.x86_64 | |
if [ $? -ne 0 ]; then echo "An error occured. Exiting. 12"; exit 12; fi; | |
yum -y install vzctl vzquota nano | |
if [ $? -ne 0 ]; then echo "An error occured. Exiting. 13"; exit 13; fi; | |
echo "OVZ Kernel installed. Enter Y to reboot now. "; | |
read val1; | |
if [ "$val1" = "Y" ]; then | |
reboot | |
fi | |
elif [ "$CENTOS_VERSION" = "6" ]; then | |
wget -P /etc/yum.repos.d/ http://ftp.openvz.org/openvz.repo | |
if [ $? -ne 0 ]; then echo "An error occured. Exiting. 20"; exit 20; fi; | |
rpm --import http://ftp.openvz.org/RPM-GPG-Key-OpenVZ | |
if [ $? -ne 0 ]; then echo "An error occured. Exiting. 21"; exit 21; fi; | |
yum -y install vzkernel | |
if [ $? -ne 0 ]; then echo "An error occured. Exiting. 22"; exit 22; fi; | |
yum -y install vzctl vzquota ploop nano | |
if [ $? -ne 0 ]; then echo "An error occured. Exiting. 23"; exit 23; fi; | |
echo "OVZ Kernel installed. Enter Y to reboot now. "; | |
read val1; | |
if [ "$val1" = "Y" ]; then | |
reboot | |
fi | |
else | |
echo "Invalid version. " | |
exit 2 | |
fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if [ $? -ne 0 ]; then echo "An error occured. Exiting. 10"; exit 10; fi; | |
ctid=101 | |
echo "Enter ct hostname (`hostname -s`$ctid.`hostname -d`)" | |
echo "Enter your centos version [5|6]:" | |
read CENTOS_VERSION; | |
if [ "$CENTOS_VERSION" = "5" ]; then | |
echo "5!" | |
elif [ "$CENTOS_VERSION" = "6" ]; then | |
echo "6!" | |
else | |
echo "Invalid version. " | |
exit 2 | |
fi | |
echo "NAT subnet \"$CENTOS_VERSION\" added. Configuration saved to /etc/sysconfig/iptables" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment