请自行安装安装CentOS7.8-2003版本
如果不会,请自行学习
![e3ca08094da5aa1342920d34238c574e.png](https://img-blog.csdnimg.cn/img_convert/e3ca08094da5aa1342920d34238c574e.png)
1.基础环境配置:
[root@localhost ~]# systemctl disable firewalld #禁止防火墙服务启动
[root@localhost ~]# systemctl stop firewalld #关闭防火墙服务
[root@localhost ~]# setenforce = 0 #临时关闭SELinux
[root@localhost ~]# vi /etc/sysconfig/selinux #修改将"SELINUX=enforcing"更改为"SELINUX=disabled",永久关闭SELINUX
...
SELINUX=disabled
...
重启电脑
[root@localhost ~]# getenforce #查看状态
Disabled
[root@localhost ~]# yum install -y tree net-tools net-snmp vim ntpdate wget httpd #安装部分基础软件包
[root@localhost ~]# cd /etc/yum.repos.d/ #修改yum源 更改为阿里云
[root@localhost ~]# mv CentOS-Base.repo CentOS-Base.repo.bak #备份文件
[root@localhost ~]# wget -O CentOS-Base.repo #下载阿里云镜像仓库
[root@localhost ~]# wget -O /etc/yum.repos.d/epel.repo #下载epel仓库
[root@localhost ~]# yum clean all #清理缓存
[root@localhost ~]# yum makecache #重新生成缓存
2.安装Mysql数据库
[root@localhost ~]# wget https://repo.mysql.com//mysql57-community-release-el7-11.noarch.rpm #下载Mysql 5.7 Yum源
![ee7795e57d18135d8d39695e82b3cbc8.png](https://img-blog.csdnimg.cn/img_convert/ee7795e57d18135d8d39695e82b3cbc8.png)
[root@localhost ~]# ls mysql57-community-release-el7-11.noarch.rpm
![27934c32be4b595b21565031a6964a35.png](https://img-blog.csdnimg.cn/img_convert/27934c32be4b595b21565031a6964a35.png)
[root@localhost ~]# rpm -ivh mysql57-community-release-el7-11.noarch.rpm #安装Mysql Yum源
![2d0dfddd4caa438f8f5e2aff1d09a458.png](https://img-blog.csdnimg.cn/img_convert/2d0dfddd4caa438f8f5e2aff1d09a458.png)
[root@localhost ~]# yum -y install mysql-server #安装mysql
![5e7d6c1a0c4785368bb6e666eb0fc6b0.png](https://img-blog.csdnimg.cn/img_convert/5e7d6c1a0c4785368bb6e666eb0fc6b0.png)
[root@localhost ~]# systemctl start mysqld #启动Mysqld服务
[root@localhost ~]# systemctl enable mysqld #开机自启mysql
[root@localhost ~]# ss -antulp | grep :3306
![a31fe1039894619a6ce7429c039fae0a.png](https://img-blog.csdnimg.cn/img_convert/a31fe1039894619a6ce7429c039fae0a.png)
[root@localhost ~]# grep 'root@localhost:' /var/log/mysqld.log #查看初始密码
![058dafa3a7cd20e4a7fe0a2ad71cca9d.png](https://img-blog.csdnimg.cn/img_convert/058dafa3a7cd20e4a7fe0a2ad71cca9d.png)
2020-11-06T02:28:56.436322Z 1 [Note] A temporary password is generated for root@localhost: ON_Byhz0S6*9
红字部分为初始密码
[root@localhost ~]# mysql -h localhost -uroot -p'ON_Byhz0S6*9' #使用初始密码登陆
注意:-p和密码之间不能有空格。单引号必须要有
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 "1qaz2wsx@JSGQ"; 修改登陆密码
![16aaabe76055e2b0dcab87db477861dd.png](https://img-blog.csdnimg.cn/img_convert/16aaabe76055e2b0dcab87db477861dd.png)
如果提示
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
表示密码安全复杂度不够。要大小写加数字加字符
[root@localhost ~]# mysql -uroot -p1qaz2wsx@JSGQ //使用新密码登陆
![8ccc7d3a40d7bc16387c75d5650c8e17.png](https://img-blog.csdnimg.cn/img_convert/8ccc7d3a40d7bc16387c75d5650c8e17.png)
注意:-p和密码之前是连一起的,不能有空格
3.安装Zabbix 5.0监控平台
安装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
*****也可以使用国内清华大学的YUM安装源
[root@localhost ~]# rpm -Uvh https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
![9d2557f6e8351432dd2d645436c3fa9e.png](https://img-blog.csdnimg.cn/img_convert/9d2557f6e8351432dd2d645436c3fa9e.png)
[root@localhost ~]# yum clean all
![44178eb599cc720b5685f8168bdc2a5f.png](https://img-blog.csdnimg.cn/img_convert/44178eb599cc720b5685f8168bdc2a5f.png)
安装Zabbix Server 与 Zabbix agent
[root@localhost ~]# yum -y install zabbix-server-mysql zabbix-agent
![5f631e1673b357834185d27b8849bcbf.png](https://img-blog.csdnimg.cn/img_convert/5f631e1673b357834185d27b8849bcbf.png)
注意
1、安装报错
zabbix-server-mysql-5.0.5-1.el7.x86_64: [Errno 256] No more mirrors to try.
![c7245a0affee2100ba7cdb0fa5c81b06.png](https://img-blog.csdnimg.cn/img_convert/c7245a0affee2100ba7cdb0fa5c81b06.png)
解决方案:
修改为清华大学的YUM源即可
[root@localhost ~]# vi /etc/yum.repos.d/zabbix.repo
配置文件如下
[zabbix]
name=Zabbix Official Repository - $basearch
#baseurl=http://repo.zabbix.com/zabbix/5.0/rhel/7/$basearch/
baseurl=https://mirror.tuna.tsinghua.edu.cn/zabbix/zabbix/5.0/rhel/7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
[zabbix-frontend]
name=Zabbix Official Repository frontend - $basearch
baseurl=https://mirror.tuna.tsinghua.edu.cn/zabbix/zabbix/5.0/rhel/7/$basearch/frontend
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
[zabbix-debuginfo]
name=Zabbix Official Repository debuginfo - $basearch
#baseurl=http://repo.zabbix.com/zabbix/5.0/rhel/7/$basearch/debuginfo/
baseurl=https://mirror.tuna.tsinghua.edu.cn/zabbix/zabbix/5.0/rhel/7/$basearch/debuginfo/
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
gpgcheck=1
[zabbix-non-supported]
name=Zabbix Official Repository non-supported - $basearch
#baseurl=http://repo.zabbix.com/non-supported/rhel/7/$basearch/
baseurl=https://mirror.tuna.tsinghua.edu.cn/zabbix/non-supported/rhel/7/$basearch/
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
gpgcheck=1
2、
如果安装中报错:Delta RPMs disabled because /usr/bin/applydeltarpm not installed,则安装 deltarpm软件。
yum -y install deltarpm
安装Zabbix frontend
[root@localhost ~]# yum -y install centos-release-scl
![1a25de99423244566d2e2daab02f5ce6.png](https://img-blog.csdnimg.cn/img_convert/1a25de99423244566d2e2daab02f5ce6.png)
[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
...
安装Zabbix前端包(注意本教程是用Nginx不是Apache)
[root@localhost ~]# yum -y install zabbix-web-mysql-scl zabbix-nginx-conf-scl zabbix-apache-conf-scl
如果是Apache请使用以下命令
[root@localhost ~]# yum -y install zabbix-web-mysql-scl zabbix-apache-conf-scl
![3066de1cd7176ceb53c8f55b534e9780.png](https://img-blog.csdnimg.cn/img_convert/3066de1cd7176ceb53c8f55b534e9780.png)
创建和初始化数据库
[root@localhost ~]# mysql -uroot -p1qaz2wsx@JSGQ
![ed4bc02bb3cf48ffa0c73077fed9ac7d.png](https://img-blog.csdnimg.cn/img_convert/ed4bc02bb3cf48ffa0c73077fed9ac7d.png)
mysql> create database zabbix character set utf8 collate utf8_bin;
![2066314726fb08a2efeaf252cd21d8b4.png](https://img-blog.csdnimg.cn/img_convert/2066314726fb08a2efeaf252cd21d8b4.png)
mysql> create user zabbix@localhost identified by '1qaz2wsx@JSGQ';
![fddc8163712ce06c707da9b24c0d2be8.png](https://img-blog.csdnimg.cn/img_convert/fddc8163712ce06c707da9b24c0d2be8.png)
mysql> grant all privileges on zabbix.* to zabbix@localhost;
![65b809fa8ed9999fa4ef2c200d5d185c.png](https://img-blog.csdnimg.cn/img_convert/65b809fa8ed9999fa4ef2c200d5d185c.png)
mysql> exit
导入Zabbix数据库结构和数据
[root@localhost ~]# zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p1qaz2wsx@JSGQ zabbix
![ed2458f451d34f24cf0f8de88c508cd6.png](https://img-blog.csdnimg.cn/img_convert/ed2458f451d34f24cf0f8de88c508cd6.png)
其中-uzabbix是前面在数据库中创建的用户,-p1qaz2wsx@JSGQ是前面数据库中创建的用户的密码,后面的zabbix是前面创建的数据库。
4.配置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;
...
![601cc4d1bf31c13214a53e72ee1bdf54.png](https://img-blog.csdnimg.cn/img_convert/601cc4d1bf31c13214a53e72ee1bdf54.png)
[root@localhost ~]# cat /etc/opt/rh/rh-nginx116/nginx/conf.d/zabbix.conf
server {
listen 80;
server_name example.com;
root /usr/share/zabbix;
index index.php;
location = /favicon.ico {
log_not_found off;
}
location / {
try_files $uri $uri/ =404;
}
location /assets {
access_log off;
expires 10d;
}
location ~ /.ht {
deny all;
}
location ~ /(api/|conf[^.]|include|locale) {
deny all;
return 404;
}
location ~ [^/].php(/|$) {
fastcgi_pass unix:/var/opt/rh/rh-php72/run/php-fpm/zabbix.sock;
fastcgi_split_path_info ^(.+.php)(/.+)$;
fastcgi_index index.php;
fastcgi_param DOCUMENT_ROOT /usr/share/zabbix;
fastcgi_param SCRIPT_FILENAME /usr/share/zabbix$fastcgi_script_name;
fastcgi_param PATH_TRANSLATED /usr/share/zabbix$fastcgi_script_name;
include fastcgi_params;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_intercept_errors on;
fastcgi_ignore_client_abort off;
fastcgi_connect_timeout 60;
fastcgi_send_timeout 180;
fastcgi_read_timeout 180;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
}
}
[root@localhost ~]# vim /etc/zabbix/zabbix_server.conf
...
116 DBUser=zabbix //用户名要与数据库中创建的供zabbix访问的用户名一致
...
124 DBPassword=1qaz2wsx@JSGQ //去掉注释,添加创建的zabbix用户的数据库密码
![e0bd3a56376571fe34bbc6be9391290d.png](https://img-blog.csdnimg.cn/img_convert/e0bd3a56376571fe34bbc6be9391290d.png)
为Zabbix前端配置PHP
[root@localhost ~]# vim /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf
[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] = Europe/Riga
--》取消注释将Europe/Riga时区修改为以下:
php_value[date.timezone] = Asia/Shanghai
![d70d35d23c3d3babbb4961044c00db42.png](https://img-blog.csdnimg.cn/img_convert/d70d35d23c3d3babbb4961044c00db42.png)
6.开启服务
[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
[root@localhost ~]# ss -antulp | grep :80
tcp LISTEN 0 128 :::80 :::* users:(("httpd",pid=5619,fd=4),("httpd",pid=5618,fd=4),("httpd",pid=5617,fd=4),("httpd",pid=5616,fd=4),("httpd",pid=5614,fd=4),("httpd",pid=5585,fd=4))
![db5e0c25ee4ebff8fb568208c069e66f.png](https://img-blog.csdnimg.cn/img_convert/db5e0c25ee4ebff8fb568208c069e66f.png)
[root@localhost ~]# ps -aux | grep zabbix
......
apache 5677 0.0 0.3 336672 7316 ? S 16:36 0:00 php-fpm: pool zabbix
root 5809 0.0 0.0 112736 976 pts/0 S+ 16:47 0:00 grep --color=auto zabbix
7.访问客户端并安装
在IE中打开
![fd10d9ee9205ac0baf381dc9b57c16a5.png](https://img-blog.csdnimg.cn/img_convert/fd10d9ee9205ac0baf381dc9b57c16a5.png)
![1d48dabd187c196c68660c6b39db7169.png](https://img-blog.csdnimg.cn/img_convert/1d48dabd187c196c68660c6b39db7169.png)
![02bb260636ec10c5989d679a87b651a5.png](https://img-blog.csdnimg.cn/img_convert/02bb260636ec10c5989d679a87b651a5.png)
![08290c1ca4f85ce2f3f13ed749fad773.png](https://img-blog.csdnimg.cn/img_convert/08290c1ca4f85ce2f3f13ed749fad773.png)
![4eb5f0742859de6f8b553d11638e69c0.png](https://img-blog.csdnimg.cn/img_convert/4eb5f0742859de6f8b553d11638e69c0.png)
![d784a4db9f35fd1a9ba4491e42d12677.png](https://img-blog.csdnimg.cn/img_convert/d784a4db9f35fd1a9ba4491e42d12677.png)
![4a7545a2f8251eac1fad0bf6d3e62f41.png](https://img-blog.csdnimg.cn/img_convert/4a7545a2f8251eac1fad0bf6d3e62f41.png)
错误:时区不对
DateTime::__construct(): Invalid date.timezone value 'Aisa/Shanghai', we selected the timezone 'UTC' for now.
![abf281b01d3a958f230b47b95f1ac3a2.png](https://img-blog.csdnimg.cn/img_convert/abf281b01d3a958f230b47b95f1ac3a2.png)
vim /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf
修改为
php_value[date.timezone] = Asia/Shanghai
注意拼写
第一次写成了Aisa/Shanghai
导致出错
![06185754337b743b9517b4e7b1064c12.png](https://img-blog.csdnimg.cn/img_convert/06185754337b743b9517b4e7b1064c12.png)
错误:时区错误
如下图
![1456fabee47eeffbd48ac45af7928c67.png](https://img-blog.csdnimg.cn/img_convert/1456fabee47eeffbd48ac45af7928c67.png)
主要原因也是没有配置时区