Zabbix 4.0.2试用(三):安装Zabbix 4.0.2
完成上一步的CentOS7的安装后,开始安装Zabbix,具体步骤如下:
使用root用户登陆系统:
1、关闭防火墙
首先查看防火墙状态
[root@zabbix ~]# firewall-cmd –state
running
[root@zabbix ~]#
关闭firewall,并禁止防火墙开机启动,命令如下:
[root@zabbix ~]# systemctl stop firewalld.service
[root@zabbix ~]# systemctl disable firewalld.service
再次查看,防火墙已不在运行:
[root@zabbix ~]# firewall-cmd –state
2、关闭SELINUX
安装之前还需将SELINUX关闭,运行如下命令编辑SELINUX配置文件:
[root@zabbix ~]# vi /etc/selinux/config
并将SELINUX=enforcing改成SELINUX=disable,如下:
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing – SELinux security policy is enforced.
# permissive – SELinux prints warnings instead of enforcing.
# disabled – No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three two values:
# targeted – Targeted processes are protected,
# minimum – Modification of targeted policy. Only selected processes are protected.
# mls – Multi Level Security protection.
SELINUXTYPE=targeted
修改完成后,重启机器,运行如下命令查看是否 SELINUX已关闭:
[root@zabbix ~]# getenforce
退回disable即为已关闭,如下图。
3、安装LAMP环境
Zabbix前端为PHP,后端准备使用的数据库为MariaDB(与MYSQL兼容,mysql创始化带领团队创建),目前集合的环境有LAMP和LNMP,只是WEB应用使用Apache或Nginx的区别,本次准备采用LAMP来运行Zabbix,因为本机与互联网相通,故准备采用yum的方式来安装。
首先升级相关yum源中的软件至最新版,使用如下命令:
[root@zabbix ~]# yum -y update
开始对程序进行升级,如下图:
如上图,完成了yum源升级后,开始安装LAMP,运行如下命令:
[root@zabbix ~]# yum install -y httpd mariadb-server mariadb php php-mysql php-gd libjpeg* php-ldap php-odbc php-pear php-xml php-xmlrpc php-mhash
开始安装,如下图:
完成安装后,使用如下命令查看重要是否已安装:
[root@zabbix ~]# rpm -qa httpd php mariadb
httpd-2.4.6-88.el7.centos.x86_64
mariadb-5.5.60-1.el7_5.x86_64
php-5.4.16-46.el7.x86_64
[root@zabbix ~]#
如上,显示已安装了http、php和数据库mariadb。
4、配置LAMP环境
完成LAMP环境安装后,开始配置Apache和PHP,通过如下命令打开httpd.conf配置文件,修改ServerName和DirectoryIndex,将监听IP及端口修改为本机的IP及80端口,DirectoryIndex中加入index.php文件:
[root@zabbix ~]# vi /etc/httpd/conf/httpd.conf
由于本机的IP为10.208,则ServerName修改成:
ServerName 192.168.10.208:80
Zabbix默认页面为index.php,添加index.php进DirectoryIndex,如下:
<IfModule dir_module>
DirectoryIndex index.html index.php
< /IfModule>
完成以上修改为保存退出。
再修改php.ini配置文件,设置时区为PRC,由于运维管理系统是记录设备运维日志等,需要查看设备出现问题时的时间,对时间的准确性有要求,故需修改:
[root@zabbix ~]# vi /etc/php.ini
使用/timezone搜索需要修改的位置,并修改为:
date.timezone = PRC
完成后保存退出。
5、启动LAMP环境
开始启动httpd和mariadb:
[root@zabbix ~]# systemctl start httpd
[root@zabbix ~]# systemctl start mariadb
设置开机启动服务:
[root@zabbix ~]# systemctl enable httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
[root@zabbix ~]# systemctl enable mariadb
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
[root@zabbix ~]#
查看服务是否启动:
[root@zabbix ~]# ss -naplt | grep httpd
LISTEN 0 128 :::80 :::* users:((“httpd”,pid=26988,fd=4),(“httpd”,pid=26987,fd=4),(“httpd”,pid=26986,fd=4),(“httpd”,pid=26985,fd=4),(“httpd”,pid=26984,fd=4),(“httpd”,pid=26980,fd=4))
[root@zabbix ~]# ss -naplt | grep mysqld
LISTEN 0 50 *:3306 *:* users:((“mysqld”,pid=27272,fd=13))
[root@zabbix ~]#
查看httpd和mysqld已经启动,80和3306端口也已启动,如下图:
接着再测试php是否正常,新建一个PHP测试页:
[root@zabbix ~]# vi /var/www/html/index.php
输入:
<?php
phpinfo();
?>
保存退出,然后打开浏览器,输入http://192.168.10.208,显示PHP即为正常。
6、配置MariaDB数据库
设置数据库密码为zabbixroot:
[root@zabbix ~]# mysqladmin -u root password zabbixroot
验证密码是否正常:
[root@zabbix ~]# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 5.5.60-MariaDB MariaDB ServerCopyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.
MariaDB [(none)]>
开始创建数据库,
MariaDB [(none)]> CREATE DATABASE zabbix character set utf8 collate utf8_bin;
Query OK, 1 row affected (0.00 sec)MariaDB [(none)]> GRANT all ON zabbix.* TO ‘zabbix’@’zabbix’ IDENTIFIED BY ‘zabbix123’;
Query OK, 0 rows affected (0.00 sec)MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)MariaDB [(none)]> quit
Bye
[root@zabbix ~]#
完成创建后,测试数据库是否能够连接,运行是否正常,将刚创建的php测试页的内容修改为:
<?php
$link=mysql_connect(‘192.168.10.208′,’zabbix’,’zabbix123′);
if($link) echo “<h1>Datebase Connect Success~~~~~</h1>”;
else echo “Fail!!”;
mysql_close();
?>
设置本机的IP地址,并设置刚才创建的用户名和密码:
设置后保存退出,然后在浏览器中输入http://192.168.10.208,正常应该显示Datebase Connect Success~~~~~:
7、安装Zabbix 4.0.2
完成以上的设置后,即可以开始安装Zabbix,继续采用yum方式安装,首先安装相关依赖包:
[root@zabbix ~]# yum -y install net-snmp net-snmp-devel curl curl-devel libxml2 libxml2-devel libevent-devel.x86_64 javacc.noarch javacc-javadoc.noarch javacc-maven-plugin.noarch javacc*
yum会自动下载安装包并完成安装,
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.cn99.com
* extras: mirrors.aliyun.com
* updates: mirrors.cn99.com
base | 3.6 kB 00:00:00
extras | 3.4 kB 00:00:00
updates | 3.4 kB 00:00:00
Package curl-7.29.0-51.el7.x86_64 already installed and latest version
Package libxml2-2.9.1-6.el7_2.3.x86_64 already installed and latest version
Resolving Dependencies
–> Running transaction check
—> Package javacc.noarch 0:5.0-10.el7 will be installed
—> Package javacc-demo.noarch 0:5.0-10.el7 will be installed
—> Package javacc-javadoc.noarch 0:5.0-10.el7 will be installed
—> Package javacc-manual.noarch 0:5.0-10.el7 will be installed
—> Package javacc-maven-plugin.noarch 0:2.6-17.el7 will be installed
–> Processing Dependency: mvn(org.codehaus.plexus:plexus-utils) for package: javacc-maven-plugin-2.6-17.el7.noarch
–> Processing Dependency: mvn(org.apache.maven:maven-project) for package: javacc-maven-plugin-2.6-17.el7.noarch
–> Processing Dependency: mvn(org.apache.maven:maven-plugin-api) for package: javacc-maven-plugin-2.6-17.el7.noarch
–> Processing Dependency: mvn(org.apache.maven:maven-model) for package: javacc-maven-plugin-2.6-17.el7.noarch
–> Processing Dependency: mvn(org.apache.maven.reporting:maven-reporting-impl) for package: javacc-maven-plugin-2.6-17.el7.noarch
–> Processing Dependency: mvn(org.apache.maven.reporting:maven-reporting-api) for package: javacc-maven-plugin-2.6-17.el7.noarch
–> Processing Dependency: mvn(org.apache.maven.doxia:doxia-site-renderer) for package: javacc-maven-plugin-2.6-17.el7.noarch
–> Processing Dependency: mvn(org.apache.maven.doxia:doxia-sink-api) for package: javacc-maven-plugin-2.6-17.el7.noarch
—> Package javacc-maven-plugin-javadoc.noarch 0:2.6-17.el7 will be installed
—> Package libcurl-devel.x86_64 0:7.29.0-51.el7 will be installed
—> Package libevent-devel.x86_64 0:2.0.21-4.el7 will be installed
—> Package libxml2-devel.x86_64 0:2.9.1-6.el7_2.3 will be installed
–> Processing Dependency: zlib-devel for package: libxml2-devel-2.9.1-6.el7_2.3.x86_64
–> Processing Dependency: xz-devel for package: libxml2-devel-2.9.1-6.el7_2.3.x86_64
—> Package net-snmp.x86_64 1:5.7.2-37.el7 will be installed
–> Processing Dependency: net-snmp-agent-libs = 1:5.7.2-37.el7 for package: 1:net-snmp-5.7.2-37.el7.x86_64
–> Processing Dependency: libnetsnmptrapd.so.31()(64bit) for package: 1:net-snmp-5.7.2-37.el7.x86_64
–> Processing Dependency: libnetsnmpmibs.so.31()(64bit) for package: 1:net-snmp-5.7.2-37.el7.x86_64
–> Processing Dependency: libnetsnmpagent.so.31()(64bit) for package: 1:net-snmp-5.7.2-37.el7.x86_64
—> Package net-snmp-devel.x86_64 1:5.7.2-37.el7 will be installed
再安装PHP组件包,用于支持zabbix:
[root@zabbix ~]# yum install php-bcmath php-mbstring –y
开始安装:
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.cn99.com
* extras: mirrors.aliyun.com
* updates: mirrors.cn99.com
Resolving Dependencies
–> Running transaction check
—> Package php-bcmath.x86_64 0:5.4.16-46.el7 will be installed
—> Package php-mbstring.x86_64 0:5.4.16-46.el7 will be installed
–> Finished Dependency ResolutionDependencies Resolved
=====================================================================================================
Package Arch Version Repository Size
=====================================================================================================
Installing:
php-bcmath x86_64 5.4.16-46.el7 base 58 k
php-mbstring x86_64 5.4.16-46.el7 base 505 kTransaction Summary
=====================================================================================================
Install 2 Packages
完成后开始安装Zabbix,进入zabbix官网文档,选择产品手册->安装->从二进制包安装->1 Red Hat Enterprise,
[root@zabbix ~]# rpm -ivh http://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm
Retrieving http://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm
warning: /var/tmp/rpm-tmp.KHhpIz: Header V4 RSA/SHA512 Signature, key ID a14fe591: NOKEY
Preparing… ################################# [100%]
Updating / installing…
1:zabbix-release-4.0-1.el7 ################################# [100%]
[root@zabbix ~]#
zabbix共有3个核心组件,server、proxy及web,本次只安装基于mysql数据库的server和web:
[root@zabbix ~]# yum install zabbix-server-mysql zabbix-web-mysql -y
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.cn99.com
* extras: mirrors.aliyun.com
* updates: mirrors.cn99.com
zabbix | 2.9 kB 00:00:00
zabbix-non-supported | 951 B 00:00:00
zabbix/x86_64/primary_db | 26 kB 00:00:01
zabbix-non-supported/x86_64/primary | 1.6 kB 00:00:00
zabbix-non-supported 4/4
Resolving Dependencies
–> Running transaction check
—> Package zabbix-server-mysql.x86_64 0:4.0.2-1.el7 will be installed
–> Processing Dependency: fping for package: zabbix-server-mysql-4.0.2-1.el7.x86_64
–> Processing Dependency: libiksemel.so.3()(64bit) for package: zabbix-server-mysql-4.0.2-1.el7.x86_64
–> Processing Dependency: libOpenIPMIposix.so.0()(64bit) for package: zabbix-server-mysql-4.0.2-1.el7.x86_64
–> Processing Dependency: libOpenIPMI.so.0()(64bit) for package: zabbix-server-mysql-4.0.2-1.el7.x86_64
—> Package zabbix-web-mysql.noarch 0:4.0.2-1.el7 will be installed
8、导入数据并配置zabbix数据库
完成zabbix的安装后,之前在mariadb中创建的zabbix数据库中是没有数据的,需要将zabbix提供的模板表结构等数据导入zabbix数据库中,进行如下操作:
[root@zabbix ~]# zcat /usr/share/doc/zabbix-server-mysql-4.0.2/create.sql.gz | mysql -uzabbix -p -h 192.168.10.208 zabbix
Enter password:
[root@zabbix ~]#
输入之前zabbix用户的用户名,这里为zabbix123,输入后自动开始导入,等待10秒左右,未出现错误,则表示导入成功。
完成后开始配置zabbix server的配置文件,使配置文件中引用刚才创建的数据库,编辑/etc/zabbix/zabbix_server.conf文件:
[root@zabbix ~]# vi /etc/zabbix/zabbix_server.conf
主要设置以下几项:
DBHost=zabbix DBName=zabbix DBUser=zabbix DBPassword=zabbix123
9、修改zabbix配置文件时区及PHP参数设置
由于时间的重要性,需要将zabbix的时区也改成本地时区:
[root@zabbix ~]# vi /etc/httpd/conf.d/zabbix.conf
将php_value date.timezone 开关的#号去除,然后值修改为Asia/Shanghai,如下。
完成后保存退出即可。
10、启动zabbix服务并完成安装
以上操作完成后,可以启动zabbix server:
[root@zabbix ~]# 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@zabbix ~]#
[root@zabbix ~]# systemctl start zabbix-server
[root@zabbix ~]#
完成后重启服务器,然后进入/var/log/zabbix,查看zabbix_server.log日志文件,未发现相关错误:
5611:20181216:113337.714 Starting Zabbix Server. Zabbix 4.0.2 (revision 87228).
5611:20181216:113337.715 ****** Enabled features ******
5611:20181216:113337.715 SNMP monitoring: YES
5611:20181216:113337.716 IPMI monitoring: YES
5611:20181216:113337.716 Web monitoring: YES
5611:20181216:113337.716 VMware monitoring: YES
5611:20181216:113337.716 SMTP authentication: YES
5611:20181216:113337.716 Jabber notifications: YES
5611:20181216:113337.716 Ez Texting notifications: YES
5611:20181216:113337.716 ODBC: YES
5611:20181216:113337.716 SSH2 support: YES
5611:20181216:113337.716 IPv6 support: YES
5611:20181216:113337.716 TLS support: YES
5611:20181216:113337.716 ******************************
5611:20181216:113337.716 using configuration file: /etc/zabbix/zabbix_server.conf
5611:20181216:113337.783 [Z3001] connection to database ‘zabbix’ failed: [2003] Can’t connect to My
SQL server on ‘zabbix’ (99)
5611:20181216:113337.783 database is down: reconnecting in 10 seconds
5611:20181216:113347.926 database connection re-established
5611:20181216:113347.975 current database version (mandatory/optional): 04000000/04000003
5611:20181216:113347.975 required mandatory version: 04000000
5611:20181216:113348.294 server #0 started [main process]
9274:20181216:113348.295 server #1 started [configuration syncer #1]
9275:20181216:113348.297 server #2 started [alerter #1]
9276:20181216:113348.297 server #3 started [alerter #2]
9278:20181216:113348.301 server #5 started [housekeeper #1]
9282:20181216:113348.302 server #8 started [discoverer #1]
9285:20181216:113348.303 server #10 started [history syncer #2]
9286:20181216:113348.304 server #11 started [history syncer #3]
9283:20181216:113348.306 server #9 started [history syncer #1]
9291:20181216:113348.308 server #16 started [task manager #1]
9289:20181216:113348.311 server #14 started [proxy poller #1]
9277:20181216:113348.315 server #4 started [alerter #3]
9297:20181216:113348.316 server #22 started [unreachable poller #1]
9292:20181216:113348.319 server #17 started [poller #1]
9296:20181216:113348.322 server #21 started [poller #5]
9287:20181216:113348.323 server #12 started [history syncer #4]
9301:20181216:113348.324 server #25 started [trapper #3]
9298:20181216:113348.324 server #23 started [trapper #1]
9288:20181216:113348.326 server #13 started [escalator #1]
9303:20181216:113348.329 server #27 started [trapper #5]
9279:20181216:113348.330 server #6 started [timer #1]
9295:20181216:113348.331 server #20 started [poller #4]
9290:20181216:113348.332 server #15 started [self-monitoring #1]
9280:20181216:113348.333 server #7 started [http poller #1]
9293:20181216:113348.334 server #18 started [poller #2]
9307:20181216:113348.335 server #30 started [preprocessing manager #1]
9302:20181216:113348.336 server #26 started [trapper #4]
9308:20181216:113348.337 server #31 started [preprocessing worker #1]
9306:20181216:113348.337 server #29 started [alert manager #1]
9309:20181216:113348.337 server #32 started [preprocessing worker #2]
9294:20181216:113348.338 server #19 started [poller #3]
9300:20181216:113348.339 server #24 started [trapper #2]
9304:20181216:113348.344 server #28 started [icmp pinger #1]
9310:20181216:113348.433 server #33 started [preprocessing worker #3]
[root@zabbix zabbix]#
开始完成安装,浏览器打开http://192.168.10.208/zabbix,主界面已显示,点击Next Step:
填入相应信息,端口为3306,用户名及密码为之前创建的信息,如下图
输入host,这里为zabbix,端口默认,名称自定义
最后确认信息是否正常:
完成后,显示登陆界面,输入默认信息:用户名Admin,密码zabbix,进入主界面。
至此,zabbix的安装完成,后期将是相关配置的工作。
参考文章: