本来是dd了windows server打算用VMware Workstation随便用一下的, 没想到vmware开出来的虚拟机再通过vmware的端口转发, 外网下载小鸡的文件速度只有300KB, 但是下载母鸡的文件能达到满速. 至今还没有搞明白. 所以就用Proxmox了.
安装Proxmox
hetzner虽然后台没有提供Proxmox的模板可供选择, 但是在救援系统里是可以通过installimage
命令安装的.
在后台选择救援模式重启, 输入hz提供的root密码ssh登录. 执行installimage
命令, 选择other->proxmox...debian-stretch
修改install.conf, 这边我参考了senra大佬的文: IDC零基础系列——Hetzner独服使用Proxmox创建VPS
开启raid, 选择raid0. /var/lib/vz目录是Proxmox的数据目录,模板,虚拟机磁盘全放在这。
SWRAID 1
SWRAIDLEVEL 0
PART /boot ext3 512M
PART lvm vg0 all
LV vg0 root / ext3 100G
LV vg0 swap swap swap 32G
LV vg0 data /var/lib/vz ext4 all
安装完成之后通过https://ip:8006访问Proxmox的web ui界面, 账号类型选择Linux PAM, 账号root密码, 密码是服务器的root密码
修改母鸡的网卡配置, 如下:
source /etc/network/interfaces.d/*
auto lo
iface lo inet loopback
iface lo inet6 loopback
iface enp0s31f6 inet manual
auto vmbr0
iface vmbr0 inet static
address 母鸡IP
netmask 子网掩码
gateway 网关
broadcast 95.216.21.191 #这个在面板的IPs选项卡里鼠标移动到ip上能看到
bridge_ports enp0s31f6
bridge-stp off
bridge-fd 0
up route add -net 母鸡IP netmask 子网掩码 gw 网关 dev enp0s31f6
iface vmbr0 inet6 static
address IPv6地址
netmask 64
gateway fe80::1
#配置内网ip
auto vmbr1
iface vmbr1 inet static
address 10.20.20.1
netmask 255.255.255.0
bridge_ports none
bridge_stp off
bridge_fd 0
post-up echo 1 > /proc/sys/net/ipv4/ip_forward
post-up iptables -t nat -A POSTROUTING -s '10.20.20.0/24' -o vmbr0 -j MASQUERADE
post-down iptables -t nat -D POSTROUTING -s '10.20.20.0/24' -o vmbr0 -j MASQUERADE
确认没有问题, 之后直接重启.
配置nat转发规则
因为我们没有多余的独立ip可以分配给小鸡, 所以这里选择nat端口转发的形式让外网能访问小鸡.
创建文件vim /etc/network/if-pre-up.d/iptables
输入以下文本
#!/bin/sh
/sbin/iptables-restore < /etc/iptables
执行chmod +x /etc/network/if-pre-up.d/iptables
这样配置之后, 每次开机会从/etc/iptables读取iptables设置. 解决Debian系统重启后不保持iptables设置的问题(Proxmox基于debian).
现在配置iptables规则:
#增加一条nat转发规则
iptables -t nat -A PREROUTING -i vmbr0(母鸡网卡) -p tcp --dport 母鸡端口 -j DNAT --to 小鸡ip:端口
#把设置好的iptables规则保存到/etc/iptables这个文件
iptables-save > /etc/iptables
看到网上有人说这么操作之后可能还是无法联网, 所以这里先记一下
特别说明:如果创建好的虚拟机无法连接外网。直接编辑文件/etc/sysctl.conf,增加net.ipv4.ip_forward = 1,或者去掉注释。保存后执行sysctl -p,不能联网的虚拟机就恢复正常了。
小鸡配置静态ip
Proxmox默认不支持dhcp, 所以要么自己配置dhcp, 要么配置静态ip.
记录一下Centos7配置静态ip的过程
进入 /etc/sysconfig/network-scripts
找到网卡的配置文件(ifcfg-网卡),网卡名称可以通过ip addr
查看.
编辑配置文件
BOOTPROTO=static
IPADDR=10.20.20.6
NETMASK=255.255.255.0
NM_CONTROLLED=no
...
ONBOOT=yes
保存之后重启网络服务systemctl restart network.service
配置dns
nmcli con mod 网卡 ipv4.dns "8.8.8.8 8.8.4.4"
nmcli con up 网卡
opz小鸡
记录一下opz模板下载地址: https://download.openvz.org/template/precreated/
记录一些奇怪的问题
关于Proxmox正常运行但是无法创建虚拟机, 提示节点离线的解决办法:
- 执行
service pvestatd restart
原因不明. 似乎是pvestatd进程被杀死了.
Proxmox show nodes OFFLINE
Try this:
service pvestatd restart – restarts no service
service pvedaemon restart – restarts pve deamons
service pve-cluster restart – restarts pve cluster- 从外网找到的其他方案, 暂未尝试
Hi,
I've had a similar issue. Someone kindly suggested me to set the 'token'
value to 4000 in the corosync.cnf.
/etc/pve/corosync.conf
totem {
cluster_name: xxxxx
config_version: 35
ip_version: ipv4
version: 2
token: 4000
interface {
bindnetaddr: X.X.X.X
ringnumber: 0
}
}
Then do this on all nodes:
killall -9 corosync
/etc/init.d/pve-cluster restart
service pveproxy restart
This solved the similar problem for me and my cluster of 12 nodes is
working properly ever since.- 执行