目录
一、背景需求
二、实现方法
1、查看自启动脚本
2、将启动脚本拷贝到/etc/init.d目录
3、修改zabbix_agentd启动脚本
4、启动zabbix_agentd服务
5、设置开机自动启动
编译完zabbix-agent后,生成sbin/zabbix_agentd启动命令,需求是希望zabbix_agentd以服务的形式启动,并能开机自启动。
在源码包路径下,有脚本文件:
/usr/local/src/zabbix/misc/init.d/fedora/core5/zabbix_agentd
查看脚本文件内容命令:
cat zabbix_agentd
[root@localhost tru64]# cat zabbix_agentd
#!/bin/bash
# /etc/rc.d/init.d/zabbix_agentd
# Starts the zabbix_agentd daemon
# chkconfig: - 95 5
# description: Zabbix Monitoring Agent
# processname: zabbix_agentd
# pidfile: /tmp/zabbix_agentd.pid
# Modified for Zabbix 2.0.0
# May 2012, Zabbix SIA
# Source function library.
. /etc/init.d/functions
RETVAL=0
prog="Zabbix Agent"
ZABBIX_BIN="/usr/local/sbin/zabbix_agentd"
if [ ! -x ${ZABBIX_BIN} ] ; then
echo -n "${ZABBIX_BIN} not installed! "
# Tell the user this has skipped
exit 5
fi
start() { echo -n $"Starting $prog: "
daemon $ZABBIX_BIN
RETVAL=$?
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/zabbix_agentd
echo}
stop() { echo -n $"Stopping $prog: "
killproc $ZABBIX_BIN
RETVAL=$?
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/zabbix_agentd
echo}
case "$1" in start)
start ;; stop)
stop ;; reload|restart)
stop sleep 10 start
RETVAL=$?;; condrestart)
if [ -f /var/lock/subsys/zabbix_agentd ]; then
stop start fi ;; status)
status $ZABBIX_BIN RETVAL=$? ;; *)
echo $"Usage: $0 {condrestart|start|stop|restart|reload|status}"
exit 1
esac
exit $RETVAL
源码包在/usr/local/src/目录,执行拷贝命令:
cp /usr/local/src/zabbix/misc/init.d/fedora/core5/zabbix_agentd /etc/init.d/
将DAEMON启动命令路径修改为安装时指定的路径。
实际环境中DAEMON是引用ZABBIX_BIN
所以修改文件内容为:ZABBIX_BIN=”/usr/local/zabbix-agent/sbin/zabbix_agentd”
执行服务启动命令:
/etc/init.d/zabbix_agentd start
出现警告:Warning: The unit file, source configuration file or drop-ins of zabbix_agentd.service changed on disk. Run 'systemctl daemon-reload' to reload units.
解决方法:执行systemctl daemon-reload赋予执行权限即可
设置开机自启动命令:
systemctl enable zabbix_agentd
出现提示:zabbix_agentd.service is not a native service, redirecting to systemd-sysv-install.
Executing: /usr/lib/systemd/systemd-sysv-install enable zabbix_agentd
解决方法:执行/usr/lib/systemd/systemd-sysv-install enable zabbix_agentd即可。
本文发布于:2024-01-29 01:12:40,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170646196511649.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |