linux 配置keeplive
时间: 2023-08-09 13:05:34 浏览: 77
keepalived配置
在 Linux 中配置 keepalive 的步骤如下:
1. 安装 keepalive
使用以下命令安装 keepalive:
```
sudo apt-get install keepalived
```
2. 配置 keepalive
keepalive 的配置文件在 `/etc/keepalived/keepalived.conf`,你需要修改它以适应你的环境。以下是一个示例配置文件:
```
vrrp_script chk_http_port {
script "/etc/keepalived/check_http.sh"
interval 2
}
vrrp_instance VI_1 {
interface eth0
state MASTER
virtual_router_id 51
priority 101
virtual_ipaddress {
192.168.1.10/24 dev eth0
}
track_script {
chk_http_port
}
}
```
这个配置文件定义了一个名称为 `VI_1` 的 VRRP 实例,使用 `eth0` 接口作为虚拟路由器的接口,虚拟路由器 ID 为 51,优先级为 101,虚拟 IP 地址为 `192.168.1.10/24`,并且使用脚本 `check_http.sh` 检查 HTTP 端口。
3. 启动 keepalive
使用以下命令启动 keepalive:
```
sudo systemctl start keepalived
```
如果需要在系统启动时自动启动 keepalive,可以使用以下命令:
```
sudo systemctl enable keepalived
```
如果需要停止 keepalive,可以使用以下命令:
```
sudo systemctl stop keepalived
```
如果需要查看 keepalive 的状态,可以使用以下命令:
```
sudo systemctl status keepalived
```
如果 keepalive 正常运行,你应该会看到一个类似下面的输出:
```
● keepalived.service - LVS and VRRP High Availability Monitor
Loaded: loaded (/lib/systemd/system/keepalived.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2021-10-12 11:11:11 CST; 1h 23min ago
Main PID: 1234 (keepalived)
Tasks: 2 (limit: 4915)
Memory: 1.2M
CPU: 3.023s
CGroup: /system.slice/keepalived.service
└─1234 /usr/sbin/keepalived -D -P -l -f /etc/keepalived/keepalived.conf -n
Oct 12 11:11:11 ubuntu systemd[1]: Started LVS and VRRP High Availability Monitor.
```
阅读全文