Java充电社
专辑
博文
联系我
本人继续续收门徒,亲手指导
Linux专题第24篇:安装keepalived
相关专辑:
Linux专题
<div style="display:none"></div> ## 1、keepalived作用 > Keepalived是基于vrrp协议的一款高可用软件。它的作用是检测服务器的状态,如果有一台web服务器宕机,或工作出现故障,Keepalived将检测到,并将有故障的服务器从系统中剔除,同时使用其他服务器代替该服务器的工作,当服务器工作正常后Keepalived自动将服务器加入到服务器群中,这些工作全部自动完成,不需要人工干涉,需要人工做的只是修复故障的服务器。 ## 2、keepalived安装 ### 1)、下载 下载地址:<a href="https://www.keepalived.org/" target="_blank">https://www.keepalived.org/</a>,我们下载2.2.7 ![](https://itsoku.oss-cn-hangzhou.aliyuncs.com/itsoku/blog/article/346/90097b86-b716-4b2b-8af2-a87d9e4058d6.png) ### 2)、上传到服务器 ```shell [root@test001 soft]# pwd /opt/soft [root@test001 soft]# ls keepalived-2.2.7.tar.gz nginx-1.20.2 nginx-1.20.2.tar.gz ``` ### 3)、先安装下面的依赖包 ```shell yum -y install libnl libnl-devel yum -y install openssl openssl-devel ``` ### 4)、解压 ```shell [root@test001 soft]# cd /opt/soft/ [root@test001 soft]# ls keepalived-2.2.7.tar.gz nginx-1.20.2 nginx-1.20.2.tar.gz [root@test001 soft]# tar -xzvf keepalived-2.2.7.tar.gz ``` ### 5)、安装 ```shell [root@test001 keepalived-2.2.7]# pwd /opt/soft/keepalived-2.2.7 [root@test001 keepalived-2.2.7]# ./configure --prefix=/usr/local/keepalived --sysconf=/etc [root@test001 keepalived-2.2.7]# make && make install ``` ### 6)、vi /etc/keepalived/keepalived.conf 内容如下 ```shell global_defs { # 路由id:当前安装keepalived节点主机的标识符,全局唯一 router_id keep_128 } vrrp_instance VI_1 { # 表示当前的128为ngxin的主节点,master state MASTER # 当前实例绑定的网卡名称:ifconfig可以查看 interface ens33 # 保证主备节点一致 virtual_router_id 51 # 优先级/权重,谁的优先级高,在master挂掉以后,就能成为master priority 100 # 主备之间同步检查的时间间隔,默认1s advert_int 1 # 认证授权的密码,防止非法的节点进入 authentication { auth_type PASS auth_pass 1111 } # VIP virtual_ipaddress { 192.168.216.130 } } ``` ### 7)、启动之前看一下ip ![](https://itsoku.oss-cn-hangzhou.aliyuncs.com/itsoku/blog/article/346/2a540883-aa70-41dc-a37d-f05ad1898b25.png) ### 8)、启动keepalived ```shell [root@test001 sbin]# pwd /usr/local/keepalived/sbin [root@test001 sbin]# ./keepalived ``` ### 9)、再次查看网卡,发现多了一个虚拟的网卡 ![](https://itsoku.oss-cn-hangzhou.aliyuncs.com/itsoku/blog/article/346/9266ba1e-a9d9-40f6-bb83-3eecd662b065.png) ## 3、把keepalived注册为系统服务 进入到keepalived的解压目录,拷贝相关的文件 ```shell [root@test001 keepalived-2.2.7]# cd /opt/soft/keepalived-2.2.7/keepalived/etc/ [root@test001 etc]# pwd /opt/soft/keepalived-2.2.7/keepalived/etc [root@test001 etc]# cp init.d/keepalived /etc/init.d/ [root@test001 etc]# cp sysconfig/keepalived /etc/sysconfig/ cp:是否覆盖"/etc/sysconfig/keepalived"? y [root@test001 etc]# systemctl daemon-reload ``` 之后就可以使用systemctl进行启动、停止 ```shell [root@test001 etc]# systemctl stop keepalived.service [root@test001 etc]# systemctl start keepalived.service ``` <a style="display:none" target="_blank" href="https://mp.weixin.qq.com/s/_S1DD2JADnXvpexxaBwLLg" style="color:red; font-size:20px; font-weight:bold">继续收门徒,亲手带,月薪 4W 以下的可以来找我</a> ## 最新资料 1. <a href="https://mp.weixin.qq.com/s?__biz=MzkzOTI3Nzc0Mg==&mid=2247484964&idx=2&sn=c81bce2f26015ee0f9632ddc6c67df03&scene=21#wechat_redirect" target="_blank">尚硅谷 Java 学科全套教程(总 207.77GB)</a> 2. <a href="https://mp.weixin.qq.com/s?__biz=MzkwOTAyMTY2NA==&mid=2247484192&idx=1&sn=505f2faaa4cc911f553850667749bcbb&scene=21#wechat_redirect" target="_blank">2021 最新版 Java 微服务学习线路图 + 视频</a> 3. <a href="https://mp.weixin.qq.com/s?__biz=MzkwOTAyMTY2NA==&mid=2247484573&idx=1&sn=7f3d83892186c16c57bc0b99f03f1ffd&scene=21#wechat_redirect" target="_blank">阿里技术大佬整理的《Spring 学习笔记.pdf》</a> 4. <a href="https://mp.weixin.qq.com/s?__biz=MzkwOTAyMTY2NA==&mid=2247484544&idx=2&sn=c1dfe907cfaa5b9ae8e66fc247ccbe84&scene=21#wechat_redirect" target="_blank">阿里大佬的《MySQL 学习笔记高清.pdf》</a> 5. <a href="https://mp.weixin.qq.com/s?__biz=MzkwOTAyMTY2NA==&mid=2247485167&idx=1&sn=48d75c8e93e748235a3547f34921dfb7&scene=21#wechat_redirect" target="_blank">2021 版 java 高并发常见面试题汇总.pdf</a> 6. <a href="https://mp.weixin.qq.com/s?__biz=MzkwOTAyMTY2NA==&mid=2247485664&idx=1&sn=435f9f515a8f881642820d7790ad20ce&scene=21#wechat_redirect" target="_blank">Idea 快捷键大全.pdf</a> ![](https://itsoku.oss-cn-hangzhou.aliyuncs.com/itsoku/blog/article/1/2883e86e-3eff-404a-8943-0066e5e2b454.png)
相关专辑:
Linux专题