Centos7.6+MySQL+Nginx 安装Zabbix5.0,监控java spring进程和MySQL进程

安装Zabbix5.0,监控java spring进程和MySQL进程

  • 1.zabbix安装需求:
          • 需求:监控云服务器上的进程
          • 地址:https://www.zabbix.com/
    • 1.1 安装Zabbix server端
    • 1.2 安装MySQL
    • 1.3.安装Zabbix 5.0监控平台
    • 1.4 在Server端安装zabbix_get
    • 1.5 在被监控的client端Zabbix-agent安装
    • 1.6 在10.10.10.1 server端测试一下
  • 2. 监控进程
    • 2.1 java spring进程监控
    • 2.2 MySQL进程监控和java进程监控一致

1.zabbix安装需求:

需求:监控云服务器上的进程
10.10.10.1 Zabbix server端 2个java进程
10.10.10.1 Zabbix 客户端 3个java进程+MySQL
地址:https://www.zabbix.com/

1.1 安装Zabbix server端

Centos7.6+MySQL+Nginx 安装Zabbix5.0,监控java spring进程和MySQL进程_第1张图片

1.2 安装MySQL

systemctl stop firewalld #关闭防火墙服务

systemctl disable firewalld   #禁止防火墙服务启动 

setenforce = 0     #临时关闭SELinux
 
sed -i s/SELINUX=enforcing/SELINUX=disabled/g /etc/selinux/config     #修改将“SELINUX=enforcing”更改为“SELINUX=disabled”,永久关闭SELINUX

wget https://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm    #下载mysql 5.7安装包
 
rpm -ivh mysql57-community-release-el7-9.noarch.rpm  #安装源
 
yum install -y mysql-server  #安装mysql

service mysqld start && chkconfig mysqld on  #启动Mysqld服务和设置开机自动启动
 
grep -an “temporary password” /var/log/mysqld.log   #查看初始密码
 
mysql -u root -p nX6-hKRoLjyW   #使用初始密码登陆

mysql: [Warning] Using a password on the command line interface can be insecure.
...
Server version: 5.7.29
...
mysql>

mysql> alter user root@"localhost" identified by "123qqqWWW";   修改登陆密码

mysql -uroot -p #使用新密码登陆

1.3.安装Zabbix 5.0监控平台

1.3.1安装Zabbix Yum源仓库

rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm```
yum clean all

1.3.2 安装Zabbix Server 与 Zabbix agent

yum install -y zabbix-server-mysql zabbix-agent #有些云服务器比较慢,这里需要多重试几次。

1.3.3 安装Zabbix frontend

[root@localhost ~]# yum -y install centos-release-scl

[root@localhost ~]# vim /etc/yum.repos.d/zabbix.repo
...
[zabbix-frontend]
name=Zabbix Official Repository frontend - $basearch
baseurl=http://repo.zabbix.com/zabbix/5.0/rhel/7/$basearch/frontend
enabled=1        //将0修改为1
...

1.3.4 安装Zabbix前端包

[root@localhost ~]# yum -y install zabbix-web-mysql-scl zabbix-nginx-conf-scl  #这里也需要多次重试一下

1.3.5 创建和初始化数据库

[root@localhost ~]# mysql -uroot -p123qqqWWW
...
mysql> create database zabbix character set utf8 collate utf8_bin;
Query OK, 1 row affected (0.00 sec)

mysql> create user zabbix@localhost identified by '123qqqWWW';
Query OK, 0 rows affected (0.00 sec)

mysql> grant all privileges on zabbix.* to zabbix@localhost;
Query OK, 0 rows affected (0.00 sec)

mysql> exit
Bye

1.3.6 导入Zabbix数据库结构和数据

[root@localhost ~]# zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p123qqqWWW zabbix

1.3.7 配置Zabbix Server

[root@localhost ~]# vim /etc/opt/rh/rh-nginx116/nginx/conf.d/zabbix.conf
server {
#        listen          80;
#        server_name     example.com;
取消以上两行注释修改后为以下:
server {
        listen          80;
        server_name     example.com;
...

把116行和124行改一下

[root@localhost ~]# vim /etc/zabbix/zabbix_server.conf
...
DBUser=zabbix     //用户名要与数据库中创建的供zabbix访问的用户名一致
...
DBPassword=123qqq...A      //去掉注释,添加创建的zabbix用户的数据库密码
...

1.3.8 为Zabbix前端配置PHP

[zabbix]
user = apache
group = apache

listen = /var/opt/rh/rh-php72/run/php-fpm/zabbix.sock
listen.acl_users = apache,nginx  #添加一个nginx
listen.allowed_clients = 127.0.0.1

pm = dynamic
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 35

php_value[session.save_handler] = files
php_value[session.save_path]    = /var/opt/rh/rh-php72/lib/php/session/

php_value[max_execution_time] = 300
php_value[memory_limit] = 128M
php_value[post_max_size] = 16M
php_value[upload_max_filesize] = 2M
php_value[max_input_time] = 300
php_value[max_input_vars] = 10000
php_value[date.timezone] = Asia/Shanghai  #时区改为Asia/shanghai

1.3.9 开启服务

[root@localhost ~]# systemctl restart zabbix-server zabbix-agent  httpd rh-php72-php-fpm

[root@localhost ~]# systemctl enable zabbix-server zabbix-agent httpd rh-php72-php-fpm

1.3.10 初始化配置
Centos7.6+MySQL+Nginx 安装Zabbix5.0,监控java spring进程和MySQL进程_第2张图片
Centos7.6+MySQL+Nginx 安装Zabbix5.0,监控java spring进程和MySQL进程_第3张图片
Centos7.6+MySQL+Nginx 安装Zabbix5.0,监控java spring进程和MySQL进程_第4张图片
Centos7.6+MySQL+Nginx 安装Zabbix5.0,监控java spring进程和MySQL进程_第5张图片

Centos7.6+MySQL+Nginx 安装Zabbix5.0,监控java spring进程和MySQL进程_第6张图片
Centos7.6+MySQL+Nginx 安装Zabbix5.0,监控java spring进程和MySQL进程_第7张图片
Centos7.6+MySQL+Nginx 安装Zabbix5.0,监控java spring进程和MySQL进程_第8张图片
1.3.11 中文字体乱码的问题

将Win10操作系统C:\Windows\Fonts目录下的任意字体,拷贝到/usr/share/zabbix/assets/fonts/目录下,更改后缀为’.ttf’
1.在本地操作,先把本地的字体上传到云服务器

scp -r simhei.ttf root@10.10.10.1:/usr/share/zabbix/assets/fonts/

2.在云服务里面操作,然后字体就正常了

ln -s simhei.ttf graphfont.ttf

1.4 在Server端安装zabbix_get

[root@localhost ~]# rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
[root@localhost ~]# yum list |grep zabbix
[root@localhost ~]# yum -y install zabbix-get.x86_64

1.5 在被监控的client端Zabbix-agent安装

1.5.1安装Zabbix Yum源仓库

[root@localhost ~]# rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm

[root@localhost ~]# yum list all |grep zabbix

[root@localhost ~]# yum install -y zabbix-agent

1.5.2 修改配置文件并启动服务

[root@localhost ~]# vim /etc/zabbix/zabbix_agentd.conf
119 Server=127.0.0.1,10.10.10.1.   //Zabbix-server地址,多个用","隔开
160 ServerActive=10.10.10.1     //Zabbix-server地址
172 Hostname=10.10.10.2     //本客户端IP地址

[root@localhost ~]# systemctl start zabbix-agent
[root@localhost ~]# systemctl enable zabbix-agent
[root@localhost ~]# ss -antulp |grep :10050 #查看10050端口有没有打开
tcp    LISTEN     0      128       *:10050                 *:*                   users:(("zabbix_agentd",pid=6868,fd=4),("zabbix_agentd",pid=6867,fd=4),("zabbix_agentd",pid=6866,fd=4),("zabbix_agentd",pid=6865,fd=4),("zabbix_agentd",pid=6864,fd=4),("zabbix_agentd",pid=6863,fd=4))
tcp    LISTEN     0      128      :::10050                :::*                   users:(("zabbix_agentd",pid=6868,fd=5),("zabbix_agentd",pid=6867,fd=5),("zabbix_agentd",pid=6866,fd=5),("zabbix_agentd",pid=6865,fd=5),("zabbix_agentd",pid=6864,fd=5),("zabbix_agentd",pid=6863,fd=5))

1.6 在10.10.10.1 server端测试一下

[root@localhost ~]# zabbix_get -s 192.168.43.42 -p 10050 -k system.cpu.load[all,avg1]
0.000000

需要监控服务器里的基本信息的自己百度

2. 监控进程

2.1 java spring进程监控

1. 创建脚本目录,并且给脚本执行权限

[root@localhost ~]# mkdir -p /opt/scripts/
[root@localhost ~]# cd /opt/scripts/
[root@localhost scripts]# ls
mysql.sh
[root@localhost scripts]# vim java.sh 
[root@localhost scripts]# cat java.sh 
#!/bin/bash

count=$(ps -ef|grep -Ev "grep|$0"|grep -c java)

if [ $count -gt 2 ];then     #因为这台服务器有3个java spring进程,这里-gt是小于2 
    echo '0'
else
    echo '1'
fi
[root@localhost scripts]# chmod +x java.sh 
[root@localhost scripts]# bash java.sh 

2. 修改脚本存放目录的属主属组为zabbix

[root@localhost opt]# chown -R zabbix.zabbix scripts
[root@localhost opt]# ll
总用量 4
drwxr-xr-x 2 zabbix zabbix 4096 Jul  2 17:40 scripts
[root@localhost scripts]# chown -R zabbix.zabbix java.sh 
[root@localhost scripts]# ll
-rwxr-xr-x 1 zabbix zabbix 126 Jul  2 16:44 java.sh

3.修改客户端配置文件agentd.conf

[root@localhost ~]# vim /etc/zabbix/zabbix_agentd.conf
//添加下面两项
UnsafeUserParameters=1
UserParameter=key_java,/bin/bash /opt/scripts/java.sh

4.重启zabbix_agent

[root@localhost ~]# systemctl restart zabbix-agent
[root@localhost ~]# ss -antulp |grep :10050
tcp    LISTEN     0      128       *:10050                 *:*                   users:(("zabbix_agentd",pid=6868,fd=4),("zabbix_agentd",pid=6867,fd=4),("zabbix_agentd",pid=6866,fd=4),("zabbix_agentd",pid=6865,fd=4),("zabbix_agentd",pid=6864,fd=4),("zabbix_agentd",pid=6863,fd=4))
tcp    LISTEN     0      128      :::10050                :::*                   users:(("zabbix_agentd",pid=6868,fd=5),("zabbix_agentd",pid=6867,fd=5),("zabbix_agentd",pid=6866,fd=5),("zabbix_agentd",pid=6865,fd=5),("zabbix_agentd",pid=6864,fd=5),("zabbix_agentd",pid=6863,fd=5))

5.在服务端手动测试

[root@localhost ~]# zabbix_get -s 10.10.10.2-k key_java
0

6.配置网页界面,添加监控项以及触发器

Centos7.6+MySQL+Nginx 安装Zabbix5.0,监控java spring进程和MySQL进程_第9张图片
Centos7.6+MySQL+Nginx 安装Zabbix5.0,监控java spring进程和MySQL进程_第10张图片
Centos7.6+MySQL+Nginx 安装Zabbix5.0,监控java spring进程和MySQL进程_第11张图片
查看结果,显示"0"位正常,如果显示"1"时表示出故障了
Centos7.6+MySQL+Nginx 安装Zabbix5.0,监控java spring进程和MySQL进程_第12张图片
Centos7.6+MySQL+Nginx 安装Zabbix5.0,监控java spring进程和MySQL进程_第13张图片

2.2 MySQL进程监控和java进程监控一致

在这里再添加一行

[root@localhost ~]# vim /etc/zabbix/zabbix_agentd.conf
UserParameter=key_java,/bin/bash /opt/scripts/java.sh
UserParameter=key_mysql,/bin/bash /opt/scripts/mysql.sh 

你可能感兴趣的:(Centos7.6+MySQL+Nginx 安装Zabbix5.0,监控java spring进程和MySQL进程)