任务一 Zabbix5.0监控
1. yum安装配置zabbix
关闭防火墙
[root@zabbix ~]# systemctl stop firewalld [root@zabbix ~]# systemctl disable firewalld [root@zabbix ~]# setenforce 0
https://www.zabbix.com/cn/download?zabbix=5.4&os_distribution=centos&os_version=7&db=&ws=
[root@zabbix ~]# rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm Retrieving https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm warning: /var/tmp/rpm-tmp.S0nk6I: Header V4 RSA/SHA512 Signature, key ID a14fe591: NOKEY Preparing... ################################# [100%] Updating / installing... 1:zabbix-release-5.0-1.el7 ################################# [100%] [root@zabbix ~]# yum clean all Loaded plugins: fastestmirror Cleaning repos: base extras updates zabbix zabbix-non-supported Cleaning up everything Cleaning up list of fastest mirrors
[root@zabbix ~]# yum -y install zabbix-server-mysql zabbix-agent
[root@zabbix ~]# yum -y install centos-release-scl
[root@zabbix ~]# vi /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 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
安装数据库
[root@zabbix ~]# wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm [root@zabbix ~]# yum -y install mysql57-community-release-el7-10.noarch.rpm [root@zabbix ~]# yum -y install mysql-community-server
[root@zabbix ~]# yum install zabbix-web-mysql-scl zabbix-nginx-conf-scl
启动mysqld服务
[root@zabbix ~]# systemctl start mysqld
[root@zabbix ~]# systemctl enable mysqld
查看密码
[root@zabbix ~]# grep ‘temporary password‘ /var/log/mysqld.log 2021-06-23T15:12:57.498908Z 1 [Note] A temporary password is generated for root@localhost: m;lr2oMa7tbn
[root@zabbix ~]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 19 Server version: 5.7.34 Copyright (c) 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>
修改密码
mysql> alter user user() identified by ‘Jinyang@.123‘; Query OK, 0 rows affected (0.02 sec) //密码要设置复杂的,否则失败
mysql> create database zabbix character set utf8 collate utf8_bin; Query OK, 1 row affected (0.30 sec) mysql> create user zabbix@localhost identified by ‘Jinyang@.123‘; Query OK, 0 rows affected (0.01 sec) mysql> grant all privileges on zabbix.* to zabbix@localhost; Query OK, 0 rows affected (0.02 sec) mysql> quit Bye
导入初始架构和数据,系统将提示您输入新创建的密码
[root@zabbix ~]# zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p zabbix Enter password:Jinyang@.123
编辑/etc/zabbix/zabbix_server.conf
[root@zabbix ~]# vi /etc/zabbix/zabbix_server.conf DBPassword=Jinyang@.123
为zabbix前端配置php
编辑配置文件/etc/opt/rh/rh-nginx116/nginx/conf.d/zabbix.conf
[root@zabbix ~]# vi /etc/opt/rh/rh-nginx116/nginx/conf.d/zabbix.conf # listen 80; # server_name example.com;
编辑配置文件/etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf
[root@zabbix ~]# vi /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf listen.acl_users = apache,nginx php_value[date.timezone] = Asia/Shanghai
启动zabbix server和agent进程
[root@zabbix ~]# systemctl restart zabbix-server zabbix-agent rh-nginx116-nginx rh-php72-php-fpm [root@zabbix ~]# systemctl enable zabbix-server zabbix-agent rh-nginx116-nginx rh-php72-php-fpm Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-server.service to /usr/lib/systemd/system/zabbix-server.service. Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-agent.service to /usr/lib/systemd/system/zabbix-agent.service. Created symlink from /etc/systemd/system/multi-user.target.wants/rh-nginx116-nginx.service to /usr/lib/systemd/system/rh-nginx116-nginx.service. Created symlink from /etc/systemd/system/multi-user.target.wants/rh-php72-php-fpm.service to /usr/lib/systemd/system/rh-php72-php-fpm.service.
为Zabbix前端配置PHP编辑配置文件
将第2第3行取消#号注释。listen修改为8080
这里注意一定不要使用默认的80端口
因为nginx默认使用/etc/opt/rh/rh-nginx116/nginx/nginx.conf
然后才会使用/etc/opt/rh/rh-nginx116/nginx/conf.d/zabbix.conf
如果使用默认80端口访问是显示nginx默认欢迎页,无法跳转至zabbix页面 这里使用8080端口 也可以配置自定义端口号
[root@zabbix ~]# vi /etc/opt/rh/rh-nginx116/nginx/conf.d/zabbix.conf server { listen 8080; server_name example.com;
重启
[root@zabbix ~]# systemctl restart zabbix-server zabbix-agent rh-nginx116-nginx rh-php72-php-fpm
输入用户名:Admin
密码:zabbix
选择中文