扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:田逸 来源:IT168 2009年9月27日
关键字: 负载均衡 keepalived
在本页阅读全文(共4页)
三、keepalived 安装验证
Keepalived安装完成后,会在安装目录/usr/local/keepalived生成 bin,etc,man,sbin这4个目录。其中etc为配置文件所在的目录,进入这个目录,看看里面都有些什么?
[root@ChinaTelecom-1 etc]# pwd
/usr/local/keepalived/etc
[root@ChinaTelecom-1 etc]# ll
total 12
drwxr-xr-x 3 root root 4096 Apr 23 10:23 keepalived
drwxr-xr-x 3 root root 4096 Apr 23 10:23 rc.d
drwxr-xr-x 2 root root 4096 Apr 23 10:23 sysconfig
还有子目录,这里着重关注一下keepalived目录,它的下面包含一个完整的配置文件keepalived.conf(实际上是一个样例)以及一些单独的配置样例文件。
[root@ChinaTelecom-1 keepalived]# tree -l
.
|-- keepalived.conf
`-- samples
|-- client.pem
|-- dh1024.pem
|-- keepalived.conf.HTTP_GET.port
|-- keepalived.conf.SMTP_CHECK
|-- keepalived.conf.SSL_GET
|-- keepalived.conf.fwmark
|-- keepalived.conf.inhibit
|-- keepalived.conf.misc_check
|-- keepalived.conf.misc_check_arg
|-- keepalived.conf.sample
|-- keepalived.conf.status_code
|-- keepalived.conf.track_interface
|-- keepalived.conf.virtual_server_group
|-- keepalived.conf.virtualhost
|-- keepalived.conf.vrrp
|-- keepalived.conf.vrrp.localcheck
|-- keepalived.conf.vrrp.lvs_syncd
|-- keepalived.conf.vrrp.routes
|-- keepalived.conf.vrrp.scripts
|-- keepalived.conf.vrrp.static_ipaddress
|-- keepalived.conf.vrrp.sync
|-- root.pem
`-- sample.misccheck.smbcheck.sh
值得注意的是,keepalived的启动过程并不会对配置文件进行语法检查,就算没有配置文件,keepalived的守护进程照样能够被运行起来。在默认状态下--即不指定配置文件的位置-keepalived先查找文件 /etc/keepalived/keepalived.conf ,如果为了省事,可以手动创建这个文件,然后在这个文件里书写规则,来达到控制keepalived运行的目的。
这里我们先来试试默认情况,即没有配置文件下运行keepalived.运行前先了解一下其语法:
[root@lvs-m keepalived]# keepalived --help
Keepalived v1.1.17 (06/23,2009)
Usage:
keepalived
keepalived -n
keepalived -f keepalived.conf
keepalived -d
keepalived -h
keepalived -v
Commands:
Either long or short options are allowed.
keepalived --vrrp -P Only run with VRRP subsystem.
keepalived --check -C Only run with Health-checker subsystem.
keepalived --dont-release-vrrp -V Dont remove VRRP VIPs & VROUTEs on daemon stop.
keepalived --dont-release-ipvs -I Dont remove IPVS topology on daemon stop.
keepalived --dont-fork -n Dont fork the daemon process.
keepalived --use-file -f Use the specified configuration file.
Default is /etc/keepalived/keepalived.conf.
keepalived --dump-conf -d Dump the configuration data.
keepalived --log-console -l Log message to local console.
keepalived --log-detail -D Detailed log messages.
keepalived --log-facility -S 0-7 Set syslog facility to LOG_LOCAL[0-7]. (default=LOG_DAEMON)
keepalived --help -h Display this short inlined help screen.
keepalived --version -v Display the version number
keepalived --pid -p pidfile
keepalived --checkers_pid -c checkers pidfile
keepalived --vrrp_pid -r vrrp pidfile
接下来我们参照这个帮助语法,执行命令 /usr/local/keepalived/sbin/keepalive -D ,然后来检查keepalived运行后的状况。
1、 查看进程 ps aux | grep keepalived ,其输出为:
[root@lvs-m ~]# ps aux| grep keepalived |grep -v grep
root 21786 0.0 0.0 4840 564 ? Ss 15:39 0:00 keepalived -D
root 21787 4.8 0.0 4884 1336 ? S 15:39 23:47 keepalived -D
root 21788 4.9 0.0 4884 904 ? S 15:39 24:15 keepalived -D
Keepalived正常运行时,共启动3个进程,其中一个进程是父进程,负责监控其子进程;一个是vrrp子进程;另外一个是checkers子进程。图2 为keepalived 3个进程之间的关系。
图2keepalived进程相关性
2、 查看内核模块,ip_vs 模块应该被加载到内核空间。 Lsmod | grep ip_vs .
3、 查看系统日志。因为我在启动keepalived是使用了选项 -D ,这将详细的打印日志消息。
[root@lvs-m ~]# tail -f /var/log/messages
Jun 27 00:58:05 lvs-m Keepalived: Starting VRRP child process, pid=22017
Jun 27 00:58:05 lvs-m Keepalived_healthcheckers: Netlink reflector reports IP 61.135.20.137 added
Jun 27 00:58:05 lvs-m Keepalived_healthcheckers: Registering Kernel netlink reflector
Jun 27 00:58:05 lvs-m Keepalived_vrrp: Netlink reflector reports IP 61.135.20.137 added
Jun 27 00:58:05 lvs-m Keepalived_healthcheckers: Registering Kernel netlink command channel
Jun 27 00:58:05 lvs-m Keepalived_vrrp: Registering Kernel netlink reflector
Jun 27 00:58:05 lvs-m Keepalived_vrrp: Registering Kernel netlink command channel
Jun 27 00:58:05 lvs-m Keepalived_vrrp: Registering gratutious ARP shared channel
Jun 27 00:58:05 lvs-m Keepalived_healthcheckers: Configuration is using : 2285 Bytes
Jun 27 00:58:05 lvs-m Keepalived_vrrp: Configuration is using : 28803 Bytes
逐项检查这个输出,可知图1所示的组件都可以在这里找到对应的纪录。从而进一步证实keepalived安装的正确性。
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者