当前位置:网站首页>HAproxy + Keepalive实现LDAP代理服务
HAproxy + Keepalive实现LDAP代理服务
2022-06-29 20:50:00 【星哥玩云】
因为公司的各种高自研发的系统非常多,这些系统又全部是在使用LDAP做认证,目前我们有几台DC控制器来分担这些ldap请求,用户通过访问ldap.xxxx.com这个域名来连接ldap服务器,我们通过DNS轮询的方式指向不同的DC服务器。
这样出现一个问题就是:当某一台DC挂掉的时候,会导致部分用户或者系统的认证失败,为了达到高可用性,我们更改了环境拓扑,用四台linux服务器充当代理服务器,代理所有ldap请求。
结构如下图:
简单解释一下,4台代理服务器两两一组,都是一台主机,一台热备,分配两个VIP,用户通过DNS查询ldap这个a记录会被轮询到这两个虚IP的代理服务器上,代理服务器后端通过HAproxy检测DC主机端口状态,平均分配用户请求到这些主机上,如果用DC主机故障,就不分配请求。两台一组的代理服务器通过keepalived检测健康状态,如果一台故障,自动将vip飘到备份主机上。
我不得不说,因为我在接到这个任务之前,完全是个linux小白,我连linux怎么做系统都不会。。所以如果我的这篇文章有写的不对的地方,请多多指出。
好吧,虽然我不会装linux系统,但是公司技术部的大大和安全组的大大们研发了一套linux的pxe自助系统,我只需要PXE启动后,选择我要装linux RHEL 6.3版本即可,所以我这里没法介绍怎么做系统。
同样,IP和主机名的修改我也不讲了,这个还是挺容易查到的。
现在开始进行系统的配置:
安装keepalived和HAProxy需要的组件
好吧,我可以用yum命令。。又省事了 yum install gcc kernel-headers kernel-devel yum install keepalived
2 配置keepalived: Keepalived配置文件的默认位置为: vi /etc/keepalived/keepalived.conf
建议复制一份原始的做备份 修改配置文件为:
vrrp_scriptchk_http_port { script"/etc/keepalived/check_haproxy.sh" #检测haproxy健康状态的脚本 interval 2 weight 2 } vrrp_instanceVI_1 { interface eth0 state MASTER #备机配置为BACKUP priority 101 #备机配置为100 virtual_router_id 51 #keepalived组表示,同一组中的主机该值要一样 smtp_alert virtual_ipaddress { x.x.x.2 #虚拟IP } track_script { chk_http_port } }
创建上面用到的脚本文件,意思是当检测到haproxy服务没有启动时启动它,如果启动失败则停掉本机的keepalived服务,这样VIP会切换到备机上:
#vi /etc/keepalived/check_haproxy.sh #!/bin/bash A=`ps -C haproxy --no-header |wc -l` if [ $A -eq 0 ];then /root/haproxy-1.4.23/haproxy -f /root/haproxy-1.4.23/haproxy.cfg sleep 3 if [ `ps -C haproxy --no-header |wc -l` -eq 0 ];then /etc/init.d/keepalived stop fi fi #chmod 755 /etc/keepalived/check_haproxy.sh
3 安装HAProxy wget http://haproxy.1wt.eu/download/1.4/src/haproxy-1.4.23.tar.gz tar–zvxf haproxy-1.4.23.tar.gz cd haproxy-1.4.23 make TARGET=linux26
4 配置HAProxy
创建配置文件: vi /root/haproxy-1.4.23/haproxy.cfg
配置文件如下 global log /dev/log local0 info #日志 log /dev/log local0 notice #日志 maxconn 4096 user root group root daemon defaults log global contimeout 5000 clitimeout 50000 srvtimeout 50000 option forwardfor option redispatch stats refresh 30 retries 3 frontend ldap_tcp bind *:389 default_backend pool_ldap log global option forwardfor backend pool_ldap balance roundrobin mode tcp server DC03 10.1.1.3:389 check inter 5000 #监听的LDAP服务器 server DC04 10.1.1.4:389 check inter 5000 server DC05 10.1.1.5:389 check inter 5000 server DC06 10.1.1.6:389 check inter 5000 frontend vs_stats :8081 #监控页面端口 mode http default_backend stats_backend backend stats_backend mode http stats enable stats uri /stats #监控页面URL stats auth admin:admin #监控页面管理员账号和密码
主机和备机配置一样。
配置HAProxy日志: vi /etc/syslog.conf
修改syslog内容,添加一行: local0.* /var/log/haproxy.log
重启rsyslog服务 service rsyslog restart
可以在/var/log下看到haproxy.log了
5 启用服务 全部配置完毕后,使用下面命令启动服务: service keepalived start
keepalived会自动把haproxy启动 chkconfig keepalived on
让keepalived开机自启动。
6 启用LDAPS代理 如果同时还要添加636的SSL ldap认证,还需要为DC安装证书 因为我们有多个DC服务器,所以需呀一张类似Exchange的SAN证书,即多域名证书。可以通过Exchange服务器上的证书申请功能申请,也可以直接像CA申请,这里讲解直接像CA申请,因为比较复杂:
登录CA服务器,打开PowerShell,输入: certutil-setreg policy\EditFlags +EDITF_ATTRIBUTESUBJECTALTNAME2 net stop certsvc net start certsvc 该命令允许CA接受SAN证书的申请。
在申请证书网站的界面的Attribute属性中,输入: san:dns=dc03.xxx.com&dns=ldap.xxx.com.com&dns=dc04.xxx.com&dns=dc05.xxx.com&dns=dc06.xxx.com 提交证书申请后,就会得到一张多域名证书。将其安装在各DC上。
在HAProxy脚本加入下面内容: frontendldap_ssl bind *:636 default_backend pool_ssl backendpool_ssl balance roundrobin mode tcp server DC03 10.1.1.3:636 check inter 5000#LDAP服务器 server DC04 10.1.1.4:636 check inter 5000 server DC05 10.1.1.5:636 check inter 5000 server DC06 10.1.1.6:636 check inter 5000
重启服务后,整个代理环境就算配置完成了。
边栏推荐
- Uncover the secret! Pay attention to those machines under the membership system!
- 60天远程办公经验分享 | 社区征文
- Community interview -- jumpserver open source fortress in the eyes of an it newcomer
- Selection of materials for space conductive disc slip ring
- 如何从外表判断导电滑环的质量
- Final review [microcomputer principle]
- How do I audit Active Directory User account changes?
- 2021 CCPC 哈尔滨 J. Local Minimum (思维题)
- 60 days of remote office experience sharing | community essay solicitation
- Analysis on the true topic of "cost management" by Guangdong second-class cost engineer
猜你喜欢

时钟树综合(CTS)

Hangfire详解

"Xiaodeng" in operation and maintenance monitors user login operations in real time
![[compilation principle] semantic analysis](/img/2e/9c17da3dbc758b2985e55201c73f99.png)
[compilation principle] semantic analysis

LSF bsub command

"Xiaodeng" ad domain delegation for operation and maintenance

"Xiaodeng" active directory password expiration notification function is available for operation and maintenance

Win7 easy connect 提示:选路连接失败,可能当前连接网络异常,请稍后重试

Three. JS development: drawing of thick lines

「运维有小邓」实时监控用户登录操作
随机推荐
18. `bs对象.节点名.next_sibling` previous_sibling 获取兄弟节点
利用积分商城游戏进行营销需要避免哪些问题出现?
fastadmin后台设置单选按钮
Set up your own website (12)
annotation
Oracle保留字查询
Three. JS development: drawing of thick lines
偶然发现了另一种跨域方式,不知道有没有人这么玩过
Jupyter服务安装及启动
Alibaba cloud released the atlas of China's robot industry (2022), 122 Pages pdf
18. `bs object Node name next_ sibling` previous_ Sibling get sibling node
Liunx instruction
How to evaluate iFLYTEK AI translation pen P20 series? Is it worth buying?
Fastadmin background setting radio button
量子机器学习的基础和应用:一个简明文献综述
Mapbox GL development tutorial (12): loading surface layer data
导航【微机原理】
Comparable comparator writing & ClassCastException class conversion exception
Exit operation in project
如何评价科大讯飞AI翻译笔P20系列,值得买吗?