首先本人是一片空白的进行zabbix搭建工作,其实搭建这个之前我搭建过zabbix 2.4,我感觉之前的那个太老了,然后就又推到了重新干了一遍,感觉收获满满。其实最重要的还是要多折腾,折腾多了就自然而然的学会怎么搭建了。当然之前的搭建也是看了前辈们的操作文档,所以还是非常感谢前辈们的贡献,废话不多说,干起来。
一、软件下载:
rpm软件下载地址:http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/
cd /usr/src/zabbix3.4.5/ //软件包下载目录 (没有目录可以在底下建立一个,当然这个目录随意)
[root@Node3 zabbix3.4.5]# ls
zabbix-agent-3.4.5-1.el7.x86_64.rpm
zabbix-proxy-sqlite3-3.4.5-1.el7.x86_64.rpm
zabbix-web-japanese-3.4.5-1.el7.noarch.rpm
zabbix-get-3.4.5-1.el7.x86_64.rpm
zabbix-sender-3.4.5-1.el7.x86_64.rpm
zabbix-web-mysql-3.4.5-1.el7.noarch.rpm
zabbix-java-gateway-3.4.5-1.el7.x86_64.rpm
zabbix-server-mysql-3.4.5-1.el7.x86_64.rpm
zabbix-web-pgsql-3.4.5-1.el7.noarch.rpm
zabbix-proxy-mysql-3.4.5-1.el7.x86_64.rpm
zabbix-server-pgsql-3.4.5-1.el7.x86_64.rpm
zabbix-proxy-pgsql-3.4.5-1.el7.x86_64.rpm
zabbix-web-3.4.5-1.el7.noarch.rpm
其实我就是用一个笨方法一个一个的获取,比如说获取 zabbix-agent-3.4.5-1.el7.x86_64.rpm 我就用这个命令http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-agent-3.4.5-1.el7.x86_64.rpm 下载它,其他的依次类推一个一个的下载
当然也可以在windows上下载好以后传到linux主机上,看自己的喜好来。
二、关闭防火墙:
[root@Node3 ~]# systemctl stop firewalld.service //停掉防火墙
[root@Node3 ~]# systemctl disable firewalld.service //禁止防火墙开机自启动
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service. Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@Node3 ~]# iptables -X
[root@Node3 ~]# iptables -Z
[root@Node3 ~]# iptables -F
[root@Node3 ~]# iptables -vnL
Chain INPUT (policy ACCEPT 228 packets, 15806 bytes) pkts bytes target prot opt in out source destination Chain FORWARD (policy ACCEPT 0 packets, 0 bytes) pkts bytes target prot opt in out source destination Chain OUTPUT (policy ACCEPT 252 packets, 19733 bytes) pkts bytes target prot opt in out source destination
三、禁用SElinux
[root@Node3 ~]# vim /etc/selinux/config //在/etc/selinux/config 把SELNUX=enforcing换成SELINUX=disabled
[root@Node3 ~]# setenforce 0
setenforce: SELinux is disabled
[root@Node3 ~]# getenforce Disabled
[root@Node3 ~]# systemctl reboot
注:部署官方文档
rpm包安装3.4手册:https://www.zabbix.com/documentation/3.4/zh/manual/installation/getting_zabbix
从源代码安装zabbix 3.4: https://www.zabbix.com/documentation/3.4/zh/manual/installation/install#installation_from_sources
四、数据库的安装及配置
这里采用的是MariaDB,MariaDB的目的是完全兼容MySQL,包括API和命令行,使之能轻松成为MySQL的代替品
1)安装MariaDB:
[root@Node3 ~]# yum install mariadb-server mariadb –y //yum安装mariadb
[root@Node3 ~]# rpm -qa | grep mariadb
mariadb-5.5.56-2.el7.x86_64 mariadb-server-5.5.56-2.el7.x86_64 mariadb-libs-5.5.56-2.el7.x86_64
2)设置MariaDB并启动:
1、编辑my.cnf文件,增加以下内容:
[root@Node3 ~]# vim /etc/my.cnf //编辑my.cnf文件
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock innodb_file_per_table = on //每个表使用一张单独的表
skip_name_resolve = on //跳过名称反解
# Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
[mysqld_safe] log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid
#
# include all files from the config directory
# !includedir /etc/my.cnf.d
2、启动数据库,并设置开机自启动
[root@Node3 ~]# systemctl start mariadb.service //启动数据库
[root@Node3 ~]# systemctl enable mariadb.service //设置开机自启动
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
[root@Node3 ~]# systemctl status mariadb.service //查看状态
[root@Node3 ~]# ss -tnl | grep 3306 //查看3306端口是否正常
LISTEN 0 50 *:3306 *:*
3) 创建数据库:
[root@Node3 ~]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 2 Server version: 5.5.56-MariaDB MariaDB Server Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> CREATE DATABASE zabbix CHARSET 'utf8' COLLATE 'utf8_bin'; //创建数据库,并设置字符集
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> GRANT ALL ON zabbix.* TO 'zabbix'@Node3 IDENTIFIED BY 'zabbix'; //授权用户对其数据库的权限
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> exit
Bye
[root@Node3 ~]# mysql -uzabbix -pzabbix -h Node3 //测试数据库是否登录正常
Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 3 Server version: 5.5.56-MariaDB MariaDB Server Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>
五 、Zabbix3.4.5安装及配置:
1、设置zabbix yum源仓库
[root@Node3 ~]# rpm -Uvh http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-1.el7.centos.noarch.rpm //连接外网可以安装yum源的rpm包,让其自动生成zabbix仓库
Retrieving http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-1.el7.centos.noarch.rpm Preparing... ################################# [100%]
Updating / installing... 1:zabbix-release-3.4-1.el7.centos ################################# [100%]
[root@Node3 ~]# ls /etc/yum.repos.d/ //查看仓库是否自动生成
cdrom.repo repo zabbix.repo CentOS-Base.repo
2、安装 zabbix3.4.5
[root@Node3 zabbix3.4.5]# yum -y install zabbix-server-mysql-3.4.5-1.el7.x86_64.rpm zabbix-web-mysql-3.4.5-1.el7.noarch.rpm zabbix-get-3.4.5-1.el7.x86_64.rpm //安装zabbix服务端(直接复制粘贴)
等待安装成功,安装成功后导入数据库文件
3、导入zabbix数据库
[root@Node3 zabbix3.4.5]# zcat /usr/share/doc/zabbix-server-mysql-3.4.5/create.sql.gz |mysql -uzabbix-pzabbix -hNode3 zabbix //导入数据库
4、配置数据库用户及密码
[root@Node3 ~]# vim /etc/zabbix/zabbix_server.conf //修改zabbix_server.conf配置文件红色部分
[root@Node3 ~]# vim /etc/zabbix/zabbix_server.conf //查看并修改部分
LogFile=/var/log/zabbix/zabbix_server.log
LogFileSize=0
PidFile=/var/run/zabbix/zabbix_server.pid
SocketDir=/var/run/zabbix
DBHost=127.0.0.1 //修改数据库地址
DBName=zabbix //修改数据库名
DBUser=zbxuser //修改数据库账号
DBPassword=zbxpass //修改数据库密码
SNMPTrapperFile=/var/log/snmptrap/snmptrap.log
Timeout=4 490:AlertScriptsPath=/usr/lib/zabbix/alertscripts //Zabbix运行脚本存放目录
ExternalScripts=/usr/lib/zabbix/externalscripts
LogSlowQueries=3000
(对比下自己的文件,如果相同则不需要更改)
5、编辑Zabbix前端PHP配置,更改时区
[root@Node3 zabbix]# vim +19 /etc/httpd/conf.d/zabbix.conf
//将#去掉,修改为Asia/Shanghai
6、SELinux配置
[root@Node3 zabbix]# setsebool -P
httpd_can_connect_zabbix on setsebool: SELinux is disabled.
[root@Node3 zabbix]# setsebool -P
httpd_can_cetwork_connect_db on setsebool: SELinux is disabled.
7、开启httpd服务,并设置开机自启动
1 2 3 4 5 |
[root@Node3 zabbix]# systemctl start httpd.service [root@Node3 zabbix]# systemctl enable httpd.service Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service. [root@Node3 zabbix]# ss -tnl | grep 80 LISTEN 0 128 :::80 :::* |
8、开启zabbix- server服务,并设置为开机自启动
[root@Node3 zabbix]# systemctl start zabbix-server.service
[root@Node3 zabbix]# systemctl enable zabbix-server.service
Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-server.service to /usr/lib/systemd/system/zabbix-server.service.
[root@Node3 zabbix]# ss -tnl | grep 10051
LISTEN 0 128 *:10051 *:* LISTEN 0 128 :::10051 :::*
四、安装Zabbix Web
1、浏览器访问,并进行安装http://127.0.0.1/zabbix/
2、点击Next setp
3、查看没有相关的报错信息,然后再点击Next step
4、设置数据库地址,数据库,数据用户及密码、端口号等(端口号0代表默认端口)
(在password中写入当时设置的数据库密码:zabbix)
5、设置Zabbix平台名称,点击Next step
完成安装,会将在/etc/zabbix/web/zabbix.conf.php生成配置文件
Congratulations! You have successfully installed Zabbix frontend.
Configuration file "/etc/zabbix/web/zabbix.conf.php" created.
6、看到以上安装 成功的字样,代表安装成功,点击Finish结束安装,打开登录界面,默认账号为:Admin 密码为:zabbix,点击Sign in
7、登录成功之后,看到以下界面,代表安装结束
8.进去页面后,发现全是英文怎么办?
可以在点击小人,然后出来选择语言项目,点击选择chinese zh_CN 界面就变成熟悉的汉字了