Zabbix 安装部署
zabbix官网:TP
可选择中英文阅读
1.更改zabbbix的官方源
[root@m01 ~]# rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
2.清理yum 缓存并查看源仓库
[root@m01 ~]# yum clean all
[root@m01 ~]# ll /etc/yum.repos.d/
-rw-r--r--. 1 root root 2523 Jul 14 23:48 CentOS-Base.repo
-rw-r--r--. 1 root root 664 Jul 14 23:48 epel.repo
-rw-r--r-- 1 root root 853 May 11 2020 zabbix.repo
3.安装zabbix的服务端和客户端
[root@m01 ~]# yum -y install zabbix-server-mysql zabbix-agent
4.安装zabbix的web前端
[root@m01 ~]# yum install centos-release-scl -y
5.打开zabbix的前端仓库
[root@m01 ~]# 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
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
6.安装zabbix前端
[root@m01 ~]# yum install zabbix-web-mysql-scl zabbix-nginx-conf-scl -y
7.安装数据库
[root@m01 ~]# yum install -y mariadb-server
8.启动mariadb并加入开机自启
[root@m01 ~]# systemctl start mariadb
[root@m01 ~]# systemctl enable mariadb
9.连接数据库
[root@m01 ~]# mysql
9.1创建数据库
#创建zabbix数据库,字符集是utf8,校验规则是utf8_bin
MariaDB [(none)]> create database zabbix character set utf8 collate utf8_bin;
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
| zabbix |
+--------------------+
9.2创建用户
#创建zabbix用户,主机是localhost,密码是zabbix
MariaDB [(none)]> grant all privileges on zabbix.* to zabbix@localhost identified by ‘zabbix‘;
MariaDB [(none)]> select user,host from mysql.user;
+--------+-----------+
| user | host |
+--------+-----------+
| root | 127.0.0.1 |
| root | ::1 |
| | localhost |
| root | localhost |
| zabbix | localhost |
| | zabbix |
| root | zabbix |
+--------+-----------+
10.导入MySQL数据
[root@m01 ~]# zcat /usr/share/doc/zabbix-server-mysql-5.0.14/create.sql.gz|mysql zabbix
#进入数据库
[root@m01 ~]# mysql
MariaDB [(none)]> use zabbix;
MariaDB [zabbix]> show tables;
11.修改zabbix-server配置文件
[root@m01 ~]# vim /etc/zabbix/zabbix_server.conf
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix
12.修改zabbix前端配置(nginx配置)
[root@m01 ~]# vim /etc/opt/rh/rh-nginx116/nginx/conf.d/zabbix.conf
server {
listen 80;
server_name zabbix.qy.com;
12.1域名解析
在电脑端按windows+R 输入drivers 找到C:\Windows\System32\drivers\etc\hosts文件
10.0.0.71 zabbix.qy.com
13.修改php-fpm配置文件
[root@m01 ~]# vim /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf
[zabbix]
user = nginx
group = nginx
listen.acl_users = nginx
php_value[date.timezone] = Asia/Shanghai #更改时区
14.启动服务并加入开机自启
[root@m01 ~]# systemctl start zabbix-server zabbix-agent rh-nginx116-nginx rh-php72-php-fpm
[root@m01 ~]# systemctl enable zabbix-server zabbix-agent rh-nginx116-nginx rh-php72-php-fpm
15.修改目录权限
-----------------------------1.修改php session共享的目录权限 ----------------------------------
[root@m01 nginx]# chown -R nginx.nginx /var/opt/rh/
-----------------------------2.php socket文件授权 --------------------------------------------
[root@m01 nginx]# chown nginx.nginx /var/opt/rh/rh-php72/run/php-fpm/zabbix.sock
---------------------------- 3.修改php目录权限 ------------------------------------------------
[root@m01 nginx]# chown -R nginx.nginx /etc/zabbix/web/
打开浏览器访问:http://zabbix.qy.com/
zabbix汉化
修改汉字
在windows上找到中文字体 C:\Windows\Fonts 放到: /usr/share/zabbix/assets/fonts 改名为:graphfont.ttf
安装zabbix客户端
# 1.修改客户端yum源
[root@web02 ~]# rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
# 2.清理缓存
[root@web02 ~]# yum clean all
# 3.安装zabbix客户端
[root@web02 ~]# yum install -y zabbix-agent
# 4.修改配置文件(写服务端IP)
[root@web02 ~]# vim /etc/zabbix/zabbix_agentd.conf
Server=127.0.0.1,172.16.1.61 ={{ ansible_eth1.ipv4.address }} 变量
ServerActive=127.0.0.1,172.16.1.61 ={{ ansible_defult_ipv4.address }} 变量
# 5.启动服务加入开机自启
[root@web02 ~]# systemctl start zabbix-agent
[root@web02 ~]# systemctl enable zabbix-agent
# 6.检查端口
[root@web02 ~]# netstat -lntup
tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 21845/zabbix_agentd
#7.防火墙增加zabbix-agent服务
[root@web02 ~]# firewall-cmd --add-service=zabbix-agent
创建主机
主从复制
主库
# 1.安装mariadb
[root@m01 ~]# yum install -y mariadb-server
# 2.修改主库配置文件
[root@m01 ~]# vim /etc/my.cnf
新增2行配置
log-bin=mysql-bin
server_id=1
# 3.重启服务
[root@m01 ~]# systemctl restart mariadb
# 4.在主库上创建一个可以主从复制的用户
[root@m01 ~]# mysql
MariaDB [(none)]> grant replication slave on *.* to rep@‘172.16.1.%‘ identified by ‘123‘;
注解:*.* 表示所有库所有表 rep :用户
# 5.记录主库上的日志位置点
MariaDB [(none)]> show master status;
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000001 | 96582 | | |
+------------------+----------+--------------+------------------+
MariaDB [(none)]> show master status;
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000003 | 390 | | |
+------------------+----------+--------------+------------------+
从库
# 1.安装mariadb
[root@web02 ~]# yum install -y mariadb-server
# 2.修改从库的配置文件
[root@web02 ~]# vim /etc/my.cnf
新增1行配置
server_id=2
# 3.启动从库
[root@web02 ~]# systemctl start mariadb
# 4.从库配置
[root@web02 ~]# mysql
change master to
master_host=‘172.16.1.61‘,
master_user=‘rep‘,
master_password=‘123‘,
master_log_file=‘mysql-bin.000001‘,
master_log_pos=350028;
# 5.开启主从复制
MariaDB [(none)]> start slave;
# 6.查看主从复制状态
MariaDB [(none)]> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 172.16.1.61
Master_User: rep
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000003
Read_Master_Log_Pos: 390
Relay_Log_File: mariadb-relay-bin.000002
Relay_Log_Pos: 529
Relay_Master_Log_File: mysql-bin.000003
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
##当 Slave_IO_Running 和 Slave_SQL_Running 均为 yes 时才可完成主从复制
##如果不是yes,可查看主库防火墙是否允许mysql服务访问通过
-----------------------------------------#验证 -----------------------------------------------
#1.在主库里创建新的库
MariaDB [(none)]> create database qy;
#2.在从库里查看是否出现新出现的库
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| qy |
| test |
+--------------------+
搭建zabbix主从复制服务时需要准备的文件使用ansible搭建时
1.zabbix的数据库文件
mysqldump zabbix > /opt/zabbix.sql
2.连接数据库的配置文件
/etc/zabbix/web/zabbix.conf.php文件
3.注意:先将主从复制服务搭建好,然后再推送wordpress/zhihu的数据