设为首页 收藏本站
查看: 1096|回复: 0

[经验分享] Zabbix4.0环境搭建

[复制链接]

尚未签到

发表于 2019-1-17 14:03:26 | 显示全部楼层 |阅读模式
  Zabbix4.0环境部署


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


实验环境

  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

[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

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-664483-1-1.html 上篇帖子: zabbix安装报错 下篇帖子: Zabbix微信个人账号告警
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表