Linux教程

nginx中转负载均衡

黑色 · 4月8日 · 2020年 848次已读
  • 升级系统 centos
yum update
apt-get update
  • 下载nginx源(centos)
rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
  • 安装
yum install nginx -y   #centos
apt-get install nginx -y  #debian
  • 运行nginx
systemctl start nginx.service  #centos
service nginx start   #debian
  • 依次输入
mkdir -p /etc/nginx/tcpconf.d
vi /etc/nginx/tcpconf.d/ssrproxy.conf
echo "include /etc/nginx/tcpconf.d/*.conf;" >> /etc/nginx/nginx.conf
  • 关闭防火墙
systemctl stop firewalld.service
  • 开机禁止启动防火墙
systemctl disable firewalld.service
  • 编辑配置文件
vi /etc/nginx/tcpconf.d/ssrproxy.conf
  • 重启nginx
systemctl restart nginx
service nginx restart
  • 设置开机启动
systemctl enable nginx.service
  • 设置定时任务
crontab -e
0 */6 * * * systemctl restart nginx
  • 配置文件模版
stream {
upstream hk {
server 2222:42194;
server 3333:55689;
server 44444:55866;
server 55555:44562;
}
server {
listen 11040;
listen 11040 udp;
proxy_pass hk;
}
}
  • GCP中转脚本
apt-get update
apt-get install -y wget
wget -qO natcfg.sh http://arloor.com/sh/iptablesUtils/natcfg.sh && bash natcfg.sh
wget -qO natcfg.sh https://raw.githubusercontent.com/arloor/iptablesUtils/master/natcfg.sh && bash natcfg.sh. #备用
  • iptables一键脚本
wget -N --no-check-certificate https://raw.githubusercontent.com/ToyoDAdoubiBackup/doubi/master/iptables-pf.sh && chmod +x iptables-pf.sh && bash iptables-pf.sh

运行命令 ./iptables-pf.sh

如果出现refused运行以下命令

yum -y install wget  #CentOS
apt-get -y install wget  #Ubuntu/Debian
apt-get update
apt-get upgrade
apt-get update -y && apt-get install curl -y
apt-get update -y && apt-get install curl -y