Ubuntu操作系统编写zabbix的启动管理脚本
作者:尹正杰
版权声明:原创作品,谢绝转载!否则将追究法律责任。
一.修改zabbix的pid存放路径
1>.创建存放zabbix的pid目录
[[email protected] ~]# mkdir -v /yinzhengjie/softwares/zabbix/pid mkdir: created directory '/yinzhengjie/softwares/zabbix/pid' [[email protected] ~]#
2>.修改pid的目录权限
[[email protected] ~]# ll /yinzhengjie/softwares/zabbix/ total 0 drwxr-xr-x 8 zabbix zabbix 75 2月 14 10:37 ./ drwxr-xr-x 3 root root 20 2月 14 06:23 ../ drwxr-xr-x 2 zabbix zabbix 45 2月 14 06:23 bin/ drwxr-xr-x 4 zabbix zabbix 114 2月 14 10:39 etc/ drwxr-xr-x 3 zabbix zabbix 21 2月 14 06:23 lib/ drwxr-xr-x 2 root root 6 2月 14 10:37 pid/ drwxr-xr-x 3 zabbix zabbix 67 2月 14 06:23 sbin/ drwxr-xr-x 4 zabbix zabbix 31 2月 14 06:23 share/ [[email protected] ~]# [[email protected] ~]# chown zabbix:zabbix /yinzhengjie/softwares/zabbix/pid/ [[email protected] ~]# [[email protected] ~]# ll /yinzhengjie/softwares/zabbix/ total 0 drwxr-xr-x 8 zabbix zabbix 75 2月 14 10:37 ./ drwxr-xr-x 3 root root 20 2月 14 06:23 ../ drwxr-xr-x 2 zabbix zabbix 45 2月 14 06:23 bin/ drwxr-xr-x 4 zabbix zabbix 114 2月 14 10:39 etc/ drwxr-xr-x 3 zabbix zabbix 21 2月 14 06:23 lib/ drwxr-xr-x 2 zabbix zabbix 6 2月 14 10:37 pid/ drwxr-xr-x 3 zabbix zabbix 67 2月 14 06:23 sbin/ drwxr-xr-x 4 zabbix zabbix 31 2月 14 06:23 share/ [[email protected] ~]#
3>.修改zabbix server和zabbix agent的配置文件
[[email protected] ~]# grep PidFile= /yinzhengjie/softwares/zabbix/etc/zabbix_server.conf # PidFile=/tmp/zabbix_server.pid [[email protected] ~]# [[email protected] ~]# sed -r -i 's@# (PidFile=)/tmp@\1/yinzhengjie/softwares/zabbix/pid@' /yinzhengjie/softwares/zabbix/etc/zabbix_server.conf [[email protected] ~]# [[email protected] ~]# grep PidFile= /yinzhengjie/softwares/zabbix/etc/zabbix_server.conf PidFile=/yinzhengjie/softwares/zabbix/pid/zabbix_server.pid [[email protected] ~]#
[[email protected] ~]# grep PidFile= /yinzhengjie/softwares/zabbix/etc/zabbix_agentd.conf # PidFile=/tmp/zabbix_agentd.pid [[email protected] ~]# [[email protected] ~]# sed -r -i 's@# (PidFile=)/tmp@\1/yinzhengjie/softwares/zabbix/pid@' /yinzhengjie/softwares/zabbix/etc/zabbix_agentd.conf [[email protected] ~]# [[email protected] ~]# grep PidFile= /yinzhengjie/softwares/zabbix/etc/zabbix_agentd.conf PidFile=/yinzhengjie/softwares/zabbix/pid/zabbix_agentd.pid [[email protected] ~]# [[email protected] ~]#
二.修改zabbix server的log存放路径
1>.创建存放zabbix的log目录
[[email protected] ~]# ll /yinzhengjie/softwares/zabbix/ total 0 drwxr-xr-x 8 zabbix zabbix 75 Feb 14 12:20 ./ drwxr-xr-x 3 root root 20 Feb 14 06:23 ../ drwxr-xr-x 2 zabbix zabbix 45 Feb 14 06:23 bin/ drwxr-xr-x 4 zabbix zabbix 114 Feb 14 12:18 etc/ drwxr-xr-x 3 zabbix zabbix 21 Feb 14 06:23 lib/ drwxr-xr-x 2 zabbix zabbix 31 Feb 14 11:13 pid/ drwxr-xr-x 3 zabbix zabbix 67 Feb 14 06:23 sbin/ drwxr-xr-x 4 zabbix zabbix 31 Feb 14 06:23 share/ [[email protected] ~]# [[email protected] ~]# mkdir -v /yinzhengjie/softwares/zabbix/logs mkdir: created directory '/yinzhengjie/softwares/zabbix/logs' [[email protected] ~]# [[email protected] ~]# ll /yinzhengjie/softwares/zabbix/ total 0 drwxr-xr-x 9 zabbix zabbix 87 Feb 14 12:20 ./ drwxr-xr-x 3 root root 20 Feb 14 06:23 ../ drwxr-xr-x 2 zabbix zabbix 45 Feb 14 06:23 bin/ drwxr-xr-x 4 zabbix zabbix 114 Feb 14 12:18 etc/ drwxr-xr-x 3 zabbix zabbix 21 Feb 14 06:23 lib/ drwxr-xr-x 2 root root 6 Feb 14 12:20 logs/ drwxr-xr-x 2 zabbix zabbix 31 Feb 14 11:13 pid/ drwxr-xr-x 3 zabbix zabbix 67 Feb 14 06:23 sbin/ drwxr-xr-x 4 zabbix zabbix 31 Feb 14 06:23 share/ [[email protected] ~]# [[email protected] ~]#
2>.修改log的目录权限
[[email protected] ~]# ll /yinzhengjie/softwares/zabbix/ total 0 drwxr-xr-x 9 zabbix zabbix 87 Feb 14 12:20 ./ drwxr-xr-x 3 root root 20 Feb 14 06:23 ../ drwxr-xr-x 2 zabbix zabbix 45 Feb 14 06:23 bin/ drwxr-xr-x 4 zabbix zabbix 114 Feb 14 12:18 etc/ drwxr-xr-x 3 zabbix zabbix 21 Feb 14 06:23 lib/ drwxr-xr-x 2 root root 6 Feb 14 12:20 logs/ drwxr-xr-x 2 zabbix zabbix 31 Feb 14 11:13 pid/ drwxr-xr-x 3 zabbix zabbix 67 Feb 14 06:23 sbin/ drwxr-xr-x 4 zabbix zabbix 31 Feb 14 06:23 share/ [[email protected] ~]# [[email protected] ~]# chown zabbix:zabbix /yinzhengjie/softwares/zabbix/logs [[email protected] ~]# [[email protected] ~]# ll /yinzhengjie/softwares/zabbix/ total 0 drwxr-xr-x 9 zabbix zabbix 87 Feb 14 12:20 ./ drwxr-xr-x 3 root root 20 Feb 14 06:23 ../ drwxr-xr-x 2 zabbix zabbix 45 Feb 14 06:23 bin/ drwxr-xr-x 4 zabbix zabbix 114 Feb 14 12:18 etc/ drwxr-xr-x 3 zabbix zabbix 21 Feb 14 06:23 lib/ drwxr-xr-x 2 zabbix zabbix 6 Feb 14 12:20 logs/ drwxr-xr-x 2 zabbix zabbix 31 Feb 14 11:13 pid/ drwxr-xr-x 3 zabbix zabbix 67 Feb 14 06:23 sbin/ drwxr-xr-x 4 zabbix zabbix 31 Feb 14 06:23 share/ [[email protected] ~]# [[email protected] ~]#
3>.修改zabbix server的配置文件
[[email protected] ~]# grep ^LogFile= /yinzhengjie/softwares/zabbix/etc/zabbix_server.conf LogFile=/tmp/zabbix_server.log [[email protected] ~]# [[email protected] ~]# sed -r -i 's#(LogFile=)/tmp#\1/yinzhengjie/softwares/zabbix/logs#' /yinzhengjie/softwares/zabbix/etc/zabbix_server.conf [[email protected] ~]# [[email protected] ~]# grep ^LogFile= /yinzhengjie/softwares/zabbix/etc/zabbix_server.conf LogFile=/yinzhengjie/softwares/zabbix/logs/zabbix_server.log [[email protected] ~]# [[email protected] ~]#
三.查看CentOS 6.x操作系统使用的脚本(不推荐使用)
[[email protected] ~]# ll /usr/local/src/zabbix-4.0.17/misc/init.d/ total 44 drwxr-xr-x 10 1001 1001 4096 Jan 28 14:36 ./ drwxr-xr-x 5 1001 1001 4096 Feb 14 13:11 ../ drwxr-xr-x 2 1001 1001 4096 Jan 28 14:36 aix/ drwxr-xr-x 2 1001 1001 4096 Jan 28 14:36 debian/ drwxr-xr-x 4 1001 1001 4096 Jan 28 14:36 fedora/ drwxr-xr-x 2 1001 1001 4096 Jan 28 14:36 freebsd/ drwxr-xr-x 2 1001 1001 4096 Jan 28 14:36 gentoo/ -rw-r--r-- 1 1001 1001 230 Jan 28 14:36 README drwxr-xr-x 5 1001 1001 4096 Jan 28 14:36 suse/ drwxr-xr-x 2 1001 1001 4096 Jan 28 14:36 tru64/ drwxr-xr-x 2 1001 1001 4096 Jan 28 14:36 ubuntu/ [[email protected] ~]#
四.编写zabbix-server的启动脚本(需要做第一步和第二步)
1>.编写脚本"/lib/systemd/system/zabbix-server.service"
[[email protected] ~]# vim /lib/systemd/system/zabbix-server.service [[email protected] ~]# [[email protected] ~]# cat /lib/systemd/system/zabbix-server.service [Unit] Description=Yinzhengjie's Zabbix Server After=syslog.target After=network.target After=mysql.service After=mysqld.service After=mariadb.service [Service] Environment="CONFFILE=/yinzhengjie/softwares/zabbix/etc/zabbix_server.conf" EnvironmentFile=-/etc/default/zabbix-server Type=forking Restart=on-failure PIDFile=/yinzhengjie/softwares/zabbix/pid/zabbix_server.pid KillMode=control-group ExecStart=/yinzhengjie/softwares/zabbix/sbin/zabbix_server -c $CONFFILE ExecStop=/bin/kill -SIGTERM $MAINPID RestartSec=10s TimeoutSec=infinity [Install] WantedBy=multi-user.target [[email protected] ~]# [[email protected] ~]# systemctl daemon-reload [[email protected] ~]#
[[email protected] ~]# sync [[email protected] ~]#
2>.使用脚本管理zabbix server服务
[[email protected] ~]# ss -untlp | grep zabbix tcp LISTEN 0 128 0.0.0.0:10051 0.0.0.0:* users:(("zabbix_server",pid=111386,fd=4),("zabbix_server",pid=111385,fd=4),("zabbix_server",pid=111384,fd=4),("zabbix_server",pid=111383,fd=4),("zabbix_server",pid=111382,fd=4),("zabbix_ser ver",pid=111381,fd=4),("zabbix_server",pid=111380,fd=4),("zabbix_server",pid=111379,fd=4),("zabbix_server",pid=111378,fd=4),("zabbix_server",pid=111377,fd=4),("zabbix_server",pid=111376,fd=4),("zabbix_server",pid=111375,fd=4),("zabbix_server",pid=111374,fd=4),("zabbix_server",pid=111373,fd=4),("zabbix_server",pid=111372,fd=4),("zabbix_server",pid=111371,fd=4),("zabbix_server",pid=111370,fd=4),("zabbix_server",pid=111369,fd=4),("zabbix_server",pid=111368,fd=4),("zabbix_server",pid=111367,fd=4),("zabbix_server",pid=111366,fd=4),("zabbi_server",pid=111365,fd=4),("zabbix_server",pid=111364,fd=4),("zabbix_server",pid=111363,fd=4),("zabbix_server",pid=111362,fd=4),("zabbix_server",pid=111361,fd=4),("zabbix_server",pid=111360,fd=4),("zabbix_server",pid=111359,fd=4),("zabbix_server",pid=111358,fd=4),("zabbix_server",pid=111357,fd=4),("zabbix_server",pid=111356,fd=4),("zabbix_server",pid=111355,fd=4),("zabbix_server",pid=111354,fd=4),("zabbix_server",pid=111341,fd=4))[[email protected] ~]# [[email protected] ~]# systemctl restart zabbix-server.service [[email protected] ~]# [[email protected] ~]# ss -untlp | grep zabbix tcp LISTEN 0 128 0.0.0.0:10051 0.0.0.0:* users:(("zabbix_server",pid=111615,fd=4),("zabbix_server",pid=111614,fd=4),("zabbix_server",pid=111613,fd=4),("zabbix_server",pid=111612,fd=4),("zabbix_server",pid=111611,fd=4),("zabbix_ser ver",pid=111610,fd=4),("zabbix_server",pid=111609,fd=4),("zabbix_server",pid=111608,fd=4),("zabbix_server",pid=111607,fd=4),("zabbix_server",pid=111606,fd=4),("zabbix_server",pid=111605,fd=4),("zabbix_server",pid=111604,fd=4),("zabbix_server",pid=111603,fd=4),("zabbix_server",pid=111602,fd=4),("zabbix_server",pid=111601,fd=4),("zabbix_server",pid=111600,fd=4),("zabbix_server",pid=111599,fd=4),("zabbix_server",pid=111598,fd=4),("zabbix_server",pid=111597,fd=4),("zabbix_server",pid=111596,fd=4),("zabbix_server",pid=111595,fd=4),("zabbi_server",pid=111594,fd=4),("zabbix_server",pid=111593,fd=4),("zabbix_server",pid=111592,fd=4),("zabbix_server",pid=111591,fd=4),("zabbix_server",pid=111590,fd=4),("zabbix_server",pid=111589,fd=4),("zabbix_server",pid=111588,fd=4),("zabbix_server",pid=111587,fd=4),("zabbix_server",pid=111586,fd=4),("zabbix_server",pid=111585,fd=4),("zabbix_server",pid=111584,fd=4),("zabbix_server",pid=111578,fd=4),("zabbix_server",pid=111570,fd=4))[[email protected] ~]#
[[email protected] ~]# ss -untlp | grep zabbix tcp LISTEN 0 128 0.0.0.0:10051 0.0.0.0:* users:(("zabbix_server",pid=111615,fd=4),("zabbix_server",pid=111614,fd=4),("zabbix_server",pid=111613,fd=4),("zabbix_server",pid=111612,fd=4),("zabbix_server",pid=111611,fd=4),("zabbix_ser ver",pid=111610,fd=4),("zabbix_server",pid=111609,fd=4),("zabbix_server",pid=111608,fd=4),("zabbix_server",pid=111607,fd=4),("zabbix_server",pid=111606,fd=4),("zabbix_server",pid=111605,fd=4),("zabbix_server",pid=111604,fd=4),("zabbix_server",pid=111603,fd=4),("zabbix_server",pid=111602,fd=4),("zabbix_server",pid=111601,fd=4),("zabbix_server",pid=111600,fd=4),("zabbix_server",pid=111599,fd=4),("zabbix_server",pid=111598,fd=4),("zabbix_server",pid=111597,fd=4),("zabbix_server",pid=111596,fd=4),("zabbix_server",pid=111595,fd=4),("zabbi_server",pid=111594,fd=4),("zabbix_server",pid=111593,fd=4),("zabbix_server",pid=111592,fd=4),("zabbix_server",pid=111591,fd=4),("zabbix_server",pid=111590,fd=4),("zabbix_server",pid=111589,fd=4),("zabbix_server",pid=111588,fd=4),("zabbix_server",pid=111587,fd=4),("zabbix_server",pid=111586,fd=4),("zabbix_server",pid=111585,fd=4),("zabbix_server",pid=111584,fd=4),("zabbix_server",pid=111578,fd=4),("zabbix_server",pid=111570,fd=4))[[email protected] ~]# [[email protected] ~]# [[email protected] ~]# systemctl stop zabbix-server.service [[email protected] ~]# [[email protected] ~]# ss -untlp | grep zabbix [[email protected] ~]# [[email protected] ~]#
[[email protected] ~]# ss -untlp | grep zabbix [[email protected] ~]# [[email protected] ~]# [[email protected] ~]# systemctl start zabbix-server.service [[email protected] ~]# [[email protected] ~]# ss -untlp | grep zabbix tcp LISTEN 0 128 0.0.0.0:10051 0.0.0.0:* users:(("zabbix_server",pid=111689,fd=4),("zabbix_server",pid=111688,fd=4),("zabbix_server",pid=111687,fd=4),("zabbix_server",pid=111686,fd=4),("zabbix_server",pid=111685,fd=4),("zabbix_ser ver",pid=111684,fd=4),("zabbix_server",pid=111683,fd=4),("zabbix_server",pid=111682,fd=4),("zabbix_server",pid=111681,fd=4),("zabbix_server",pid=111680,fd=4),("zabbix_server",pid=111679,fd=4),("zabbix_server",pid=111678,fd=4),("zabbix_server",pid=111677,fd=4),("zabbix_server",pid=111676,fd=4),("zabbix_server",pid=111675,fd=4),("zabbix_server",pid=111674,fd=4),("zabbix_server",pid=111673,fd=4),("zabbix_server",pid=111672,fd=4),("zabbix_server",pid=111671,fd=4),("zabbix_server",pid=111670,fd=4),("zabbix_server",pid=111669,fd=4),("zabbi_server",pid=111668,fd=4),("zabbix_server",pid=111667,fd=4),("zabbix_server",pid=111666,fd=4),("zabbix_server",pid=111665,fd=4),("zabbix_server",pid=111664,fd=4),("zabbix_server",pid=111663,fd=4),("zabbix_server",pid=111662,fd=4),("zabbix_server",pid=111661,fd=4),("zabbix_server",pid=111660,fd=4),("zabbix_server",pid=111659,fd=4),("zabbix_server",pid=111658,fd=4),("zabbix_server",pid=111657,fd=4),("zabbix_server",pid=111656,fd=4))[[email protected] ~]# [[email protected] ~]#
[[email protected] ~]# systemctl status zabbix-server.service ● zabbix-server.service - Yinzhengjie's Zabbix Server Loaded: loaded (/lib/systemd/system/zabbix-server.service; disabled; vendor preset: enabled) Active: active (running) since Fri 2020-02-14 11:13:07 UTC; 32s ago Process: 111642 ExecStart=/yinzhengjie/softwares/zabbix/sbin/zabbix_server -c $CONFFILE (code=exited, status=0/SUCCESS) Main PID: 111656 (zabbix_server) Tasks: 34 (limit: 4633) CGroup: /system.slice/zabbix-server.service ├─111656 /yinzhengjie/softwares/zabbix/sbin/zabbix_server -c /yinzhengjie/softwares/zabbix/etc/zabbix_server.conf ├─111657 /yinzhengjie/softwares/zabbix/sbin/zabbix_server: configuration syncer [synced configuration in 0.012227 sec, idle 60 sec] ├─111658 /yinzhengjie/softwares/zabbix/sbin/zabbix_server: housekeeper [startup idle for 30 minutes] ├─111659 /yinzhengjie/softwares/zabbix/sbin/zabbix_server: timer #1 [updated 0 hosts, suppressed 0 events in 0.002024 sec, idle 52 sec] ├─111660 /yinzhengjie/softwares/zabbix/sbin/zabbix_server: http poller #1 [got 0 values in 0.000906 sec, idle 5 sec] ├─111661 /yinzhengjie/softwares/zabbix/sbin/zabbix_server: discoverer #1 [processed 0 rules in 0.000720 sec, idle 60 sec] ├─111662 /yinzhengjie/softwares/zabbix/sbin/zabbix_server: history syncer #1 [processed 0 values, 0 triggers in 0.000017 sec, idle 1 sec] ├─111663 /yinzhengjie/softwares/zabbix/sbin/zabbix_server: history syncer #2 [processed 1 values, 1 triggers in 0.005204 sec, idle 1 sec] ├─111664 /yinzhengjie/softwares/zabbix/sbin/zabbix_server: history syncer #3 [processed 0 values, 0 triggers in 0.000026 sec, idle 1 sec] ├─111665 /yinzhengjie/softwares/zabbix/sbin/zabbix_server: history syncer #4 [processed 0 values, 0 triggers in 0.000083 sec, idle 1 sec] ├─111666 /yinzhengjie/softwares/zabbix/sbin/zabbix_server: escalator #1 [processed 0 escalations in 0.002050 sec, idle 3 sec] ├─111667 /yinzhengjie/softwares/zabbix/sbin/zabbix_server: proxy poller #1 [exchanged data with 0 proxies in 0.000031 sec, idle 5 sec] ├─111668 /yinzhengjie/softwares/zabbix/sbin/zabbix_server: self-monitoring [processed data in 0.000029 sec, idle 1 sec] ├─111669 /yinzhengjie/softwares/zabbix/sbin/zabbix_server: task manager [processed 0 task(s) in 0.000618 sec, idle 5 sec] ├─111670 /yinzhengjie/softwares/zabbix/sbin/zabbix_server: poller #1 [got 1 values in 0.000262 sec, idle 1 sec] ├─111671 /yinzhengjie/softwares/zabbix/sbin/zabbix_server: poller #2 [got 0 values in 0.000031 sec, idle 1 sec] ├─111672 /yinzhengjie/softwares/zabbix/sbin/zabbix_server: poller #3 [got 0 values in 0.000109 sec, idle 1 sec] ├─111673 /yinzhengjie/softwares/zabbix/sbin/zabbix_server: poller #4 [got 0 values in 0.000033 sec, idle 1 sec] ├─111674 /yinzhengjie/softwares/zabbix/sbin/zabbix_server: poller #5 [got 0 values in 0.000066 sec, idle 1 sec] ├─111675 /yinzhengjie/softwares/zabbix/sbin/zabbix_server: unreachable poller #1 [got 0 values in 0.000032 sec, idle 5 sec] ├─111676 /yinzhengjie/softwares/zabbix/sbin/zabbix_server: trapper #1 [processed data in 0.000000 sec, waiting for connection] ├─111677 /yinzhengjie/softwares/zabbix/sbin/zabbix_server: trapper #2 [processed data in 0.000376 sec, waiting for connection] ├─111678 /yinzhengjie/softwares/zabbix/sbin/zabbix_server: trapper #3 [processed data in 0.000000 sec, waiting for connection] ├─111679 /yinzhengjie/softwares/zabbix/sbin/zabbix_server: trapper #4 [processed data in 0.000000 sec, waiting for connection] ├─111680 /yinzhengjie/softwares/zabbix/sbin/zabbix_server: trapper #5 [processed data in 0.000000 sec, waiting for connection] ├─111681 /yinzhengjie/softwares/zabbix/sbin/zabbix_server: icmp pinger #1 [got 0 values in 0.000021 sec, idle 5 sec] ├─111682 /yinzhengjie/softwares/zabbix/sbin/zabbix_server: alert manager #1 [sent 0, failed 0 alerts, idle 5.012680 sec during 5.012842 sec] ├─111683 /yinzhengjie/softwares/zabbix/sbin/zabbix_server: alerter #1 started ├─111684 /yinzhengjie/softwares/zabbix/sbin/zabbix_server: alerter #2 started ├─111685 /yinzhengjie/softwares/zabbix/sbin/zabbix_server: alerter #3 started ├─111686 /yinzhengjie/softwares/zabbix/sbin/zabbix_server: preprocessing manager #1 [queued 0, processed 5 values, idle 5.002530 sec during 5.002650 sec] ├─111687 /yinzhengjie/softwares/zabbix/sbin/zabbix_server: preprocessing worker #1 started ├─111688 /yinzhengjie/softwares/zabbix/sbin/zabbix_server: preprocessing worker #2 started └─111689 /yinzhengjie/softwares/zabbix/sbin/zabbix_server: preprocessing worker #3 started Feb 14 11:13:07 zabbix203.yinzhengjie.org.cn systemd[1]: Starting Yinzhengjie's Zabbix Server... Feb 14 11:13:07 zabbix203.yinzhengjie.org.cn systemd[1]: zabbix-server.service: Can't open PID file /yinzhengjie/softwares/zabbix/pid/zabbix_server.pid (yet?) after start: No such file or directory Feb 14 11:13:07 zabbix203.yinzhengjie.org.cn systemd[1]: Started Yinzhengjie's Zabbix Server. [[email protected] ~]# [[email protected] ~]#
五.编写zabbix-agent的启动脚本(需要做第一步和第二步)
1>.编写脚本"/lib/systemd/system/zabbix-agent.service"
[[email protected] ~]# vim /lib/systemd/system/zabbix-agent.service [[email protected] ~]# [[email protected] ~]# cat /lib/systemd/system/zabbix-agent.service [Unit] Description=Yinzhengjie's Zabbix Agent After=syslog.target After=network.target [Service] Environment="CONFFILE=/yinzhengjie/softwares/zabbix/etc/zabbix_agentd.conf" EnvironmentFile=-/etc/default/zabbix-agent Type=forking Restart=on-failure PIDFile=/yinzhengjie/softwares/zabbix/pid/zabbix_agentd.pid KillMode=control-group ExecStart=/yinzhengjie/softwares/zabbix/sbin/zabbix_agentd -c $CONFFILE ExecStop=/bin/kill -SIGTERM $MAINPID RestartSec=10s User=zabbix Group=zabbix [Install] WantedBy=multi-user.target [[email protected] ~]# [[email protected] ~]# systemctl daemon-reload [[email protected] ~]# [[email protected] ~]# sync [[email protected] ~]# [[email protected] ~]#
2>.使用脚本管理zabbix agent服务
[[email protected] ~]# ss -untlp | grep zabbix tcp LISTEN 0 128 0.0.0.0:10050 0.0.0.0:* users:(("zabbix_agentd",pid=120562,fd=4),("zabbix_agentd",pid=120561,fd=4),("zabbix_agentd",pid=120560,fd=4),("zabbix_agentd",pid=120559,fd=4),("zabbix_agentd",pid=120558,fd=4),("zabbix_age ntd",pid=120549,fd=4))tcp LISTEN 0 128 0.0.0.0:10051 0.0.0.0:* users:(("zabbix_server",pid=120294,fd=4),("zabbix_server",pid=120293,fd=4),("zabbix_server",pid=120292,fd=4),("zabbix_server",pid=120291,fd=4),("zabbix_server",pid=120290,fd=4),("zabbix_ser ver",pid=120289,fd=4),("zabbix_server",pid=120288,fd=4),("zabbix_server",pid=120287,fd=4),("zabbix_server",pid=120286,fd=4),("zabbix_server",pid=120285,fd=4),("zabbix_server",pid=120284,fd=4),("zabbix_server",pid=120283,fd=4),("zabbix_server",pid=120282,fd=4),("zabbix_server",pid=120281,fd=4),("zabbix_server",pid=120280,fd=4),("zabbix_server",pid=120279,fd=4),("zabbix_server",pid=120278,fd=4),("zabbix_server",pid=120277,fd=4),("zabbix_server",pid=120276,fd=4),("zabbix_server",pid=120275,fd=4),("zabbix_server",pid=120274,fd=4),("zabbi_server",pid=120273,fd=4),("zabbix_server",pid=120272,fd=4),("zabbix_server",pid=120271,fd=4),("zabbix_server",pid=120270,fd=4),("zabbix_server",pid=120269,fd=4),("zabbix_server",pid=120268,fd=4),("zabbix_server",pid=120267,fd=4),("zabbix_server",pid=120266,fd=4),("zabbix_server",pid=120265,fd=4),("zabbix_server",pid=120264,fd=4),("zabbix_server",pid=120263,fd=4),("zabbix_server",pid=120262,fd=4),("zabbix_server",pid=120261,fd=4))[[email protected] ~]# [[email protected] ~]# systemctl restart zabbix-agent [[email protected] ~]# [[email protected] ~]# ss -untlp | grep zabbix tcp LISTEN 0 128 0.0.0.0:10050 0.0.0.0:* users:(("zabbix_agentd",pid=120591,fd=4),("zabbix_agentd",pid=120590,fd=4),("zabbix_agentd",pid=120589,fd=4),("zabbix_agentd",pid=120588,fd=4),("zabbix_agentd",pid=120587,fd=4),("zabbix_age ntd",pid=120586,fd=4))tcp LISTEN 0 128 0.0.0.0:10051 0.0.0.0:* users:(("zabbix_server",pid=120294,fd=4),("zabbix_server",pid=120293,fd=4),("zabbix_server",pid=120292,fd=4),("zabbix_server",pid=120291,fd=4),("zabbix_server",pid=120290,fd=4),("zabbix_ser ver",pid=120289,fd=4),("zabbix_server",pid=120288,fd=4),("zabbix_server",pid=120287,fd=4),("zabbix_server",pid=120286,fd=4),("zabbix_server",pid=120285,fd=4),("zabbix_server",pid=120284,fd=4),("zabbix_server",pid=120283,fd=4),("zabbix_server",pid=120282,fd=4),("zabbix_server",pid=120281,fd=4),("zabbix_server",pid=120280,fd=4),("zabbix_server",pid=120279,fd=4),("zabbix_server",pid=120278,fd=4),("zabbix_server",pid=120277,fd=4),("zabbix_server",pid=120276,fd=4),("zabbix_server",pid=120275,fd=4),("zabbix_server",pid=120274,fd=4),("zabbi_server",pid=120273,fd=4),("zabbix_server",pid=120272,fd=4),("zabbix_server",pid=120271,fd=4),("zabbix_server",pid=120270,fd=4),("zabbix_server",pid=120269,fd=4),("zabbix_server",pid=120268,fd=4),("zabbix_server",pid=120267,fd=4),("zabbix_server",pid=120266,fd=4),("zabbix_server",pid=120265,fd=4),("zabbix_server",pid=120264,fd=4),("zabbix_server",pid=120263,fd=4),("zabbix_server",pid=120262,fd=4),("zabbix_server",pid=120261,fd=4))[[email protected] ~]# [[email protected] ~]#
[[email protected] ~]# ss -ntl State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128 127.0.0.53%lo:53 0.0.0.0:* LISTEN 0 128 0.0.0.0:22 0.0.0.0:* LISTEN 0 128 0.0.0.0:10051 0.0.0.0:* LISTEN 0 128 *:80 *:* LISTEN 0 128 [::]:22 [::]:* [[email protected] ~]# [[email protected] ~]# [[email protected] ~]# systemctl start zabbix-agent [[email protected] ~]# [[email protected] ~]# ss -ntl State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128 127.0.0.53%lo:53 0.0.0.0:* LISTEN 0 128 0.0.0.0:22 0.0.0.0:* LISTEN 0 128 0.0.0.0:10050 0.0.0.0:* LISTEN 0 128 0.0.0.0:10051 0.0.0.0:* LISTEN 0 128 *:80 *:* LISTEN 0 128 [::]:22 [::]:* [[email protected] ~]# [[email protected] ~]#
[[email protected] ~]# ss -ntl State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128 127.0.0.53%lo:53 0.0.0.0:* LISTEN 0 128 0.0.0.0:22 0.0.0.0:* LISTEN 0 128 0.0.0.0:10050 0.0.0.0:* LISTEN 0 128 0.0.0.0:10051 0.0.0.0:* LISTEN 0 128 *:80 *:* LISTEN 0 128 [::]:22 [::]:* [[email protected] ~]# [[email protected] ~]# [[email protected] ~]# systemctl stop zabbix-agent [[email protected] ~]# [[email protected] ~]# ss -ntl State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128 127.0.0.53%lo:53 0.0.0.0:* LISTEN 0 128 0.0.0.0:22 0.0.0.0:* LISTEN 0 128 0.0.0.0:10051 0.0.0.0:* LISTEN 0 128 *:80 *:* LISTEN 0 128 [::]:22 [::]:* [[email protected] ~]# [[email protected] ~]#
[[email protected] ~]# ss -ntl State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128 127.0.0.53%lo:53 0.0.0.0:* LISTEN 0 128 0.0.0.0:22 0.0.0.0:* LISTEN 0 128 0.0.0.0:10050 0.0.0.0:* LISTEN 0 128 0.0.0.0:10051 0.0.0.0:* LISTEN 0 128 *:80 *:* LISTEN 0 128 [::]:22 [::]:* [[email protected] ~]# [[email protected] ~]# [[email protected] ~]# systemctl status zabbix-agent ● zabbix-agent.service - Yinzhengjie's Zabbix Agent Loaded: loaded (/lib/systemd/system/zabbix-agent.service; disabled; vendor preset: enabled) Active: active (running) since Fri 2020-02-14 15:02:32 UTC; 42s ago Process: 120575 ExecStop=/bin/kill -SIGTERM $MAINPID (code=exited, status=0/SUCCESS) Process: 120576 ExecStart=/yinzhengjie/softwares/zabbix/sbin/zabbix_agentd -c $CONFFILE (code=exited, status=0/SUCCESS) Main PID: 120586 (zabbix_agentd) Tasks: 6 (limit: 4633) CGroup: /system.slice/zabbix-agent.service ├─120586 /yinzhengjie/softwares/zabbix/sbin/zabbix_agentd -c /yinzhengjie/softwares/zabbix/etc/zabbix_agentd.conf ├─120587 /yinzhengjie/softwares/zabbix/sbin/zabbix_agentd: collector [idle 1 sec] ├─120588 /yinzhengjie/softwares/zabbix/sbin/zabbix_agentd: listener #1 [waiting for connection] ├─120589 /yinzhengjie/softwares/zabbix/sbin/zabbix_agentd: listener #2 [waiting for connection] ├─120590 /yinzhengjie/softwares/zabbix/sbin/zabbix_agentd: listener #3 [waiting for connection] └─120591 /yinzhengjie/softwares/zabbix/sbin/zabbix_agentd: active checks #1 [idle 1 sec] Feb 14 15:02:32 zabbix203.yinzhengjie.org.cn systemd[1]: Starting Yinzhengjie's Zabbix Agent... Feb 14 15:02:32 zabbix203.yinzhengjie.org.cn systemd[1]: zabbix-agent.service: Can't open PID file /yinzhengjie/softwares/zabbix/pid/zabbix_agentd.pid (yet?) after start: No such file or directory Feb 14 15:02:32 zabbix203.yinzhengjie.org.cn systemd[1]: Started Yinzhengjie's Zabbix Agent. [[email protected] ~]# [[email protected] ~]# [[email protected] ~]#