Zabbix监控搭建
1.安装nginx
关闭防火墙:
systemctl stop firewalld ##关闭防火墙
Systemctl disable firewalld #删除防火墙
setenforce 0 #关闭核心安全
新建nginx的yum仓库
vi /etc/yum.repos.d/nginx.repo
写入:
[nginx]
name=nginx
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1
清除yum缓存
yum clean all
生成缓存
yum makecache
yum安装nginx
yum install -y nginx
开启
systemctl start nginx
systemctl enable nginx #开机自启
2.安装mariadb
yum -y install mariadb-server mariadb
开启
systemctl start mariadb.service
systemctl enable mariadb.service
初始化:
mysql_secure_installation
然后按步骤:
Enter current password for root (enter for none): #回车
Set root password? [Y/n] #Y
New password: #123456
Re-enter new password: #123456
Remove anonymous users? #n
Disallow root login remotely? #n
Remove test database and access to it? #n
Reload privilege tables now? #Y
登录数据库:
mysql -u root -p123456
退出数据库
exit
3.安装PHP
yum -y install epel-release.noarch
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm #yum源的建立
yum install -y php72w php72w-devel php72w-fpm php72w-gd php72w-mbstring php72w-mysql #安装环境依赖包
php -v #查看版本
编辑配置文件:
vi /etc/php-fpm.d/www.conf
更改:
user = nginx #第8行
group = nginx #第10行
编辑nginx配置文件
vi /etc/nginx/conf.d/default.conf
更改:
index index.php index.html index.htm; #第10行添加index.php
location ~ \.php$ { #配置php模块,去掉注释
root /usr/share/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
修改php配置:
vi /etc/php.ini
更改:
short_open_tag = On #202行修改,支持php短标签
expose_php = Off #359行修改,隐藏php版本
##为PHP兼容zabbix进行修改,优化配置要求
max_execution_time = 300 #368行修改,执行时间
max_input_time = 300 #378行修改,接收数据等待时向
memory_limit = 128M #389行,每个脚本占用内存
post_max_size = 16M #656行修改,POST数据大小
upload_max_filesize = 2M #799行,下载文件大小
always_populate_raw_post_data = -1 #800行添加,可以用$HTTP_RAW_POST DATA
date.timezone = Asia/Shanghai #877行取消注释并添加时区
开启服务:
systemctl start php-fpm
systemctl enable php-fpm
重启nginx:
systemctl restart nginx
登入数据库删除用户名为空的主机:
mysql -uroot -p123456 #登录
select user,host from mysql.user; #查看用户
drop user ''@localhost; #删除空用户
drop user ''@zabbixnew;
select user,host from mysql.user; #再次查看用户
详见图片
4.安装zabbix
rpm -i https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm
yum -y install zabbix-server-mysql zabbix-web-mysql zabbix-agent
导入数据库脚本:
zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -padmin123 zabbix
修改zabbix配置文件
vi /etc/zabbix/zabbix_server.conf
修改:
LogFile=/var/log/zabbix/zabbix_server.log #38行
LogFileSize=0 #49行
PidFile=/var/run/zabbix/zabbix_server.pid #72行
SocketDir=/var/run/zabbix #82行
DBHost=localhost #91行,取消注释
DBName=zabbix #100行
DBUser=zabbix #116行
DBPassword=admin123 #124行,取消注释,zabbix数据库的密码
SNMPTrapperFile=/var/log/snmptrap/snmptrap.log #356行
Timeout=4 #473行
AlertScriptsPath=/usr/lib/zabbix/alertscripts #516行
ExternalScripts=/usr/lib/zabbix/externalscripts #527行
LogSlowQueries=3000
以及:
vi /etc/httpd/conf.d/zabbix.conf
php_value date.timezone Asia/Shanghai #20行,修改时区
授权:
cp -r /usr/share/zabbix/ /usr/share/nginx/html/
chown -R zabbix:zabbix /etc/zabbix/
chown -R zabbix:zabbix /usr/share/nginx/
chown -R zabbix:zabbix /usr/lib/zabbix/
chmod -R 755 /etc/zabbix/web/
chmod -R 777 /var/lib/php/session/
开启服务:
systemctl start zabbix-server
systemctl enable zabbix-server
systemctl start zabbix-agent.service
systemctl enable zabbix-agent.service
netstat -ntap | grep 10051
systemctl restart php-fpm.service
systemctl restart nginx
配置文件加权限:
chmod +x zabbix.conf.php
账号Admin
密码zabbix