Centos6.5 安装Keepalived教程:配置与启动

需积分: 18 5 下载量 15 浏览量 更新于2024-09-13 收藏 56KB DOCX 举报
"在CentOS 6.5环境中安装keepalived 1.1.20版本的步骤详解如下: 首先,确认系统的内核版本,CentOS 6.5使用的是2.6.32-431.el6.x86_64。由于keepalived依赖于特定的内核模块,因此需要创建一个指向实际内核源代码目录的软链接,以便编译时能找到所需的库。在终端中执行: ``` ln -s /usr/src/kernels/2.6.32-431.el6.x86_64 /usr/src/linux ``` 接下来,为了安装keepalived及其依赖项,运行以下命令以通过YUM安装必要的开发工具: ``` yum install openssl-devel popt-devel libnl-devel ``` 然后,开始编译keepalived。解压下载的keepalived-1.1.20.tar.gz包,并进入目录: ``` tar -zxvf keepalived-1.1.20.tar.gz cd keepalived-1.1.20 ``` 进行配置,指定安装路径和内核目录: ``` ./configure --prefix=/usr/local/keepalived --with-kernel-dir=/usr/src/kernels/2.6.32-431.el6.x86_64 ``` 接着执行编译和安装: ``` make && makeinstall ``` 安装完成后,设置keepalived在系统启动时自动运行。复制必要的启动脚本和服务配置到对应位置: ``` cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/rc.d/init.d/ cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/ cp /usr/local/keepalived/sbin/keepalived /usr/sbin/ chkconfig keepalived on ``` 由于keepalived默认会在启动时查找配置文件,因此创建一个配置文件夹并复制预置的配置文件: ``` mkdir /etc/keepalived cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/ ``` 最后,编辑配置文件(例如使用vi)来定义具体的VRRP(虚拟路由冗余协议)配置、通知邮件地址等。一个基本的keepalived配置可能包括以下几个部分: ```bash global_defs { notification_email { acassen@firewall.loc failover@firewall.loc sysadmin@firewall.loc } notification_email_from Alexandre.Cassen@firewall.loc smtp_server "your_smtp_server_address" } vrrp_instance VI_1 { state MASTER interface eth0 virtual_ipaddress { 192.168.1.1 } ... } ``` 记得替换`your_smtp_server_address`为你自己的SMTP服务器地址。 完成以上步骤后,你可以通过`service keepalived start`命令启动keepalived服务,或使用`chkconfig keepalived start`使其在下次系统重启时自动启动。务必检查配置文件的正确性,以确保高可用服务的正常运行。"