1.准备工作
Zabbix需要LAMP环境来支持,请自行安装支持环境,或参考本文(建议采用yum方式安装,简单省事,不易出错)。本文在多个环境下编写而成,如存在描述不严谨的地方(如配置文件位置等),请自行对照自己的系统环境。本文采用源码安装zabbix4.4安装前建议关闭防火墙和selinux。
临时关闭selinux:setenforce 0
永久关闭selinux:sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux
临时关闭防火墙:systemctl stop firewalld.service
永久关闭防火墙:systemctl disable firewalld.service
依赖软件版本:Mysql 5.7.28、httpd-2.4.41、php-7.2.24
如需要了解其他详细信息,请参考官方文档
https://www.zabbix.com/documentation/4.0/zh/manual/installation/install
2.安装LAMP环境
2.1安装apache
1).先确认系统是否有安装,以避免其他问题。卸载rpm -e --nodeps 包名
# rpm -qa | grep httpd # groupadd apache # useradd -s /sbin/nologin -g apache -M apache
2).安装依赖包
httpd安装的依赖包
# yum -y install pcre-devel # yum -y install openssl-devel # yum -y groupinstall "Development Tools"
arp-util安装的依赖包
# yum install expat-devel
3).编译安装apr-1.7.0
# wget http://mirrors.tuna.tsinghua.edu.cn/apache/apr/apr-1.7.0.tar.gz # tar zxvf apr-1.7.0.tar.gz # cd apr-1.7.0 # ./configure -prefix=/usr/local/apr # make && make install
4).编译安装apr-util-1.6.1
# wget http://mirrors.tuna.tsinghua.edu.cn/apache/apr/apr-util-1.6.1.tar.gz # tar zxvf apr-util-1.6.1.tar.gz # cd apr-util-1.6.1 # ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/ # make && make install
5).编译安装httpd-2.4.41
# wget http://mirror.bit.edu.cn/apache/httpd/httpd-2.4.41.tar.gz # tar zxvf httpd-2.4.41.tar.gz # cd httpd-2.4.41 # ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-modeles=most --enable-mpms-shared=all --with-mpm=event # make && make install
6).添加httpd服务开启启动
# ln -s /usr/local/apache/bin/apachectl /etc/rc.d/init.d/httpd
# vim /etc/rc.d/init.d/httpd
在#/bin/sh 下加上两行
# chkconfig: 2345 95 10
# description: Activates/Deactivates Apache Web Server
注意:源码编译apache,运行用户为deamon,修改配置文件改变apache运行身份,修改httpd.conf文件添加以下两行。
# User apache # vim /etc/httpd/httpd.conf
Group apache
useradd -U apache
添加服务并设置开机自启
# chkconfig --add httpd # systemctl enable httpd | chkconfig httpd on |systemctl start httpd
2.2.安装mysql
1).先确认系统是否有安装,以避免其他问题。
# rpm -qa | grep mysql # rpm -qa | grep mariadb
注意:本文档安装的是mysql5.7.28,所以卸载了查询到的所有包,以避免异常。
2).安装相关支持包:
因为7系默认使用mariadb代替mysql,所以需要去mysql官网下载相应的rpm安装包,下载地址:https://dev.mysql.com/downloads/mysql/
安装以下6个包就行:
mysql-community-client-5.7.28-1.el7.x86_64、mysql-community-common-5.7.28-1.el7.x86_64、mysql-community-devel-5.7.28-1.el7.x86_64、mysql-community-libs-5.7.28-1.el7.x86_64、mysql-community-libs-compat-5.7.28-1.el7.x86_64、mysql-community-server-5.7.28-1.el7.x86_64
3).配置数据库:
执行以下命令更改root密码并创建zabbix用户和数据库
# systemctl restart mysqld # echo 'skip-grant-tables' >>/etc/my.cnf
或使用mysql初始化默认密码:
# awk '{if($0~"A temporary password") print}' /var/log/mysqld.log | awk '{print $11}'登录后再修改密码
# mysql -uroot mysql <<EOF ALTER USER 'root'@'localhost' IDENTIFIED BY '********'; ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER; SET character_set_client = utf8; SET character_set_connection = utf8; SET character_set_database = utf8 ; SET character_set_results = utf8 ; SET character_set_server = utf8 ; FLUSH PRIVILEGES; EOF
# mysql -uroot mysql <<EOF
UPDATE user SET authentication_string=PASSWORD('********') where USER='root';
create user zabbix identified by '********';
grant all privileges on zabbix.* to zabbix identified by '********';
create database zabbix character set utf8 collate utf8_general_ci;
FLUSH PRIVILEGES;
EOF# echo 'character_set_server=utf8' >> /etc/my.cnf # echo "init_connect='SET NAMES utf8'" >> /etc/my.cnf # echo 'skip-name-resolve' >> /etc/my.cnf # echo 'max_connections=1000' >> /etc/my.cnf # echo '[mysql]' >> /etc/my.cnf # echo 'default-character-set=utf8' >> /etc/my.cnf # sed -i '/^skip-grant-tables/s/.*/#skip-grant-tables/' /etc/my.cnf # systemctl restart mysqld
如需开启root用户远程连接,请执行如下命令:
# mysql -uroot -p******** mysql -s -e "update user set host = '%' where user = 'root';" # mysql -uroot -p******** mysql -s -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '********' WITH GRANT OPTION;" # mysql -uroot -p******** mysql -s -e "flush privileges;"
4).启动服务并设置开机自启
# systemctl start mysqld # systemctl enable mysqld
5).查看下服务状态是否正常
# systemctl status mysqld
2.3.安装php
1).先确认系统是否有安装,以避免其他问题。
# rpm -qa | grep php # groupadd www # useradd -s /sbin/nologin -g www -M www
# tar zxvf php-7.2.24.tar.gz # cd php-7.2.24 # ./configure --prefix=/usr/local/php7 --with-mysqli --with-pdo-mysql --with-config-file-path=/usr/local/php7/etc --with-iconv-dir=/usr/local/libiconv --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-gettext --with-libxml-dir --enable-simplexml --enable-fileinfo --enable-xml --disable-rpath --enable-bcmath --enable-soap --enable-zip --with-curl --with-fpm-user=www --with-fpm-group=www --enable-mbstring --enable-sockets --with-gd --with-openssl=/usr/local/ssl --with-mhash --enable-opcache --with-apxs2=/usr/local/apache/bin/apxs # make && make install
-----------------------------------------------------------
--enable-fpm or --with-apxs2=/usr/local/apache/bin/apxs
nginx or apache
-----------------------------------------------------------
启动后如提示没有配置文件,php fpm初始化失败,需要添加配置文件,把cp php-fpm.conf.default重命名php-fpm.conf和www.conf.default重命名www.conf
安装好后需要在php源码把目录把php.ini-production和php.ini-development复制到php的etc目录中,并把php.ini-production重命名为php.ini
php.ini文件位置可以查询phpinfo函数来确定。
启动服务并设置开机自启
# systemctl enable php-fpm # systemctl start php-fpm # systemctl status php-fpm
验证环境
浏览器访问ip:端口可以正常显示页面
3.安装zabbix_server端
3.1编译zabbix并安装
# tar -zxvf zabbix-4.4.0.tar.gz # cd zabbix-4.4.0 # ./configure --prefix=/opt/zabbix-4.0/ --enable-server --enable-agent --with-mysql=/usr/bin/mysql_config --with-net-snmp --with-libcurl --with-libxml2l # make && make install
3.2导入server端需要的表
# cd database/mysql/ # ls # data.sql images.sql Makefile Makefile.am Makefile.in schema.sql # mysql -uzabbix -p'********' zabbix < schema.sql # mysql -uzabbix -p'********' zabbix < images.sql # mysql -uzabbix -p'********' zabbix < data.sql
3.3创建zabbix用户和组
# groupadd zabbix # useradd -g zabbix zabbix # chown -R zabbix. /opt/zabbix*
3.4修改zabbix-server配置
配置数据库密码选项,其他可以保持默认或按需求修改
# vim +118 /opt/zabbix-4.0/etc/zabbix_server.conf
DBPassword=********
3.5启动zabbix
# cp misc/init.d/fedora/core5/zabbix_agentd /etc/init.d/ # sed -i '/^ZABBIX_BIN="\/usr\/local\/sbin\/zabbix_agentd"/s/.*/ZABBIX_BIN="\/opt\/zabbix-4.0\/sbin\/zabbix_agentd"/' /etc/init.d/zabbix_agentd # cp misc/init.d/fedora/core5/zabbix_server /etc/init.d/ # sed -i '/^ZABBIX_BIN="\/usr\/local\/sbin\/zabbix_server"/s/.*/ZABBIX_BIN="\/opt\/zabbix-4.0\/sbin\/zabbix_server"/' /etc/init.d/zabbix_server # chkconfig zabbix_agentd on # chkconfig zabbix_server on # systemctl enable zabbix_agentd.service # systemctl enable zabbix_server.service # systemctl restart zabbix_agentd.service # systemctl restart zabbix_server.service # systemctl status zabbix_agentd.service # systemctl status zabbix_server.service
3.6安装 Zabbix web 界面
复制 PHP 文件,Zabbix 前端是 PHP 编写的,所以必须运行在支持 PHP 的 Web 服务器上。只需要简单的从 frontends/php 路径下复制 PHP 文件到 Web 服务器的 HTML 文档目录,即可完成安装。
# mkdir /var/www/html/zabbix/ # cp -a ./frontends/php/ /var/www/html/zabbix # chown -R zabbix.zabbix /var/www/html/zabbix/
3.7前端安装
在您的浏览器打开 Zabbix 链接:http://<server_ip_or_name>/zabbix
您可以看到前端安装向导的第一个页面。

第二步,请确认满足所有的软件安装前置条件。

第三步,输入zabbix用户的数据库密码

第四步,请输入 Zabbix server 的详细信息。

第五步,查看设置的摘要。

第六步,下载配置文件并将其放在 conf/ 路径下,即在您复制 Zabbix PHP 文件的 Web 服务器 HTML 文档子目录中。

第七步,完成安装。

3.8验证测试
http://<server_ip_or_name>/zabbix/php
Zabbix 前端已经就绪!默认的用户名是 admin,密码是zabbix

3.9.其他事项
可修改apache配置文件访问ip:端口即可默认打开zabbix
# vim +119 /etc/httpd/conf/httpd.conf
DocumentRoot "/var/www/html/zabbix/php"
# vim +17 /etc/httpd/conf.d/php.conf
DirectoryIndex index.php zabbix.php
4.安装zabbix_agent端
4.1.编译安装
# yum -y install gcc-c++ net-snmp-devel libevent-devel libcurl-devel # ./configure --prefix=/opt/zabbix-agent/ --enable-agent --with-net-snmp --with-libcurl --with-libxml2l # make && make install
4.2.修改配置
# sed -i '/^Server=127.0.0.1/s/.*/Server=192.168.1.1/' /opt/zabbix-agent/etc/zabbix_agentd.conf
# sed -i '/^ServerActive=127.0.0.1/s/.*/Server=192.168.1.1/' /opt/zabbix-agent/etc/zabbix_agentd.conf
# sed -i "/^Hostname=Zabbix server/s/.*/Hostname=$(ip addr |awk '{if($0~"192.168.1") print}'|awk '{print $2}'|awk -F '/' '{print $1}')/" /opt/zabbix-agent/etc/zabbix_agentd.conf查看配置信息:
# egrep -v '(^#|^$)' /opt/zabbix-agent/etc/zabbix_agentd.conf
4.3.配置用户
# groupadd zabbix # useradd -g zabbix zabbix # chown -R zabbix:zabbix /opt/zabbix-agent/
4.4.启动agent
# cp misc/init.d/fedora/core5/zabbix_agentd /etc/init.d/ # sed -i '/^ZABBIX_BIN="\/usr\/local\/sbin\/zabbix_agentd"/s/.*/ZABBIX_BIN="\/opt\/zabbix-agent\/sbin\/zabbix_agentd"/' /etc/init.d/zabbix_agentd # chkconfig zabbix_agentd on # systemctl enable zabbix_agentd.service # systemctl restart zabbix_agentd.service # systemctl status zabbix_agentd.service

发表评论