【Linux】centos下进行keepalived安装部署

配置环境:centos7.9

[root@yyq ~]#  cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)

配置步骤

1.安装keepalived模块

yum install -y keepalived

日志:

[root@yyq ~]#  yum install -y keepalived
Loaded plugins: fastestmirror, priorities, versionlock
Loading mirror speeds from cached hostfile
name                                                                                          | 3.6 kB  00:00:00     
Resolving Dependencies
--> Running transaction check
---> Package keepalived.x86_64 0:1.3.5-19.el7 will be installed
--> Processing Dependency: libnetsnmpmibs.so.31()(64bit) for package: keepalived-1.3.5-19.el7.x86_64
--> Processing Dependency: libnetsnmpagent.so.31()(64bit) for package: keepalived-1.3.5-19.el7.x86_64
--> Running transaction check
---> Package net-snmp-agent-libs.x86_64 1:5.7.2-49.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=====================================================================================================================
 Package                            Arch                  Version                          Repository           Size
=====================================================================================================================
Installing:
 keepalived                         x86_64                1.3.5-19.el7                     name                332 k
Installing for dependencies:
 net-snmp-agent-libs                x86_64                1:5.7.2-49.el7                   name                708 k

Transaction Summary
=====================================================================================================================
Install  1 Package (+1 Dependent package)

Total download size: 1.0 M
Installed size: 3.0 M
Downloading packages:
(1/2): keepalived-1.3.5-19.el7.x86_64.rpm                                                     | 332 kB  00:00:00     
(2/2): net-snmp-agent-libs-5.7.2-49.el7.x86_64.rpm                                            | 708 kB  00:00:00     
---------------------------------------------------------------------------------------------------------------------
Total                                                                                1.1 MB/s | 1.0 MB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : 1:net-snmp-agent-libs-5.7.2-49.el7.x86_64                                                         1/2 
  Installing : keepalived-1.3.5-19.el7.x86_64                                                                    2/2 
  Verifying  : 1:net-snmp-agent-libs-5.7.2-49.el7.x86_64                                                         1/2 
  Verifying  : keepalived-1.3.5-19.el7.x86_64                                                                    2/2 

Installed:
  keepalived.x86_64 0:1.3.5-19.el7                                                                                   

Dependency Installed:
  net-snmp-agent-libs.x86_64 1:5.7.2-49.el7                                                                          

Complete!
[root@yyq ~]# 

2.配置keepalived

配置keepalived的配置文件keepalived.conf:

vi /etc/keepalived/keepalived.conf

文件内容如下
(其中的interface、priority和virtual_ipaddress按需修改,两台服务器的priority需要不同,priority较大的默认是主服务器):
interface对应网卡名称
查看网卡

[root@yyq ~]#  ifconfig
eth0: flags=4111<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1450
        inet 192.168.1.98  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 1111::f111:1111:1111:1111  prefixlen 64  scopeid 0x20<link>
        ether 11:11:11:11:11:11  txqueuelen 1000  (Ethernet)
        RX packets 9122848  bytes 6131066305 (5.7 GiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 3059946  bytes 1479130540 (1.3 GiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

keepalived.conf配置

[root@yyq ~]#  vi /etc/keepalived/keepalived.conf
! Configuration File for keepalived

vrrp_instance VI_1 {
  state BACKUP
  interface eth0
  virtual_router_id 94
  priority 110
  advert_int 1
  authentication {
      auth_type PASS
      auth_pass 1234
  }
  virtual_ipaddress {
      192.168.1.101
  }
}

~

3.启动keepalived

在服务器上执行:

systemctl start keepalived
systemctl enable keepalived

日志

[root@yyq ~]#  systemctl start keepalived
[root@yyq ~]#  systemctl enable keepalived
Created symlink from /etc/systemd/system/multi-user.target.wants/keepalived.service to /usr/lib/systemd/system/keepalived.service.
[root@yyq ~]#

4.检查虚拟IP是否正常

在任意一台服务器上执行:

ssh <虚拟IP地址>

如果可以成功登陆priority较大的那台服务器,则表示配置成功。
日志:

[root@yyq /etc/keepalived]#  ssh 192.168.1.101
The authenticity of host '192.168.1.101 (192.168.1.101)' can't be established.
ED25519 key fingerprint is SHA256:V1111111111111111.
This host key is known by the following other names/addresses:
    ~/.ssh/known_hosts:1: 192.168.1.197
    ~/.ssh/known_hosts:4: 192.168.1.210
    ~/.ssh/known_hosts:5: 192.168.1.196
    ~/.ssh/known_hosts:6: 192.168.1.203
    ~/.ssh/known_hosts:7: 192.168.1.211
    ~/.ssh/known_hosts:11: 192.168.1.208
    ~/.ssh/known_hosts:12: 192.168.1.215
    ~/.ssh/known_hosts:13: 192.168.1.204
    (2 additional names omitted)
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '192.168.1.101' (ED25519) to the list of known hosts.
Authorized only. All activity will be monitored and reported
root@192.168.1.101's password: 
Last login: Mon Mar 21 11:01:15 2022 from 192.168.1.236
Authorized users only. All activity may be monitored and reported
[root@yyq ~]#  ifconfig
eth0: flags=4111<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1450
        inet 192.168.1.98  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 1111::f111:1111:1111:1111  prefixlen 64  scopeid 0x20<link>
        ether 11:11:11:11:11:11  txqueuelen 1000  (Ethernet)
        RX packets 9122848  bytes 6131066305 (5.7 GiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 3059946  bytes 1479130540 (1.3 GiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

参考:
内部部署文档

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
安装部署keepalived的步骤如下: 1. 首先,准备一个centos7.7-x86操作系统环境,并将keepalived安装包上传到指定目录,比如/kp/keepalived。 2. 使用以下命令进行编译安装: ``` ./configure --prefix=/data/keepalived --sysconf=/etc #### 引用[.reference_title] - *1* [linux安装部署keepalived,利用keepalived多台nginx虚拟IP浮动](https://download.csdn.net/download/weixin_38639747/14052657)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [keepalived安装部署](https://blog.csdn.net/huanglm_OneWholeLife/article/details/124530257)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [Keepalived安装部署](https://blog.csdn.net/weixin_44218180/article/details/120535998)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

实施工程师木易

感谢支持

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值