一、配置负载均衡
配置麒麟的yum源
vim /etc/yum.repos.d/kylin_aarch64.repo
Copy
删除原来内容,写入如下yum源
[ks10-adv-os]
name = Kylin Linux Advanced Server 10 - Os
baseurl = http://update.cs2c.com.cn:8080/NS/V10/V10SP2/os/adv/lic/base/aarch64/
gpgcheck = 0
enabled = 1
[ks10-adv-updates]
name = Kylin Linux Advanced Server 10 - Updates
baseurl = http://update.cs2c.com.cn:8080/NS/V10/V10SP2/os/adv/lic/updates/aarch64/
gpgcheck = 0
enabled = 1
Copy
同步源
yum repolist
Copy
安装并运行nginx
yum install -y nginx
systemctl start nginx.service
systemctl status nginx.service
Copy
防火墙放行对应端口入站流量(案例中直接关闭防火墙)
systemctl stop firewalld.service
systemctl status firewalld.service
Copy
cd /etc/nginx/conf.d/
vim lb.conf
Copy
lb.conf的内容
upstream lb {
server 127.0.0.1:8085 weight=1;
server 127.0.0.1:8086 weight=2;
}server {
listen 8085;
return 200 "node1\r\n";
}server {
listen 8086;
return 200 "node2\r\n";
}server {
listen 8080;location / {
proxy_pass http://lb;
proxy_connect_timeout 10s;
proxy_read_timeout 5s;
proxy_send_timeout 5s;
}
}
Copy
保存退出,使lb.conf生效
nginx -s reload
Copy
二、测试访问
curl http://127.0.0.1:8080
curl http://127.0.0.1:8080
curl http://127.0.0.1:8080
Copy
三、配置四层反向代理
查看IP地址
ifconfig enp0s2
Copy
将sgtream模块如下代码插入nginx主配置文件
vim /etc/nginx/nginx.conf
Copy
在nginx.conf的末尾加上以下内容
stream {upstream ssh {server IP地址:22;}server {listen 10022;proxy_pass ssh;proxy_connect_timeout 10;}
}
Copy
保存退出,使文件生效
nginx -s reload
Copy
查看结果
telnet 127.0.0.1 10022
Copy