Zabbix启动脚本设置

warning: 这篇文章距离上次修改已过1224天,其中的内容可能已经有所变动。

接上篇,通过编译安装的zabbix,无法通过systemctl start/stop/status命令来管理,也无法通过systemctl enable/disable来设置开机启动,需要手动编辑创建.service脚本来实现,具体实现方法如下:

1.配置zabbix-server脚本

新建zabbix-server.service文件

vi /usr/lib/systemd/system/zabbix-server.service

然后输入以下内容:

[Unit]
Description=Zabbix Server
After=syslog.target
After=network.target

[Service]
Environment="CONFFILE=/usr/local/etc/zabbix_server.conf"
EnvironmentFile=-/etc/sysconfig/zabbix-server
Type=forking
Restart=on-failure
PIDFile=/tmp/zabbix_server.pid
KillMode=control-group
ExecStart=/usr/local/sbin/zabbix_server -c $CONFFILE
ExecStop=/bin/kill -SIGTERM $MAINPID
RestartSec=10s
TimeoutSec=0

[Install]
WantedBy=multi-user.target

2.配置zabbix-agent脚本

新建zabbix-agent.service文件

vi /usr/lib/systemd/system/zabbix-agent.service

然后输入以下内容:

[Unit]
Description=Zabbix Agent
After=syslog.target
After=network.target

[Service]
Environment="CONFFILE=/usr/local/etc/zabbix_agentd.conf"
EnvironmentFile=-/etc/sysconfig/zabbix-agent
Type=forking
Restart=on-failure
PIDFile=/tmp/zabbix_agentd.pid
KillMode=control-group
ExecStart=/usr/local/sbin/zabbix_agentd -c $CONFFILE
ExecStop=/bin/kill -SIGTERM $MAINPID
RestartSec=10s
User=zabbix
Group=zabbix

[Install]
WantedBy=multi-user.target

3.通过systemctl管理zabbix服务

zabbix-server

    systemctl start zabbix-server    #开启zabbix-server服务
    systemctl stop zabbix-server    #关闭zabbix-server服务
    systemctl status zabbix-server    #查看zabbix-server状态
    systemctl enable zabbix-server    #设置开机启动server
    systemctl disable zabbix-server    #关闭开机启动server

zabbix-agent

    systemctl start zabbix-agent    #开启zabbix-agent服务
    systemctl stop zabbix-agent    #关闭zabbix-agent服务
    systemctl status zabbix-agent    #查看zabbix-agent状态
    systemctl enable zabbix-agent    #设置开机启动agent
    systemctl disable zabbix-agent    #关闭开机启动agent

查看一下zabbix运行状态,如果显示绿色的Active: active (running),就说明zabbix正常运行了。

查看zabbix服务状态查看zabbix服务状态

添加新评论