专栏名称: 架构文摘
每天一篇架构领域重磅好文,涉及一线互联网公司的互联网应用架构、大数据、机器学习等各个热门领域。
目录
相关文章推荐
架构师之路  ·  爸爸!除了你,沈括,沈万三... ... ·  2 天前  
字节跳动技术团队  ·  掘金 AI 编程社区- 人人都是 AI 编程家竞赛 ·  13 小时前  
InfoQ Pro  ·  Redis 之父:哪怕被喷我也得说,AI ... ·  昨天  
51好读  ›  专栏  ›  架构文摘

基于Nginx负载均衡方案

架构文摘  · 公众号  · 架构  · 2017-12-21 09:06

正文

请到「今天看啥」查看全文



  • 网络相关配置

    • 服务器部分配置如下:


#OS基于Centos7,测试环境,生产环境根据实际情况修改
#安装路由软件
yum install quagga
#配置zebra
#cat /etc/quagga/zebra.conf
!
! Zebra configuration saved from vty
!   2017/09/28 15:57:12
!
hostname test-ssl-10-231.test.org #这个每台名字要不同
password 8 WuN0UOEsh./0U
enable password 8 g9UPXyneQv2n.
log file /var/log/quagga/zebra.log
service password-encryption
#配置ospfd
# cat /etc/quagga/ospfd.conf
hostname test-ssl-10-231.test.org #每台要不同
password 8 cQGHF4e9QbcA
enable password 8 RBUKMtvgMhU3M
log file /var/log/quagga/ospfd.log
service password-encryption
!
!
!
interface eth2
ip ospf authentication message-digest
ip ospf message-digest-key 1 md5 pIW87ypU3d4v3pG7 #此处密码告知网络工程师
ip ospf hello-interval 1
ip ospf dead-interval 4
ip ospf priority 0

router ospf
ospf router-id 10.10.41.130 #每台router-id要不一样
log-adjacency-changes
network 10.10.41.0/24 area 0.0.0.0
network 10.10.100.100/32 area 0.0.0.0 #宣告自己的ospf互边地址和VIP地址,新增地址都在此处添加
area 0.0.0.0 authentication message-digest
!
line vty
!

#启动服务
systemctl enable zebra.service
systemctl enable ospfd.service
systemctl start zebra.service
systemctl start ospfd.service
#添加ospf和zebra保活,打开配置文件打开如下行行
vim /etc/sysconfig/quagga
WATCH_DAEMONS="zebra ospfd"
######策略路由配置,eth0指向默认路由,在eth1模拟公网进行配置######
#cat /etc/iproute2/rt_tables增加
100 wan41
#增加路由表相关配置
ip route add 10.10.41.0/24 dev eth1 src 10.10.41.130 table wan41
ip route add default via 10.10.41.250 table wan41
ip rule add from 10.10.41.130 table wan41
持久化到配置文件
cat route-eth1
10.10.41.0/24 dev eth2 src 10.10.41.130 table wan41
default via 10.10.41.250 table 100
cat rule-eth1
from 10.10.41.130 table wan41
######策略路由配置结束######


    • 交换机配置部分(略)


  • 增加zebra ospfd保活

    • 打开/etc/sysconfig/quagga注释以下行:WATCH_DAEMONS="zebra ospfd"

  • nginx 七层配置,关键是日志配置获取ClientIP如下:


server context listen增加如下:
listen 80 proxy_protocol;







请到「今天看啥」查看全文