[root@agent scripts]# ./check_process.sh httpd
0 #输出0表示httpd服务正常
//将httpd服务停止
[root@agent scripts]# systemctl stop httpd
[root@agent scripts]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
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 [::]:22 [::]😗
[root@agent scripts]# ./check_process.sh httpd
1 #输出1表示httpd服务不正常
修改客户端的zabbix_agentd.conf配置
//开启自定义监控服务
[root@agent scripts]# vim /usr/local/etc/zabbix_agentd.conf
UnsafeUserParameters=1 #取消这322一行的注释并把0修改为1表示启用
//并在最后面新建一行插入脚本
[root@agent scripts]# vim /usr/local/etc/zabbix_agentd.conf
UserParameter=check_process[*],/scripts/check_process.sh $1
//重启zabbix服务
[root@agent scripts]# pkill zabbix
[root@agent scripts]# zabbix_agentd
[root@agent scripts]# ss -anlt
State Recv-Q Send-Q Local Address:Port Peer Address:Port
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 [::]:22 [::]😗
//服务端测试效果
[root@Server ~]# zabbix_get -s 192.168.129.135 -k check_process[‘httpd’]
1 #不正常
[root@agent scripts]# systemctl start httpd
[root@agent scripts]# ss -anlt
State Recv-Q Send-Q Local Address:Port Peer Address:Port
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 *:80 :
LISTEN 0 128 [::]:22 [::]😗
[root@Server ~]# zabbix_get -s 192.168.129.135 -k check_process[‘httpd’]
0 #正常启动
配置监控项
在客户端将httpd服务关闭
[root@agent scripts]# systemctl stop httpd
[root@agent scripts]# systemctl start httpd
添加触发器
在客户端将httpd服务关闭
[root@agent scripts]# systemctl stop httpd
因为之前设置了媒介与邮箱告警,收到了邮件
========================================================================
编写并查看脚本文件
[root@agent scripts]# vim log.py
[root@agent scripts]# cat log.py
#!/usr/bin/env python3
import sys
import re
def prePos(seekfile):
global curpos
try:
cf = open(seekfile)
except IOError:
curpos = 0
return curpos
except FileNotFoundError:
curpos = 0
return curpos
else:
try:
curpos = int(cf.readline().strip())
except ValueError:
curpos = 0
cf.close()
return curpos
cf.close()
return curpos
def lastPos(filename):
with open(filename) as lfile:
if lfile.readline():
lfile.seek(0,2)
else:
return 0
lastPos = lfile.tell()
return lastPos
def getSeekFile():
try:
seekfile = sys.argv[2]
except IndexError:
seekfile = ‘/tmp/logseek’
return seekfile
def getKey():
try:
tagKey = str(sys.argv[3])
except IndexError:
tagKey = ‘Error’
return tagKey
def getResult(filename,seekfile,tagkey):
destPos = prePos(seekfile)
curPos = lastPos(filename)
if curPos < destPos:
curpos = 0
try:
f = open(filename)
except IOError:
print(‘Could not open file: %s’ % filename)
except FileNotFoundError:
print(‘Could not open file: %s’ % filename)
else:
f.seek(destPos)
while curPos != 0 and f.tell() < curPos:
rresult = f.readline().strip()
global result
if re.search(tagkey, rresult):
result = 1
break
else:
result = 0
with open(seekfile,‘w’) as sf:
sf.write(str(curPos))
finally:
f.close()
return result
if name == “main”:
result = 0
curpos = 0
tagkey = getKey()
seekfile = getSeekFile()
result = getResult(sys.argv[1],seekfile,tagkey)
print(result)
给脚本文件添加执行权限
[root@agent scripts]# chmod +x /scripts/log.py
[root@agent scripts]# ll
总用量 8
-rwxr-xr-x 1 root root 137 10月 8 23:42 check_process.sh
-rwxr-xr-x 1 root root 1854 10月 8 23:41 log.py
安装python3
[root@agent scripts]# yum -y install python3
在客户端修改zabbix_agentd.conf配置文件
[root@agent scripts]# vim /usr/local/etc/zabbix_agentd.conf
UserParameter=check_log[*],/scripts/log.py $1 $2 $3 //最后一行添加
[root@agent scripts]# pkill zabbix_agentd
[root@agent scripts]# zabbix_agentd
[root@agent scripts]# ss -anlt
State Recv-Q Send-Q Local Address:Port Peer Address:Port
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 [::]:22 [::]😗
在客户端修改权限便于key访问
[root@agent scripts]# chmod 755 /var/log/httpd
[root@agent scripts]# ll -d /var/log/httpd/
drwxr-xr-x 2 root root 41 10月 8 23:30 /var/log/httpd/
服务端
[root@Server ~]# zabbix_get -s 192.168.129.135 -k check_log[/var/log/httpd/error_log]
0
客户端
//查看属主是否是zabbix
[root@agent scripts]# ll /tmp/logseek
-rw-rw-r-- 1 zabbix zabbix 4 10月 9 01:10 /tmp/logseek
[root@agent scripts]# echo ‘Failed’ >> /var/log/httpd/error_log
服务端
[root@Server ~]# zabbix_get -s 192.168.129.135 -k check_log[/var/log/httpd/error_log,/tmp/logseek,Failed]
1
添加监控项
添加触发器
测试验证
[root@agent scripts]# echo ‘Error’ >> /var/log/httpd/error_log
=============================================================================
mysql主从详情配置请点击下方超链接
主
[root@master ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.34 MySQL Community Server (GPL)
Copyright © 2000, 2021, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.
mysql> set password = password(‘123456’);
Query OK, 0 rows affected, 1 warning (0.01 sec)
mysql> grant replication slave on . to ‘hhr’@‘192.168.129.135’ identified by ‘hhr123!’;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
[root@master ~]# vim /etc/my.cnf
[root@master ~]# cat /etc/my.cnf
[mysqld]
basedir = /usr/local/mysql
datadir = /opt/data
socket = /tmp/mysql.sock
port = 3306
pid-file = /opt/data/mysql.pid
skip-name-resolve
log-bin=mysql_bin #启用binlog日志
server-id=10 #数据库服务器唯一标识符,主库的server-id值必须比从库的小
[root@master ~]# service mysqld restart
Shutting down MySQL… SUCCESS!
Starting MySQL. SUCCESS!
//主库查看
mysql> show master status;
±-----------------±---------±-------------±-----------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
±-----------------±---------±-------------±-----------------+
| mysql_bin.000004 | 342 | | |
±-----------------±---------±-------------±-----------------+
1 row in set (0.000 sec)
最后
我想问下大家当初选择做程序员的初衷是什么?有思考过这个问题吗?高薪?热爱?
既然入了这行就应该知道,这个行业是靠本事吃饭的,你想要拿高薪没有问题,请好好磨练自己的技术,不要抱怨。有的人通过培训可以让自己成长,有些人可以通过自律强大的自学能力成长,如果你两者都不占,还怎么拿高薪?
架构师是很多程序员的职业目标,一个好的架构师是不愁所谓的35岁高龄门槛的,到了那个时候,照样大把的企业挖他。为什么很多人想进阿里巴巴,无非不是福利待遇好以及优质的人脉资源,这对个人职业发展是有非常大帮助的。
如果你也想成为一名好的架构师,那或许这份Java核心架构笔记你需要阅读阅读,希望能够对你的职业发展有所帮助。
中高级开发必知必会:
on | Binlog_Do_DB | Binlog_Ignore_DB |
±-----------------±---------±-------------±-----------------+
| mysql_bin.000004 | 342 | | |
±-----------------±---------±-------------±-----------------+
1 row in set (0.000 sec)
最后
我想问下大家当初选择做程序员的初衷是什么?有思考过这个问题吗?高薪?热爱?
既然入了这行就应该知道,这个行业是靠本事吃饭的,你想要拿高薪没有问题,请好好磨练自己的技术,不要抱怨。有的人通过培训可以让自己成长,有些人可以通过自律强大的自学能力成长,如果你两者都不占,还怎么拿高薪?
架构师是很多程序员的职业目标,一个好的架构师是不愁所谓的35岁高龄门槛的,到了那个时候,照样大把的企业挖他。为什么很多人想进阿里巴巴,无非不是福利待遇好以及优质的人脉资源,这对个人职业发展是有非常大帮助的。
如果你也想成为一名好的架构师,那或许这份Java核心架构笔记你需要阅读阅读,希望能够对你的职业发展有所帮助。
中高级开发必知必会:
[外链图片转存中…(img-hvqLAIlN-1721834649828)]