centos7部署zabbix3.4
前言
大家好, zabbix作为分布式自动化监控系统,已经非常成熟,在生产环境中的应用也颇为广泛,本人就自己的部署过程做个分享,主要以zabbix3.4版本的部署为例,这是我第一篇文章分享,请大家多多支持,如有不足,请大家多担待。。。。
废话不多说,直接上干货。
一,系统环境
1.查看系统环境
[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.3.1611 (Core)
[root@localhost ~]# systemctl stop firewalld.service
[root@localhost ~]# systemctl disable firewalld.service
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
Removed symlink /etc/systemd/system/basic.target.wants/firewalld.service.
[root@localhost ~]# sed -i ‘s/SELINUX=enforcing/SELINUX=disabled/’ /etc/selinux/config
[root@localhost ~]# grep SELINUX=disabled /etc/selinux/config
SELINUX=disabled
[root@localhost ~]# setenforce 0
2. 安装并启动httpd
[root@localhost ~]# yum install httpd httpd-devel -y
[root@localhost ~]# rpm -qa |grep httpd
httpd-tools-2.4.6-67.el7.centos.6.x86_64
httpd-2.4.6-67.el7.centos.6.x86_64
httpd-devel-2.4.6-67.el7.centos.6.x86_64
[root@localhost ~]# systemctl enable httpd.service
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
[root@localhost ~]# systemctl start httpd.service
二,数据库的安装与配置
1.安装与查看
[root@localhost ~]# yum install mariadb-server mariadb mariadb-devel mariadb-test -y
[root@localhost ~]# rpm -qa |grep maria
mariadb-libs-5.5.56-2.el7.x86_64
mariadb-5.5.56-2.el7.x86_64
mariadb-server-5.5.56-2.el7.x86_64
mariadb-test-5.5.56-2.el7.x86_64
mariadb-devel-5.5.56-2.el7.x86_64
2.数据库相关命令
mariadb数据库的相关命令是:
systemctl start mariadb #启动MariaDB
systemctl stop mariadb #停止MariaDB
systemctl restart mariadb #重启MariaDB
systemctl enable mariadb #设置开机启动
[root@localhost ~]# systemctl start mariadb
[root@localhost ~]# systemctl stop mariadb
[root@localhost ~]# systemctl restart mariadb
[root@localhost ~]# systemctl enable mariadb
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
三、Zabbix3.4安装及配置
1、安装zabbix最新版epel源:
[root@localhost ~]# rpm -ivh http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-1.el7.centos.noarch.rpm
安装 zabbix rpm 源,鉴于国内网络情况,使用阿里云 zabbix 源
2、安装zabbix服务端软件包:
[root@localhost ~]# yum install zabbix-server-mysql zabbix-web-mysql -y
[root@localhost ~]# rpm -qa |grep zabbix-*
zabbix-release-3.4-1.el7.centos.noarch
zabbix-server-mysql-3.4.3-1.el7.x86_64
zabbix-web-3.4.3-1.el7.noarch
zabbix-web-mysql-3.4.3-1.el7.noarch
3.初始化数据库
[root@localhost ~]# mysql_secure_installation #数据库初始化命令
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we’ll need the current
password for the root user. If you’ve just installed MariaDB, and
you haven’t set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none):
ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using password: YES)
Enter current password for root (enter for none):
ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using password: YES)
Enter current password for root (enter for none):
ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using password: YES)
Enter current password for root (enter for none):
OK, successfully used password, moving on…
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
Set root password? [Y/n]y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables…
… Success!
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n]y
… Success!
Normally, root should only be allowed to connect from ‘localhost’. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n]n
… skipping.
By default, MariaDB comes with a database named ‘test’ that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] n
… skipping.
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] y
… Success!
Cleaning up…
All done! If you’ve completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
4.配置数据库
[root@localhost ~]# mysql -uroot -p
Enter password: 123456(数据库密码–自行填写)
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 11
Server version: 5.5.56-MariaDB MariaDB Server
Copyright © 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 character set utf8 collate utf8_bin;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> create user ‘zabbix’@‘localhost’ identified by ‘zabbix’;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> set storage_engine=INNODB;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> grant all privileges on zabbix.* to zabbix@localhost 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)]> quit
Bye
5.导入数据
导入数据库之前可以登陆数据库里查看zabbix有无相应的表。
[root@localhost ~]# zcat /usr/share/doc/zabbix-server-mysql-3.4.15/create.sql.gz | mysql -uzabbix -pzabbix Zabbix
注:出现此错误为导入数据到数据库zabbix时,对应的mysql版本号与当前不相符,相关代码为:zcat /usr/share/doc/zabbix-server-mysql-4.0.0/create.sql.gz | mysql -uzabbix -p -h 127.0.0.1 zabbix
解决办法在SSH下输入cd /usr/share/doc/回车,再输入ls回车就会显示出doc文件夹下面所有文件名信息
6.修改zabbix配置文件:
[root@localhost zabbix]# grep -n ‘^’[a-Z] /etc/zabbix/zabbix_server.conf
38:LogFile=/var/log/zabbix/zabbix_server.log
49:LogFileSize=0
72:PidFile=/var/run/zabbix/zabbix_server.pid
82:SocketDir=/var/run/zabbix
101:DBName=zabbix
117:DBUser=zabbix
125:DBPassword=zabbix #只需要设备MySQL数据库zabbix用户对应密码
316:SNMPTrapperFile=/var/log/snmptrap/snmptrap.log
434:Timeout=4
476:AlertScriptsPath=/usr/lib/zabbix/alertscripts
486:ExternalScripts=/usr/lib/zabbix/externalscripts
522:LogSlowQueries=3000
[root@localhost zabbix]# more /etc/zabbix/zabbix_server.conf | grep -v “#” | grep -v “^$”
LogFile=/var/log/zabbix/zabbix_server.log
LogFileSize=0
PidFile=/var/run/zabbix/zabbix_server.pid
SocketDir=/var/run/zabbix
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix
SNMPTrapperFile=/var/log/snmptrap/snmptrap.log
Timeout=4
AlertScriptsPath=/usr/lib/zabbix/alertscripts
ExternalScripts=/usr/lib/zabbix/externalscripts
LogSlowQueries=3000
7.修改Apache服务器下,php相关的配置文件:编辑Zabbix前端PHP配置,更改时区
[root@localhost zabbix]# more /etc/httpd/conf.d/zabbix.conf | grep -v “#” | grep -v “^$”
Alias /zabbix /usr/share/zabbix
<Directory “/usr/share/zabbix”>
Options FollowSymLinks
AllowOverride None
Require all granted
8.启动zabbix server并设置开机启动
[root@localhost ~]# systemctl enable zabbix-server
Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-server.service to /usr/lib/systemd/system/zabbix-server.service.
[root@localhost ~]# systemctl start zabbix-server
四、安装Zabbix Web
先重启httpd服务
[root@localhost ~]# systemctl restart httpd.service
[root@localhost ~]#
1、浏览器访问,并进行安装http://ip/zabbix/
图片: 在这里插入图片描述
2.完成安装
将在/etc/zabbix/web/zabbix.conf.php生成配置文件 Congratulations! You have successfully installed Zabbix frontend. Configuration file “/etc/zabbix/web/zabbix.conf.php” created.
登录最新版Zabbix3.4 默认用户Admin 默认密码zabbix
五、zabbxi-agent安装及配置
1、安装zabbxi-agent
[root@localhost ~]# yum install zabbix-agent -y
2、配置zabbxi-agent
[root@localhost zabbix]# grep -n ‘^’[a-Z] /etc/zabbix/zabbix_agentd.conf
13:PidFile=/var/run/zabbix/zabbix_agentd.pid
32:LogFile=/var/log/zabbix/zabbix_agentd.log
43:LogFileSize=0
97:Server=127.0.0.1
138:ServerActive=127.0.0.1
149:Hostname=Zabbix server
267:Include=/etc/zabbix/zabbix_agentd.d/*.conf
[root@localhost zabbix]#
3、启动zabbxi-agent并设置开机启动
[root@localhost ~]# systemctl enable zabbix-agent.service
Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-agent.service to /usr/lib/systemd/system/zabbix-agent.service.
[root@localhost ~]# systemctl restart zabbix-agent.service
[root@localhost ~]#
至此,zabbi-server3.4就安装成功了,后期我会继续分享zabbix-agent安装与监控其他主机的过程,也会分享一些踩坑案例,避免大家在安装过程中走弯路,欢迎大家关注我,有问题请留言,大家一起学习交流,一起进步。。。。