Ubuntu操作系统编写zabbix的启动管理脚本

                              作者:尹正杰

版权声明:原创作品,谢绝转载!否则将追究法律责任。

一.修改zabbix的pid存放路径

1>.创建存放zabbix的pid目录 

[root@zabbix203.yinzhengjie.org.cn ~]# mkdir -v /yinzhengjie/softwares/zabbix/pid
mkdir: created directory '/yinzhengjie/softwares/zabbix/pid'
[root@zabbix203.yinzhengjie.org.cn ~]#

2>.修改pid的目录权限

[root@zabbix203.yinzhengjie.org.cn ~]# ll /yinzhengjie/softwares/zabbix/
total
drwxr-xr-x zabbix zabbix 2月 : ./
drwxr-xr-x root root 2月 : ../
drwxr-xr-x zabbix zabbix 2月 : bin/
drwxr-xr-x zabbix zabbix 2月 : etc/
drwxr-xr-x zabbix zabbix 2月 : lib/
drwxr-xr-x 2 root root 6 2月 14 10:37 pid/
drwxr-xr-x zabbix zabbix 2月 : sbin/
drwxr-xr-x zabbix zabbix 2月 : share/
[root@zabbix203.yinzhengjie.org.cn ~]#
[root@zabbix203.yinzhengjie.org.cn ~]# chown zabbix:zabbix /yinzhengjie/softwares/zabbix/pid/
[root@zabbix203.yinzhengjie.org.cn ~]#
[root@zabbix203.yinzhengjie.org.cn ~]# ll /yinzhengjie/softwares/zabbix/
total
drwxr-xr-x zabbix zabbix 2月 : ./
drwxr-xr-x root root 2月 : ../
drwxr-xr-x zabbix zabbix 2月 : bin/
drwxr-xr-x zabbix zabbix 2月 : etc/
drwxr-xr-x zabbix zabbix 2月 : lib/
drwxr-xr-x 2 zabbix zabbix 6 2月 14 10:37 pid/
drwxr-xr-x zabbix zabbix 2月 : sbin/
drwxr-xr-x zabbix zabbix 2月 : share/
[root@zabbix203.yinzhengjie.org.cn ~]#

3>.修改zabbix server和zabbix agent的配置文件

[root@zabbix203.yinzhengjie.org.cn ~]# grep PidFile= /yinzhengjie/softwares/zabbix/etc/zabbix_server.conf
# PidFile=/tmp/zabbix_server.pid
[root@zabbix203.yinzhengjie.org.cn ~]#
[root@zabbix203.yinzhengjie.org.cn ~]# sed -r -i 's@# (PidFile=)/tmp@\1/yinzhengjie/softwares/zabbix/pid@' /yinzhengjie/softwares/zabbix/etc/zabbix_server.conf
[root@zabbix203.yinzhengjie.org.cn ~]#
[root@zabbix203.yinzhengjie.org.cn ~]# grep PidFile= /yinzhengjie/softwares/zabbix/etc/zabbix_server.conf
PidFile=/yinzhengjie/softwares/zabbix/pid/zabbix_server.pid
[root@zabbix203.yinzhengjie.org.cn ~]#

[root@zabbix203.yinzhengjie.org.cn ~]# sed -r -i 's@# (PidFile=)/tmp@\1/yinzhengjie/softwares/zabbix/pid@' /yinzhengjie/softwares/zabbix/etc/zabbix_server.conf

[root@zabbix203.yinzhengjie.org.cn ~]# grep PidFile= /yinzhengjie/softwares/zabbix/etc/zabbix_agentd.conf
# PidFile=/tmp/zabbix_agentd.pid
[root@zabbix203.yinzhengjie.org.cn ~]#
[root@zabbix203.yinzhengjie.org.cn ~]# sed -r -i 's@# (PidFile=)/tmp@\1/yinzhengjie/softwares/zabbix/pid@' /yinzhengjie/softwares/zabbix/etc/zabbix_agentd.conf
[root@zabbix203.yinzhengjie.org.cn ~]#
[root@zabbix203.yinzhengjie.org.cn ~]# grep PidFile= /yinzhengjie/softwares/zabbix/etc/zabbix_agentd.conf
PidFile=/yinzhengjie/softwares/zabbix/pid/zabbix_agentd.pid
[root@zabbix203.yinzhengjie.org.cn ~]#
[root@zabbix203.yinzhengjie.org.cn ~]#

[root@zabbix203.yinzhengjie.org.cn ~]# sed -r -i 's@# (PidFile=)/tmp@\1/yinzhengjie/softwares/zabbix/pid@' /yinzhengjie/softwares/zabbix/etc/zabbix_agentd.conf

二.修改zabbix server的log存放路径

1>.创建存放zabbix的log目录 

[root@zabbix203.yinzhengjie.org.cn ~]# ll /yinzhengjie/softwares/zabbix/
total
drwxr-xr-x zabbix zabbix Feb : ./
drwxr-xr-x root root Feb : ../
drwxr-xr-x zabbix zabbix Feb : bin/
drwxr-xr-x zabbix zabbix Feb : etc/
drwxr-xr-x zabbix zabbix Feb : lib/
drwxr-xr-x zabbix zabbix Feb : pid/
drwxr-xr-x zabbix zabbix Feb : sbin/
drwxr-xr-x zabbix zabbix Feb : share/
[root@zabbix203.yinzhengjie.org.cn ~]#
[root@zabbix203.yinzhengjie.org.cn ~]# mkdir -v /yinzhengjie/softwares/zabbix/logs
mkdir: created directory '/yinzhengjie/softwares/zabbix/logs'
[root@zabbix203.yinzhengjie.org.cn ~]#
[root@zabbix203.yinzhengjie.org.cn ~]# ll /yinzhengjie/softwares/zabbix/
total
drwxr-xr-x zabbix zabbix Feb : ./
drwxr-xr-x root root Feb : ../
drwxr-xr-x zabbix zabbix Feb : bin/
drwxr-xr-x zabbix zabbix Feb : etc/
drwxr-xr-x zabbix zabbix Feb : lib/
drwxr-xr-x root root Feb : logs/
drwxr-xr-x zabbix zabbix Feb : pid/
drwxr-xr-x zabbix zabbix Feb : sbin/
drwxr-xr-x zabbix zabbix Feb : share/
[root@zabbix203.yinzhengjie.org.cn ~]#
[root@zabbix203.yinzhengjie.org.cn ~]#

[root@zabbix203.yinzhengjie.org.cn ~]# mkdir -v /yinzhengjie/softwares/zabbix/logs

2>.修改log的目录权限

[root@zabbix203.yinzhengjie.org.cn ~]# ll /yinzhengjie/softwares/zabbix/
total
drwxr-xr-x zabbix zabbix Feb : ./
drwxr-xr-x root root Feb : ../
drwxr-xr-x zabbix zabbix Feb : bin/
drwxr-xr-x zabbix zabbix Feb : etc/
drwxr-xr-x zabbix zabbix Feb : lib/
drwxr-xr-x 2 root root 6 Feb 14 12:20 logs/
drwxr-xr-x zabbix zabbix Feb : pid/
drwxr-xr-x zabbix zabbix Feb : sbin/
drwxr-xr-x zabbix zabbix Feb : share/
[root@zabbix203.yinzhengjie.org.cn ~]#
[root@zabbix203.yinzhengjie.org.cn ~]# chown zabbix:zabbix /yinzhengjie/softwares/zabbix/logs
[root@zabbix203.yinzhengjie.org.cn ~]#
[root@zabbix203.yinzhengjie.org.cn ~]# ll /yinzhengjie/softwares/zabbix/
total
drwxr-xr-x zabbix zabbix Feb : ./
drwxr-xr-x root root Feb : ../
drwxr-xr-x zabbix zabbix Feb : bin/
drwxr-xr-x zabbix zabbix Feb : etc/
drwxr-xr-x zabbix zabbix Feb : lib/
drwxr-xr-x 2 zabbix zabbix 6 Feb 14 12:20 logs/
drwxr-xr-x zabbix zabbix Feb : pid/
drwxr-xr-x zabbix zabbix Feb : sbin/
drwxr-xr-x zabbix zabbix Feb : share/
[root@zabbix203.yinzhengjie.org.cn ~]#
[root@zabbix203.yinzhengjie.org.cn ~]#

3>.修改zabbix server的配置文件

[root@zabbix203.yinzhengjie.org.cn ~]# grep ^LogFile= /yinzhengjie/softwares/zabbix/etc/zabbix_server.conf
LogFile=/tmp/zabbix_server.log
[root@zabbix203.yinzhengjie.org.cn ~]#
[root@zabbix203.yinzhengjie.org.cn ~]# sed -r -i 's#(LogFile=)/tmp#\1/yinzhengjie/softwares/zabbix/logs#' /yinzhengjie/softwares/zabbix/etc/zabbix_server.conf
[root@zabbix203.yinzhengjie.org.cn ~]#
[root@zabbix203.yinzhengjie.org.cn ~]# grep ^LogFile= /yinzhengjie/softwares/zabbix/etc/zabbix_server.conf
LogFile=/yinzhengjie/softwares/zabbix/logs/zabbix_server.log
[root@zabbix203.yinzhengjie.org.cn ~]#
[root@zabbix203.yinzhengjie.org.cn ~]#

三.查看CentOS 6.x操作系统使用的脚本(不推荐使用)

[root@mysql202.yinzhengjie.org.cn ~]# ll /usr/local/src/zabbix-4.0./misc/init.d/
total
drwxr-xr-x Jan : ./
drwxr-xr-x Feb : ../
drwxr-xr-x Jan : aix/
drwxr-xr-x Jan : debian/
drwxr-xr-x Jan : fedora/
drwxr-xr-x Jan : freebsd/
drwxr-xr-x Jan : gentoo/
-rw-r--r-- Jan : README
drwxr-xr-x Jan : suse/
drwxr-xr-x Jan : tru64/
drwxr-xr-x Jan : ubuntu/
[root@mysql202.yinzhengjie.org.cn ~]#

[root@mysql202.yinzhengjie.org.cn ~]# ll /usr/local/src/zabbix-4.0.17/misc/init.d/

四.编写zabbix-server的启动脚本(需要做第一步和第二步)

1>.编写脚本"/lib/systemd/system/zabbix-server.service"

[root@zabbix203.yinzhengjie.org.cn ~]# vim /lib/systemd/system/zabbix-server.service
[root@zabbix203.yinzhengjie.org.cn ~]#
[root@zabbix203.yinzhengjie.org.cn ~]# 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
[root@zabbix203.yinzhengjie.org.cn ~]#
[root@zabbix203.yinzhengjie.org.cn ~]# systemctl daemon-reload
[root@zabbix203.yinzhengjie.org.cn ~]#
[root@zabbix203.yinzhengjie.org.cn ~]# sync 
[root@zabbix203.yinzhengjie.org.cn ~]#

2>.使用脚本管理zabbix server服务

[root@zabbix203.yinzhengjie.org.cn ~]# ss -untlp | grep zabbix
tcp LISTEN 0.0.0.0: 0.0.0.0:* users:(("zabbix_server",pid=,fd=),("zabbix_server",pid=,fd=),("zabbix_server",pid=,fd=),("zabbix_server",pid=,fd=),("zabbix_server",pid=,fd=),("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))[root@zabbix203.yinzhengjie.org.cn ~]#
[root@zabbix203.yinzhengjie.org.cn ~]# systemctl restart zabbix-server.service
[root@zabbix203.yinzhengjie.org.cn ~]#
[root@zabbix203.yinzhengjie.org.cn ~]# ss -untlp | grep zabbix
tcp LISTEN 0.0.0.0: 0.0.0.0:* users:(("zabbix_server",pid=,fd=),("zabbix_server",pid=,fd=),("zabbix_server",pid=,fd=),("zabbix_server",pid=,fd=),("zabbix_server",pid=,fd=),("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))[root@zabbix203.yinzhengjie.org.cn ~]#

[root@zabbix203.yinzhengjie.org.cn ~]# systemctl restart zabbix-server.service

[root@zabbix203.yinzhengjie.org.cn ~]# ss -untlp | grep zabbix
tcp LISTEN 0.0.0.0: 0.0.0.0:* users:(("zabbix_server",pid=,fd=),("zabbix_server",pid=,fd=),("zabbix_server",pid=,fd=),("zabbix_server",pid=,fd=),("zabbix_server",pid=,fd=),("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))[root@zabbix203.yinzhengjie.org.cn ~]#
[root@zabbix203.yinzhengjie.org.cn ~]#
[root@zabbix203.yinzhengjie.org.cn ~]# systemctl stop zabbix-server.service
[root@zabbix203.yinzhengjie.org.cn ~]#
[root@zabbix203.yinzhengjie.org.cn ~]# ss -untlp | grep zabbix
[root@zabbix203.yinzhengjie.org.cn ~]#
[root@zabbix203.yinzhengjie.org.cn ~]#

[root@zabbix203.yinzhengjie.org.cn ~]# systemctl stop zabbix-server.service

[root@zabbix203.yinzhengjie.org.cn ~]# ss -untlp | grep zabbix
[root@zabbix203.yinzhengjie.org.cn ~]#
[root@zabbix203.yinzhengjie.org.cn ~]#
[root@zabbix203.yinzhengjie.org.cn ~]# systemctl start zabbix-server.service
[root@zabbix203.yinzhengjie.org.cn ~]#
[root@zabbix203.yinzhengjie.org.cn ~]# ss -untlp | grep zabbix
tcp LISTEN 0.0.0.0: 0.0.0.0:* users:(("zabbix_server",pid=,fd=),("zabbix_server",pid=,fd=),("zabbix_server",pid=,fd=),("zabbix_server",pid=,fd=),("zabbix_server",pid=,fd=),("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))[root@zabbix203.yinzhengjie.org.cn ~]#
[root@zabbix203.yinzhengjie.org.cn ~]#

[root@zabbix203.yinzhengjie.org.cn ~]# systemctl start zabbix-server.service

[root@zabbix203.yinzhengjie.org.cn ~]# 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 -- :: UTC; 32s ago
Process: ExecStart=/yinzhengjie/softwares/zabbix/sbin/zabbix_server -c $CONFFILE (code=exited, status=/SUCCESS)
Main PID: (zabbix_server)
Tasks: (limit: )
CGroup: /system.slice/zabbix-server.service
├─ /yinzhengjie/softwares/zabbix/sbin/zabbix_server -c /yinzhengjie/softwares/zabbix/etc/zabbix_server.conf
├─ /yinzhengjie/softwares/zabbix/sbin/zabbix_server: configuration syncer [synced configuration in 0.012227 sec, idle sec]
├─ /yinzhengjie/softwares/zabbix/sbin/zabbix_server: housekeeper [startup idle for minutes]
├─ /yinzhengjie/softwares/zabbix/sbin/zabbix_server: timer # [updated hosts, suppressed events in 0.002024 sec, idle sec]
├─ /yinzhengjie/softwares/zabbix/sbin/zabbix_server: http poller # [got values in 0.000906 sec, idle sec]
├─ /yinzhengjie/softwares/zabbix/sbin/zabbix_server: discoverer # [processed rules in 0.000720 sec, idle sec]
├─ /yinzhengjie/softwares/zabbix/sbin/zabbix_server: history syncer # [processed values, triggers in 0.000017 sec, idle sec]
├─ /yinzhengjie/softwares/zabbix/sbin/zabbix_server: history syncer # [processed values, triggers in 0.005204 sec, idle sec]
├─ /yinzhengjie/softwares/zabbix/sbin/zabbix_server: history syncer # [processed values, triggers in 0.000026 sec, idle sec]
├─ /yinzhengjie/softwares/zabbix/sbin/zabbix_server: history syncer # [processed values, triggers in 0.000083 sec, idle sec]
├─ /yinzhengjie/softwares/zabbix/sbin/zabbix_server: escalator # [processed escalations in 0.002050 sec, idle sec]
├─ /yinzhengjie/softwares/zabbix/sbin/zabbix_server: proxy poller # [exchanged data with proxies in 0.000031 sec, idle sec]
├─ /yinzhengjie/softwares/zabbix/sbin/zabbix_server: self-monitoring [processed data in 0.000029 sec, idle sec]
├─ /yinzhengjie/softwares/zabbix/sbin/zabbix_server: task manager [processed task(s) in 0.000618 sec, idle sec]
├─ /yinzhengjie/softwares/zabbix/sbin/zabbix_server: poller # [got values in 0.000262 sec, idle sec]
├─ /yinzhengjie/softwares/zabbix/sbin/zabbix_server: poller # [got values in 0.000031 sec, idle sec]
├─ /yinzhengjie/softwares/zabbix/sbin/zabbix_server: poller # [got values in 0.000109 sec, idle sec]
├─ /yinzhengjie/softwares/zabbix/sbin/zabbix_server: poller # [got values in 0.000033 sec, idle sec]
├─ /yinzhengjie/softwares/zabbix/sbin/zabbix_server: poller # [got values in 0.000066 sec, idle sec]
├─ /yinzhengjie/softwares/zabbix/sbin/zabbix_server: unreachable poller # [got values in 0.000032 sec, idle sec]
├─ /yinzhengjie/softwares/zabbix/sbin/zabbix_server: trapper # [processed data in 0.000000 sec, waiting for connection]
├─ /yinzhengjie/softwares/zabbix/sbin/zabbix_server: trapper # [processed data in 0.000376 sec, waiting for connection]
├─ /yinzhengjie/softwares/zabbix/sbin/zabbix_server: trapper # [processed data in 0.000000 sec, waiting for connection]
├─ /yinzhengjie/softwares/zabbix/sbin/zabbix_server: trapper # [processed data in 0.000000 sec, waiting for connection]
├─ /yinzhengjie/softwares/zabbix/sbin/zabbix_server: trapper # [processed data in 0.000000 sec, waiting for connection]
├─ /yinzhengjie/softwares/zabbix/sbin/zabbix_server: icmp pinger # [got values in 0.000021 sec, idle sec]
├─ /yinzhengjie/softwares/zabbix/sbin/zabbix_server: alert manager # [sent , failed alerts, idle 5.012680 sec during 5.012842 sec]
├─ /yinzhengjie/softwares/zabbix/sbin/zabbix_server: alerter # started
├─ /yinzhengjie/softwares/zabbix/sbin/zabbix_server: alerter # started
├─ /yinzhengjie/softwares/zabbix/sbin/zabbix_server: alerter # started
├─ /yinzhengjie/softwares/zabbix/sbin/zabbix_server: preprocessing manager # [queued , processed values, idle 5.002530 sec during 5.002650 sec]
├─ /yinzhengjie/softwares/zabbix/sbin/zabbix_server: preprocessing worker # started
├─ /yinzhengjie/softwares/zabbix/sbin/zabbix_server: preprocessing worker # started
└─ /yinzhengjie/softwares/zabbix/sbin/zabbix_server: preprocessing worker # started Feb :: zabbix203.yinzhengjie.org.cn systemd[]: Starting Yinzhengjie's Zabbix Server...
Feb :: zabbix203.yinzhengjie.org.cn systemd[]: zabbix-server.service: Can't open PID file /yinzhengjie/softwares/zabbix/pid/zabbix_server.pid (yet?) after start: No such file or directory
Feb :: zabbix203.yinzhengjie.org.cn systemd[]: Started Yinzhengjie's Zabbix Server.
[root@zabbix203.yinzhengjie.org.cn ~]#
[root@zabbix203.yinzhengjie.org.cn ~]#

[root@zabbix203.yinzhengjie.org.cn ~]# systemctl status zabbix-server.service

五.编写zabbix-agent的启动脚本(需要做第一步和第二步)

1>.编写脚本"/lib/systemd/system/zabbix-agent.service"

[root@zabbix203.yinzhengjie.org.cn ~]# vim /lib/systemd/system/zabbix-agent.service
[root@zabbix203.yinzhengjie.org.cn ~]#
[root@zabbix203.yinzhengjie.org.cn ~]# 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
[root@zabbix203.yinzhengjie.org.cn ~]#
[root@zabbix203.yinzhengjie.org.cn ~]# systemctl daemon-reload
[root@zabbix203.yinzhengjie.org.cn ~]#
[root@zabbix203.yinzhengjie.org.cn ~]# sync
[root@zabbix203.yinzhengjie.org.cn ~]#
[root@zabbix203.yinzhengjie.org.cn ~]#

2>.使用脚本管理zabbix agent服务

[root@zabbix203.yinzhengjie.org.cn ~]# ss -untlp | grep zabbix
tcp LISTEN 0.0.0.0: 0.0.0.0:* users:(("zabbix_agentd",pid=,fd=),("zabbix_agentd",pid=,fd=),("zabbix_agentd",pid=,fd=),("zabbix_agentd",pid=,fd=),("zabbix_agentd",pid=,fd=),("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))[root@zabbix203.yinzhengjie.org.cn ~]#
[root@zabbix203.yinzhengjie.org.cn ~]# systemctl restart zabbix-agent
[root@zabbix203.yinzhengjie.org.cn ~]#
[root@zabbix203.yinzhengjie.org.cn ~]# ss -untlp | grep zabbix
tcp LISTEN 0.0.0.0: 0.0.0.0:* users:(("zabbix_agentd",pid=,fd=),("zabbix_agentd",pid=,fd=),("zabbix_agentd",pid=,fd=),("zabbix_agentd",pid=,fd=),("zabbix_agentd",pid=,fd=),("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))[root@zabbix203.yinzhengjie.org.cn ~]#
[root@zabbix203.yinzhengjie.org.cn ~]#

[root@zabbix203.yinzhengjie.org.cn ~]# systemctl restart zabbix-agent

[root@zabbix203.yinzhengjie.org.cn ~]# ss -ntl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 127.0.0.53%lo: 0.0.0.0:*
LISTEN 0.0.0.0: 0.0.0.0:*
LISTEN 0.0.0.0: 0.0.0.0:*
LISTEN *: *:*
LISTEN [::]: [::]:*
[root@zabbix203.yinzhengjie.org.cn ~]#
[root@zabbix203.yinzhengjie.org.cn ~]#
[root@zabbix203.yinzhengjie.org.cn ~]# systemctl start zabbix-agent
[root@zabbix203.yinzhengjie.org.cn ~]#
[root@zabbix203.yinzhengjie.org.cn ~]# ss -ntl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 127.0.0.53%lo: 0.0.0.0:*
LISTEN 0.0.0.0: 0.0.0.0:*
LISTEN 0.0.0.0: 0.0.0.0:*
LISTEN 0.0.0.0: 0.0.0.0:*
LISTEN *: *:*
LISTEN [::]: [::]:*
[root@zabbix203.yinzhengjie.org.cn ~]#
[root@zabbix203.yinzhengjie.org.cn ~]#

[root@zabbix203.yinzhengjie.org.cn ~]# systemctl start zabbix-agent

[root@zabbix203.yinzhengjie.org.cn ~]# ss -ntl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 127.0.0.53%lo: 0.0.0.0:*
LISTEN 0.0.0.0: 0.0.0.0:*
LISTEN 0.0.0.0: 0.0.0.0:*
LISTEN 0.0.0.0: 0.0.0.0:*
LISTEN *: *:*
LISTEN [::]: [::]:*
[root@zabbix203.yinzhengjie.org.cn ~]#
[root@zabbix203.yinzhengjie.org.cn ~]#
[root@zabbix203.yinzhengjie.org.cn ~]# systemctl stop zabbix-agent
[root@zabbix203.yinzhengjie.org.cn ~]#
[root@zabbix203.yinzhengjie.org.cn ~]# ss -ntl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 127.0.0.53%lo: 0.0.0.0:*
LISTEN 0.0.0.0: 0.0.0.0:*
LISTEN 0.0.0.0: 0.0.0.0:*
LISTEN *: *:*
LISTEN [::]: [::]:*
[root@zabbix203.yinzhengjie.org.cn ~]#
[root@zabbix203.yinzhengjie.org.cn ~]#

[root@zabbix203.yinzhengjie.org.cn ~]# systemctl stop zabbix-agent

[root@zabbix203.yinzhengjie.org.cn ~]# ss -ntl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 127.0.0.53%lo: 0.0.0.0:*
LISTEN 0.0.0.0: 0.0.0.0:*
LISTEN 0.0.0.0: 0.0.0.0:*
LISTEN 0.0.0.0: 0.0.0.0:*
LISTEN *: *:*
LISTEN [::]: [::]:*
[root@zabbix203.yinzhengjie.org.cn ~]#
[root@zabbix203.yinzhengjie.org.cn ~]#
[root@zabbix203.yinzhengjie.org.cn ~]# 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 -- :: UTC; 42s ago
Process: ExecStop=/bin/kill -SIGTERM $MAINPID (code=exited, status=/SUCCESS)
Process: ExecStart=/yinzhengjie/softwares/zabbix/sbin/zabbix_agentd -c $CONFFILE (code=exited, status=/SUCCESS)
Main PID: (zabbix_agentd)
Tasks: (limit: )
CGroup: /system.slice/zabbix-agent.service
├─ /yinzhengjie/softwares/zabbix/sbin/zabbix_agentd -c /yinzhengjie/softwares/zabbix/etc/zabbix_agentd.conf
├─ /yinzhengjie/softwares/zabbix/sbin/zabbix_agentd: collector [idle sec]
├─ /yinzhengjie/softwares/zabbix/sbin/zabbix_agentd: listener # [waiting for connection]
├─ /yinzhengjie/softwares/zabbix/sbin/zabbix_agentd: listener # [waiting for connection]
├─ /yinzhengjie/softwares/zabbix/sbin/zabbix_agentd: listener # [waiting for connection]
└─ /yinzhengjie/softwares/zabbix/sbin/zabbix_agentd: active checks # [idle sec] Feb :: zabbix203.yinzhengjie.org.cn systemd[]: Starting Yinzhengjie's Zabbix Agent...
Feb :: zabbix203.yinzhengjie.org.cn systemd[]: zabbix-agent.service: Can't open PID file /yinzhengjie/softwares/zabbix/pid/zabbix_agentd.pid (yet?) after start: No such file or directory
Feb :: zabbix203.yinzhengjie.org.cn systemd[]: Started Yinzhengjie's Zabbix Agent.
[root@zabbix203.yinzhengjie.org.cn ~]#
[root@zabbix203.yinzhengjie.org.cn ~]#
[root@zabbix203.yinzhengjie.org.cn ~]#

[root@zabbix203.yinzhengjie.org.cn ~]# systemctl status zabbix-agent

Ubuntu操作系统编写zabbix的启动管理脚本的更多相关文章

  1. Ubuntu操作系统部署zabbix agent服务

    Ubuntu操作系统部署zabbix agent服务 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.下载zabbix软件包 博主推荐阅读: https://www.cnblog ...

  2. 编写使用systemctl启动服务脚本

    CentOS 7的服务systemctl脚本存放在:/usr/lib/systemd/,有系统(system)和用户(user)之分,像需要开机不登陆就能运行的程序,还是存在系统服务里吧,即:/usr ...

  3. zabbix发送报警的脚本

    zabbix报警媒介:自定义脚本Custom alertscripts 邮件报警准备工作:安装sendEmail zabbix-server 的 配置文件 /etc/zabbix/zabbix_ser ...

  4. Ubuntu 16.04设置rc.local开机启动命令/脚本的方法(通过update-rc.d管理Ubuntu开机启动程序/服务)

    注意:rc.local脚本里面启动的用户默认为root权限. 一.rc.local脚本 rc.local脚本是一个Ubuntu开机后会自动执行的脚本,我们可以在该脚本内添加命令行指令.该脚本位于/et ...

  5. systemd 编写服务管理脚本

    我们运行 linux 服务器的主要目的是通过运行程序提供服务,比如 mysql.web server等.因此管理 linux 服务器主要工作就是配置并管理上面运行的各种服务程序.在 linux 系统中 ...

  6. systemd 编写服务管理脚本---学习

    转载:https://www.cnblogs.com/sparkdev/p/8521812.html 我们运行 linux 服务器的主要目的是通过运行程序提供服务,比如 mysql.web serve ...

  7. [转贴]systemd 编写服务管理脚本

    [转贴]sparkdev大神的博客, 关于 systemd的配置文件的 介绍, 自己之前二进制安装 k8s 时 超过一个 service文件 但是当时不明不白的. 现在再学习一下大神的文章 的确牛B ...

  8. 关于Ubuntu运行级别、开机启动脚本的说明

    关于Ubuntu运行级别.开机启动脚本的说明 目录简介 1.1介绍Ubuntu下面的自启动脚本目录 1.2 Linux操作系统运行级别的概念 1.3关于操作系统自启脚本的启动顺序 1.4    Lin ...

  9. Ubuntu 16.04设置rc.local开机启动命令/脚本的方法

    Ubuntu 16.04设置rc.local开机启动命令/脚本的方法       Ubuntu 16.04设置rc.local开机启动命令/脚本的方法(通过update-rc.d管理Ubuntu开机启 ...

随机推荐

  1. centos610最小安装之后 后续设置

    1.网络配置 centos选择最小桌面(如果不用到类似Oracle需要用到桌面的软件,则操作系统安装最小化安装)安装之后 查看网络配置如下: 截图显示网络并未启用. 2.开启网络设置 cd /etc/ ...

  2. [阿里移动推荐算法]比赛_快速入门_4_19_update_仅供参考,思维不要受局限

    [这里只讲快速入门——即破题,正负样本不平衡.特征数量等问题就自己多看论文或者其他资料吧~~如果还有数据挖掘相关基础知识不了解的,建议看看<数据挖掘导论>] [以下是理解错误案例]:错误的 ...

  3. ios中时间倒计时

    博客地址 https://github.com/sundayios/SQCountTimeDown.git

  4. 看Web视频整理标签笔记

    原来观看web视频,初学html的时候发现记忆不太深刻,所以自己整理了一些笔记,加深记忆且方便忘记时查看.html的规范(遵循)1.一个html文件开始标签和结束标签<html></ ...

  5. 将一行很长的js代码格式化输出方便查看

    之前的一行js代码,有2万多字符,打开这个网址,粘贴到左边空白框,点下面格式化: 参考下面文章: 数千行的js代码变成了一行,如何复原,该换行的换行,该对齐的对齐_开发工具_小邯韩的博客-CSDN博客 ...

  6. tensorflow中的图(02-1)

    由于tensorflow版本迭代较快且不同版本的接口会有差距,我这里使用的是1.14.0的版本 安装指定版本的方法:pip install tensorflow==1.14.0      如果你之前安 ...

  7. webservice之实现天气预报

    前通过传智的视频自学了webservice的基本使用,也了解到webservice就是一种跨编程语言和跨操作系统平台的远程调用技术. 对于这些理论知识在这里也不再做过多的解释,本次主要就是记录与分享使 ...

  8. Servlet简单的登陆窗口

    web.xml配置: jsp代码: 注意:action书写的是为这次登陆做处理类的别名,method就是请求的方式 Get请求方式没有请求实体 //如果只是看效果就光写一下service方法就行了 p ...

  9. HTML5画的简单时钟

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  10. activiti 全局流程监听ActivitiEventListener,实现监听不同类型事件,不需要在acitivit中配置任务监听,非常方便

    如果我们像给任务配置监听,按照常规的做法是这样的 一个个配置,比较麻烦. 现在利用ActivitiEventListener,监听全局事件,并且可以判断不同的事件类型,进而执行不同的业务逻辑. 1.定 ...