Zabbix4.0环境搭建

Zabbix4.0环境部署

  • LAMP环境部署
  • 安装Zabbix依赖
  • 安装Zabbix环境
  • 修改Zabbix默认配置
  • Zabbix网页监控

Zabbix4.0环境搭建

实验环境

Zabbix_Server

[root@Zabbix_Server_56 ~]# cat /etc/redhat-release 
CentOS Linux release 7.5.1804 (Core) 
[root@Zabbix_Server_56 ~]# uname -r
3.10.0-862.el7.x86_64
[root@Zabbix_Server_56 ~]# hostname
Zabbix_Server_56.7
[root@Zabbix_Server_56 ~]# ip a | grep 192.168.
    inet 192.168.56.7/24 brd 192.168.56.255 scope global noprefixroute dynamic eth0

LAMP环境部署

注意:Zabbix是建立在LAMP或者LNMP环境之上,在此为了方便就使用yum安装LAMP环境,Zabbix3.0以上对php的版本要求在5.4以上

[root@Zabbix_Server_56 ~]# yum -y install httpd httpd-devel mariadb mariadb-server mariadb-devel php php-mysql php-common php-gd php-mbstring php-mcrypt php-devel php-xml php-bcmath php-ldap*

查看应用版本信息

[root@Zabbix_Server_56 ~]# rpm -qa httpd php mariadb            #安装完成后检查应用版本
mariadb-5.5.60-1.el7_5.x86_64
php-5.4.16-45.el7.x86_64                                        #如php版本不是5.4以上,应升级版本
httpd-2.4.6-80.el7.centos.1.x86_64

启动并加入开机自启

[root@Zabbix_Server_56 ~]# systemctl start httpd
[root@Zabbix_Server_56 ~]# systemctl enable httpd
[root@Zabbix_Server_56 ~]# systemctl start mariadb
[root@Zabbix_Server_56 ~]# systemctl enable mariadb
[root@Zabbix_Server_56 ~]# ss -anplt | grep httpd
LISTEN     0      128         :::80                      :::*                   users:(("httpd",pid=1551,fd=4),("httpd",pid=1550,fd=4),("httpd",pid=1549,fd=4),("httpd",pid=1548,fd=4),("httpd",pid=1547,fd=4),("httpd",pid=1545,fd=4))
[root@Zabbix_Server_56 ~]# ss -naplt | grep mysql
LISTEN     0      50           *:3306                     *:*                   users:(("mysqld",pid=1816,fd=13))

网页测试LAMP环境

[root@Zabbix_Server_56 ~]# vim /var/www/html/index.php
<?php
phpinfo()
?>
[root@Zabbix_Server_56 ~]# systemctl stop iptables
[root@Zabbix_Server_56 ~]# systemctl stop firewalld
[root@Zabbix_Server_56 ~]# setenforce 0
[root@Zabbix_Server_56 ~]# curl http://127.0.0.1 -I         #本地测试
HTTP/1.1 200 OK
Date: Mon, 15 Oct 2018 09:50:07 GMT
Server: Apache/2.4.6 (CentOS) PHP/5.4.16
X-Powered-By: PHP/5.4.16
Content-Type: text/html; charset=UTF-8

安装Zabbix依赖

创建Zabbix用户组

[root@Zabbix_Server_56 ~]# useradd -s /sbin/nologin zabbix  -g zabbix

创建Zabbix数据库以及创建数据库账户和授权

[root@Zabbix_Server_56 ~]# mysqladmin -u root password 123456           #设置数据库root密码
[root@Zabbix_Server_56 ~]# mysql -u root -p
Enter password: 
MariaDB [(none)]> create database zabbix character set utf8 collate utf8_bin;       #创建名为zabbix的数据库
Query OK, 1 row affected (0.01 sec)

MariaDB [(none)]> GRANT ALL PRIVILEGES ON zabbix.* TO 'zabbix'@'localhost' IDENTIFIED BY '3edc#EDC'; #把名为zabbix的数据库授权给zabbix数据库用户,密码为3edc#EDC,只能在本地登录
Query OK, 0 rows affected (0.00 sec)

数据库加固

[root@Zabbix_Server_56 ~]# 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):   #输入root密码
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

You already have a root password set, so you can safely answer 'n'.

Change the root password? [Y/n] n                   #是否更改root密码
 ... skipping.

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] y               是否禁止root从远程登录
 ... Success!

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] y      #是否删除test测试数据库并取消对它的访问权限
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

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!

安装zabbix依赖包

[root@Zabbix_Server_56 ~]# 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*

部署JAVA环境

注意:Zabbix监控tomcat需要通过JMX方式监控,JMX监控方式依赖JAVA环境,在此安装JDK1.8,以下是JDK下载页面,下载完成上传到服务器
https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
[root@Zabbix_Server_56 src]# tar xf jdk-8u161-linux-x64.tar.gz  
[root@Zabbix_Server_56 src]# mv jdk1.8.0_161 /usr/local/java 
[root@Zabbix_Server_56 src]# vim /etc/profile                   #在profile文件最后添加java的环境变量
#################JAVA#################
export JAVA_HOME=/usr/local/java
export JRE_HOME=/usr/local/java/jre
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH
[root@Zabbix_Server_56 src]# source /etc/profile
[root@Zabbix_Server_56 src]# java -version                      #查看java版本信息
java version "1.8.0_161"
Java(TM) SE Runtime Environment (build 1.8.0_161-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.161-b12, mixed mode)

安装Zabbix环境

下载Zabbix4.0

wget https://sourceforge.net/projects/zabbix/files/ZABBIX%20Latest%20Stable/4.0.0/zabbix-4.0.0.tar.gz

解压并导入SQl

[root@Zabbix_Server_56 src]# tar xf zabbix-4.0.0.tar.gz 
[root@Zabbix_Server_56 src]# cd zabbix-4.0.0/database/mysql/
[root@Zabbix_Server_56 mysql]# ls
data.sql  images.sql  Makefile.am  Makefile.in  schema.sql
注意:数据库导入顺序不能修改,#把以下sql导入zabbix数据库,用户名为zabbix,密码为3edc#EDC
[root@Zabbix_Server_56 mysql]# mysql -u zabbix -p3edc#EDC zabbix < schema.sql   
[root@Zabbix_Server_56 mysql]# mysql -u zabbix -p3edc#EDC zabbix < images.sql 
[root@Zabbix_Server_56 mysql]# mysql -u zabbix -p3edc#EDC zabbix < data.sql

编译安装

[root@Zabbix_Server_56 mysql]# cd /usr/local/src/zabbix-4.0.0
[root@Zabbix_Server_56 zabbix-4.0.0]# ./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --with-mysql --enable-java --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2 --enable-mbstring
[root@Zabbix_Server_56 zabbix-4.0.0]# make && make install

拷贝zabbix启动文件

[root@Zabbix_Server_56 zabbix-4.0.0]# cp -rf /usr/local/src/zabbix-4.0.0/misc/init.d/tru64/zabbix_* /etc/init.d/
[root@Zabbix_Server_56 zabbix-4.0.0]# chmod +x /etc/init.d/zabbix_*
[root@Zabbix_Server_56 zabbix-4.0.0]# vim /etc/init.d/zabbix_server
在第二行和第三行添加以下字段以支持开机自启
  2 #chkconfig:35 95 96
  3 #description:Zabbix_Server
 25 DAEMON=/usr/local/zabbix/sbin/zabbix_server                 #25行原路径为/usr/local/sbin/zabbix_server修改为/usr/local/zabbix/sbin/zabbix_server
[root@Zabbix_Server_56 zabbix-4.0.0]# vim /etc/init.d/zabbix_agentd 
  2 #chkconfig:35 95 96
  3 #description:Zabbix_Agentd
 25 DAEMON=/usr/local/zabbix/sbin/zabbix_agentd

修改Zabbix默认配置

修改Zabbix Server主配置文件

[root@Zabbix_Server_56 /]# cd /usr/local/zabbix/etc/
[root@Zabbix_Server_56 etc]# grep -Ev "#|^$" zabbix_server.conf
LogFile=/tmp/zabbix_server.log                                  #日志文件路径
DBHost=localhost                                                #连接数据库的地址
DBName=zabbix                                                   #连接的数据库
DBUser=zabbix                                                   #连接数据库的用户
DBPassword=3edc#EDC                                             #连接数据库的密码
StartPollers=5                                                  #Zabbix进程数,这里为实验环境,所以进程数都较小
StartPollersUnreachable=1                                       #检查unreachable host(包括IPMI)的进程数
StartTrappers=5                                                 #Trappers(zabbix采集器)进程数,Trappers用于接收其它host用zabbix_sender、active_agents发送的数据,至少需要一个Trapper进程用来在前端显示Zabbix Server可用性
StartPingers=5                                                  #用于ICMP ping的进程数
StartDiscoverers=1                                              #用于自动发现(Discovery)的discovery的进程数
StartHTTPPollers=1                                              #用于HTTP检查的进程数
CacheSize=1G                                                    #存储Host、Item和Trgger数据的内存空间
HistoryCacheSize=256M                                           #存储History数据的内存大小
HistoryIndexCacheSize=256M                                      #存储历史索引缓存共享内存的大小
Timeout=10                                                      #超时时间
AlertScriptsPath=/usr/local/zabbix/etc/alertscripts             #脚本目录,例如:短信告警脚本SMS,邮件告警脚本mail,微信告警脚步Wechat
FpingLocation=/usr/sbin/fping                                   #Fping路径
LogSlowQueries=3000                                             
AllowRoot=1                                                     #值为1就允许root启动,为0则不允许
User=zabbix                                                     #zabbix进程启动用户
Include=/usr/local/zabbix/etc/zabbix_server.conf.d/*.conf       #链接文件
[root@Zabbix_Server_56 etc]# mkdir /usr/local/zabbix/etc//alertscripts      #默认是没有该文件,需创建
[root@Zabbix_Server_56 etc]# yum install fping -y               

修改Zabbix Agentd配置文件

[root@Zabbix_Server_56 etc]# grep -Ev "#|^$" zabbix_agentd.conf 
LogFile=/tmp/zabbix_agentd.log                                  #日志路径
Server=192.168.56.7                                             #被动模式,由server来拉取数据
ServerActive=192.168.56.7                                       #主动模式,主动提交数据给Server
Hostname=192.168.56.7                                           #主机名称
Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/*.conf       #链接文件

修改php配置文件

注意:php.ini默认的值和zabbix网页界面不匹配
sed -i 's/post_max_size = 8M/post_max_size = 16M/g' /etc/php.ini
sed -i 's/upload_max_filesize = 2M/upload_max_filesize = 50M/g' /etc/php.ini
sed -i 's/;date.timezone =/date.timezone =PRC/' /etc/php.ini
sed -i 's/max_execution_time = 30/max_execution_time = 300/g' /etc/php.ini
sed -i 's/max_input_time = 60/max_input_time = 300/g' /etc/php.ini
sed -i 's/memory_limit = 128M/memory_limit = 256M/g' /etc/php.ini

拷贝zabbix web网页到httpd网页目录下并做修改

[root@Zabbix_Server_56 etc]# mkdir /var/www/html/zabbix                 #创建zabbix网页路径
[root@Zabbix_Server_56 etc]# cp -rf /usr/local/src/zabbix-4.0.0/frontends/php/* /var/www/html/zabbix
[root@Zabbix_Server_56 /]# cd /var/www/html/zabbix/conf
[root@Zabbix_Server_56 conf]# ls
maintenance.inc.php  zabbix.conf.php.example
[root@Zabbix_Server_56 conf]# cp -rf zabbix.conf.php.example zabbix.conf.php
[root@Zabbix_Server_56 conf]# cat zabbix.conf.php
<?php
// Zabbix GUI configuration file.
global $DB, $HISTORY;

$DB['TYPE']             = 'MYSQL';
$DB['SERVER']           = 'localhost';
$DB['PORT']             = '0';
$DB['DATABASE']         = 'zabbix';
$DB['USER']             = 'zabbix';
$DB['PASSWORD']         = '3edc#EDC';                                   #这个地方需要修改为zabbix数据库的账号密码
// Schema name. Used for IBM DB2 and PostgreSQL.
$DB['SCHEMA']           = '';

$ZBX_SERVER             = 'localhost';
$ZBX_SERVER_PORT        = '10051';
$ZBX_SERVER_NAME        = '';

$IMAGE_FORMAT_DEFAULT   = IMAGE_FORMAT_PNG;

// Uncomment this block only if you are using Elasticsearch.
// Elasticsearch url (can be string if same url is used for all types).
//$HISTORY['url']   = [
//      'uint' => 'http://localhost:9200',
//      'text' => 'http://localhost:9200'
//];
// Value types stored in Elasticsearch.
//$HISTORY['types'] = ['uint', 'text'];

启动Zabbix,测试访问

创建软连接
[root@Zabbix_Server_56 conf]# mkdir /usr/local/etc
[root@Zabbix_Server_56 conf]# ln -s /usr/local/zabbix/etc/zabbix_server.conf /usr/local/etc/
[root@Zabbix_Server_56 conf]# ln -s /usr/local/zabbix/etc/zabbix_agentd.conf /usr/local/etc/

启动Zabbix并加入开机自启
[root@Zabbix_Server_56 conf]# /etc/init.d/zabbix_server start
Zabbix server started.
[root@Zabbix_Server_56 conf]# /etc/init.d/zabbix_agentd start
Zabbix agent started.
[root@Zabbix_Server_56 conf]# chkconfig zabbix_server on
[root@Zabbix_Server_56 conf]# chkconfig zabbix_agentd on

重启httpd
[root@Zabbix_Server_56 conf]# systemctl restart httpd

Zabbix4.0环境搭建
Zabbix4.0环境搭建
Zabbix4.0环境搭建

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章