CentOS 7.9基于LAMP环境安装部署zabbix5.0

举报
灰烬 发表于 2021/07/01 16:17:02 2021/07/01
【摘要】 zabbix是一个企业级解决方案,支持实时监控数千台服务器,虚拟机和网络设备,采集百万级监控指标,适用于任何IT基础架构、服务、应用程序和资源的解决方案。 目前使用较多的开源监控软件,可横向扩展、自定义监控项、支持多种监控方式。
一、准备工作
    ① 安装基础软件
# yum install -y centos-release-scl net-snmp-devel curl curl-devel
    ② 安装部署LAMP运行环境
        a. 安装Apache
# yum install -y httpd httpd-devel
# systemctl start httpd
        b. 安装Mysql8.0
        创建mysql.repo
# cd /etc/yum.repos.d/ 
# vim mysql.repo 
#############
# Enable to use MySQL 8.0 
[mysql80-community] 
name=MySQL 8.0 Community Server 
baseurl=http://repo.mysql.com/yum/mysql-8.0-community/el/7/$basearch/ 
enabled=1 
gpgcheck=0 
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql 
#############
:x ##保存退出
        安装|启动|设置开机自启动
# yum list mysql 
# yum repolist all | grep mysql [
# yum repolist enabled |grep mysql 
# yum install -y mysql-community-* 
# mysql -V 
# systemctl start mysqld 
# systemctl enable mysqld 
# grep 'temporary password' /var/log/mysqld.log ##查看初始密码
# mysql_secure_installation 
# mysql -uroot -p
        c. 安装PHP7.2
        创建repo源
# cd /etc/yum.repos.d/ 
# wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm 
## wget https://rpms.remirepo.net/enterprise/remi-release-7.rpm ##这个可以不装
# rpm -ivh epel-release-latest-7.noarch.rpm 
# vim remi.repo 
############
[remi]
name=Remi's RPM repository for Enterprise Linux 7 - $basearch
mirrorlist=http://rpms.remirepo.net/enterprise/7/remi/mirror
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi
[remi-php]
name=Remi's PHP 7.2 RPM repository for Enterprise Linux 7 - $basearch
mirrorlist=http://rpms.remirepo.net/enterprise/7/php72/mirror
# WARNING: If you enable this repository, you must also enable "remi"
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi
############
:x ##保存退出
# yum clean all
# yum makecache
        安装|启动|设置开机自启动
# yum install -y php php-bcmath php-cli php-common php-devel php-embedded php-fpm php-gd php-imap php-json php-ldap php-mbstring php-opcache php-pdo php-pear php-snmp php-soap php-tidy php-xml php-mysqlnd
# systemctl start php-fpm
# systemctl enable php-fpm
# netstat -nutlp
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 3383/php-fpm: maste
        d. 安装jdk8
# rz ##上传已经下载好的jdk包
# rpm -ivh jdk-8u291-linux-x64.rpm
    ③ 配置
        a. Apache
#修改配置文件以支持php
# cd /etc/httpd/conf
# cp httpd.conf httpd.conf.old
# vim httpd.conf
##添加如下内容:
<IfModule dir_module>
DirectoryIndex index.html index.php
</IfModule>
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
#隐藏版本信息
ServerSignature Off
ServerTokens Prod
#配置虚拟站点
# cd ../conf.d/
# vim httpd-vhosts.conf 
<VirtualHost *:80>
DocumentRoot "/home/www/zabbix" ##存放目录
ServerName ******** ##域名
ErrorLog "/var/log/httpd/********-error_log"
CustomLog "/var/log/httpd/********-access_log" combined
<Directory "/home/www/zabbix">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
:x ##保存退出
# systemctl restart httpd
        b. Mysql
# cd /etc/
# cp my.cnf my.cnf.old
# vim my.cnf
#修改数据库存储位置
# datadir=/var/lib/mysql
datadir=/home/data ##数据库存放路径
#设置字符编码和端口
port=3306
character-set-server=utf8
init-connect='SET NAMES utf8'
collation-server=utf8_general_ci
#修改配置项
default-authentication-plugin=mysql_native_password
##如果出现禁止root用户本地登录,请加入如下内容以免密登录,然后授权root用户本地登录权限,刷新,然后注释掉改行内容
# skip-grant-tables
:x 保存退出
#systemctl restart mysqld
####
#授权命令
# mysql -uroot -p ##弹出输入密码,直接回车(skip-grant-tables已启用)
mysql> flush privileges;
mysql> alter user 'root'@'localhost' identified by 'password';
mysql> flush privileges;
mysql> exit
        c. PHP
# rpm -ql php-fpm
/etc/logrotate.d/php-fpm
/etc/php-fpm.conf
/etc/php-fpm.d
/etc/php-fpm.d/www.conf
/etc/sysconfig/php-fpm
# cp /etc/php-fpm.conf /etc/php-fpm.conf.old
# cp /etc/php.ini /etc/php.ini.old
# vim /etc/php.ini
#############
#修改时区
date.timezone = Asia/Shanghai
#修改签名
; expose_php = On
expose_php = Off
#修改参数
post_max_size = 16M
max_execution_time = 300
max_input_time = 300
#############
# systemctl restart php-fpm
# systemctl restart httpd
二、编译安装zabbix5.0
    ① 下载、解压源码包
# wget https://cdn.zabbix.com/zabbix/sources/stable/5.4/zabbix-5.4.1.tar.gz
# tar -zxvf zabbix-5.4.1.tar.gz
    ② 创建用户组及用户
##此处参考zabbix文档操作##
# groupadd --system zabbix
# useradd --system -g zabbix -d /usr/lib/zabbix -s /sbin/nologin -c "Zabbix Monitoring System" zabbix
# mkdir -m u=rwx,g=rwx,o= -p /usr/lib/zabbix
# chown zabbix:zabbix /usr/lib/zabbix
    ③ 创建zabbix数据库
# mysql -uroot -p
Enter password: 
mysql> create database zabbix character set utf8 collate utf8_bin;
Query OK, 1 row affected, 2 warnings (0.00 sec)
mysql> create user zabbix@localhost identified by 'password';
Query OK, 0 rows affected (0.00 sec)
mysql> grant all privileges on *.* to 'zabbix'@'localhost' with grant option;
Query OK, 0 rows affected (0.00 sec)
mysql> grant all privileges on zabbix.* to 'zabbix'@'localhost';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> exit
Bye
##开始下一步前,请测试一下新创建的用户能否登录,如果提示禁止登录本地,则按照如下操作修改授权
# mysql -uroot -p
Enter password: 
mysql> use mysql
mysql> select user,host from user where user='zabbix';
mysql> update user set host='%' where user='zabbix';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> exit
Bye
    ④ 导入数据
# cd zabbix-5.4.1
# cd database/mysql/
# mysql -uroot -p zabbix < schema.sql
Enter password:
# mysql -uroot -p zabbix < images.sql
Enter password: 
# mysql -uroot -p zabbix < data.sql
Enter password:
    ⑤ 编译安装
# cd
# cd zabbix-5.4.1
# ./configure --enable-server --enable-agent --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2 --enable-java
# make install
    ⑥ 编辑zabbix_server配置文件
# cd /usr/local/etc/
# cp zabbix_server.conf zabbix_server.conf.old
# vim zabbix_server.conf
##############
DBHost=localhost(或者服务器IP地址)
DBName=zabbix
DBUser=zabbix
DBPassword=数据库连接密码
DBPort=3306
##############
:x 保存退出
    ⑦ 启动zabbix_server服务
# /usr/local/sbin/zabbix_server -c /usr/local/etc/zabbix_server.conf
# tail /tmp/zabbix_server.log
2356:20210626:180924.955 server #41 started [history poller #4]
2345:20210626:180924.956 server #30 started [preprocessing manager #1]
2347:20210626:180924.956 server #32 started [preprocessing worker #2]
2350:20210626:180924.957 server #35 started [lld worker #1]
2352:20210626:180924.957 server #37 started [alert syncer #1]
2354:20210626:180924.957 server #39 started [history poller #2]
2348:20210626:180924.958 server #33 started [preprocessing worker #3]
2343:20210626:180924.965 server #28 started [alerter #2]
2346:20210626:180925.054 server #31 started [preprocessing worker #1]
2321:20210626:180926.940 Zabbix agent item "system.localtime" on host "Zabbix server" failed: first network error, wait for 15 seconds
    ⑧ 拷贝web界面
# cd zabbix-5.4.1/ui/
# cp -a . /home/www/zabbix/
三、配置web界面

01.png

02.png

03.png

04.png

05.png

06.png

解决方案:(下载zabbix.conf.php文件到本地,上传到/home/www/zabbix/conf下,然后在浏览器刷新一下页面)
# cd /home/www/zabbix/conf
# rz #上传下载的zabbix.conf.php文件
# ls
certs maintenance.inc.php zabbix.conf.php zabbix.conf.php.example

07.png

08.png

账号:Admin 密码:zabbix

09.png

启动zabbix_agent服务
# /usr/local/sbin/zabbix_agentd
【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。