VPS安装PVE后的优化
开启BBR
如果是海外的独立服务器,建议开启BBR来优化TCP传输,开启方法如下:
修改内核配置
cat >>/etc/sysctl.conf << EOF
net.core.default_qdisc=fq
net.ipv4.tcp_congestion_control=bbr
EOF使配置生效
sysctl -p使用命令lsmod |grep bbr进行验证,当看到tcp_bbr字样,说明BBR开启成功。
Linux默认描述符为1024,为避免后期出现各种问题,建议修改ulimit描述符限制,修改方法如下:
echo 'fs.file-max = 65535' >> /etc/sysctl.conf
echo '* soft nofile 65535' >> /etc/security/limits.conf
echo '* hard nofile 65535' >> /etc/security/limits.conf
echo 'ulimit -SHn 65535' >> /etc/profile单IP VPS LXC虚拟化开NAT小鸡
配置网络
首先,配置IPv6网络,如果没有ipv6或者不需要可忽略,编辑/etc/modprobe.d/local.conf,修改或者添加如下内容:
options ipv6 disable=0编辑/etc/modules,添加如下字符:
ipv6开启IPv4,IPv6转发,编辑/etc/sysctl.conf,添加以下内容到尾部:
net.ipv4.ip_forward=1
net.ipv4.conf.all.rp_filter=1
net.ipv4.icmp_echo_ignore_broadcasts=1
net.ipv4.conf.default.forwarding=1
net.ipv4.conf.default.proxy_arp = 0
net.ipv4.conf.default.send_redirects = 1
net.ipv4.conf.all.send_redirects = 0
net.ipv6.conf.ens3.autoconf=0
net.ipv6.conf.ens3.accept_ra=2
net.ipv6.conf.default.forwarding=1
net.ipv6.conf.all.forwarding=1
net.ipv6.conf.default.proxy_ndp=1
net.ipv6.conf.all.proxy_ndp=1其中ens3修改为自己的网卡名:
net.ipv6.conf.ens3.autoconf=0
net.ipv6.conf.ens3.accept_ra=2网卡名称查看输入:ip a
重点来了,编辑/etc/network/interfaces,我的VPS原配置如下:
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
source /etc/network/interfaces.d/*
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
allow-hotplug ens3
iface ens3 inet static
address 107.175.***.***/24
gateway 107.175.***.***
# dns-* options are implemented by the resolvconf package, if installed
dns-nameservers 8.8.8.8
dns-search colocrossing.com修改如下内容如下:
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
auto lo
iface lo inet loopback
iface ens3 inet manual #修改成你原来的网卡名
auto vmbr0
iface vmbr0 inet static
address 107.175.***.***/24 #这里必须和原配置一样
netmask 255.255.255.0
gateway 107.175.***.*** #这里必须和原配置一样
bridge_ports ens3 #修改成你原来的网卡名
bridge_stp off
bridge_fd 0
#private sub network
auto vmbr1
iface vmbr1 inet static
address 10.10.10.1/24 #自定义你内网ip段,你开心定成啥就是啥
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.10.10.0/24' -j MASQUERADE
post-down iptables -t nat -D POSTROUTING -s '10.10.10.0/24' -j MASQUERADE修改完成后保存,重启VPS,如果重启发现连不上,遗憾的告诉你你改错了导致外网蹦了,去VNC重新修改配置吧!
重启成功后,进入PVE Web管理页面 https://ip:8006/
配置外网端口转发
在母鸡中执行,代码如下:
iptables -t nat -A PREROUTING -i vmbr0 -p tcp --dport 10022 -j DNAT --to-destination 10.10.10.100:22
iptables -t nat -A PREROUTING -i vmbr0 -p udp --dport 10022 -j DNAT --to-destination 10.10.10.100:22外网端口10022就是对应的内网小鸡22端口,配置完成后可以通过ip:10022来访问小鸡,如需其他端口,上面代码自行修改执行即可。
本作品采用 知识共享署名-相同方式共享 4.0 国际许可协议 进行许可。
小菜鸡
评论已关闭