• 售前

  • 售后

热门帖子
入门百科

详解centos7中设置keepalived日志为别的路径

[复制链接]
凌8乱 显示全部楼层 发表于 2021-10-25 18:52:28 |阅读模式 打印 上一主题 下一主题
keepalived 安装:
  1. cd <keepalived_sourcecode_path>
  2. ./configure --prefix=/usr/local/keepalived
  3. make && make install
  4. mkdir /etc/keepalived
  5. mkdir /etc/keepalived/scripts
  6. cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/
  7. cp /root/keepalived-2.0.6/keepalived/etc/init.d/keepalived /etc/init.d/
  8. cp /usr/local/keepalived/sbin/keepalived /sbin/keepalived
  9. cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
  10. chmod +x /etc/init.d/keepalived
复制代码
由于在默认状态下keepalived的日记会写入到/var/log/message中,我们必要将此剥离出来。
在centos 6下可以:
(1)起首修改/etc/sysconfig/keepalived文件,表明掉如下,添加如下:
  1. #KEEPALIVED_OPTIONS="-D"
  2. KEEPALIVED_OPTIONS="-D -d -S 0"
复制代码
(2)其次修改 /etc/rsyslog.conf 文件,添加如下:
  1. local0.* /var/log/keepalived.log
复制代码
在centos 7 下,还必要修改/lib/systemd/system/keepalived.service 文件:
centos 7利用。因为centos 7利用systemctl,通过systemctl调用service,以是必要修改/lib/systemd/system/keepalived.service文件。

将内里的:
  1. EnvironmentFile=-/usr/local/keepalived/etc/sysconfig/keepalived
  2. ExecStart=/usr/local/keepalived/sbin/keepalived $KEEPALIVED_OPTIONS
复制代码
修改成:
  1. EnvironmentFile=/etc/sysconfig/keepalived
  2. ExecStart=/sbin/keepalived $KEEPALIVED_OPTIONS
复制代码
然后重新加载service:
  1. systemctl daemon-reload
复制代码
整体的思绪就是,
1. 通过systemctl start keepalived去启动;
2. 启动keepalived的时间,会去读service的设置文件:/lib/systemd/system/keepalived.service;
3. 在service的设置文件时:
3.1 启动文件路径ExecStart=/sbin/keepalived $KEEPALIVED_OPTIONS,即启动方式是带情况变量文件中参数来启动;
3.2 读取情况变量参数EnvironmentFile=/etc/sysconfig/keepalived。
4. $KEEPALIVED_OPTIONS参数是在/etc/sysconfig/keepalived的设置;我们设置的是KEEPALIVED_OPTIONS="-D -d -S 0";而-S是syslog的facility,0表示放在local0,在/etc/rsyslog.conf 中设置local0.* /var/log/keepalived.log
5. 以是,写日记就去/var/log/keepalived.log了。
以上就是本文的全部内容,盼望对各人的学习有所资助,也盼望各人多多支持脚本之家。

帖子地址: 

回复

使用道具 举报

分享
推广
火星云矿 | 预约S19Pro,享500抵1000!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

草根技术分享(草根吧)是全球知名中文IT技术交流平台,创建于2021年,包含原创博客、精品问答、职业培训、技术社区、资源下载等产品服务,提供原创、优质、完整内容的专业IT技术开发社区。
  • 官方手机版

  • 微信公众号

  • 商务合作