zabbix是一个基于web界面提供分布式系统键是以及网络监视功能的企业级开源解决方案。
由2部分构成:
分别是zabbix server与zabbix agent
zabbix server可以通过SNMP,zabbix agent,ping,端口监视等方法提供对远程服务器/网络状态的监视,数据收集等功能,它可以运行在Linux,Solaris,HP-UX,AIX,Free BSD,Open BSD,OS X等平台上。
安装与配置简单,学习成本低,支持多语言(包括中文),自动发现服务器与网络设备,分布式监视以及WEB集中管理功能,可以无agent监视等
1、CPU负荷
2、内存使用
3、磁盘使用
4、网络状况
5、端口监视
6、日志监视
清空防火墙规则,关闭核心防护
iptables -F
setenforce 0
关闭网络管理
systemctl stop NetworkManager
systemctl disable NetworkManager
systemctl stop firewalld
创建nginx的yum仓库
vim /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1
进入yum.repos.d目录安装并启动
yum list
yum -y install nginx
systemctl start nginx
systemctl enable nginx
netstat -natp | grep 80
yum -y install mariadb-server mariadb
systemctl start mariadb.service
systemctl enable mariadb.service
netstat -natp | grep 3306
初始化
mysql_secure_installation
Enter current password for root (enter for none): #回车
Set root password? [Y/n] #y
New password: #123123
Re-enter new password: #123123
Remove anonymous users? #n
Disallow root login remotely? #n
Remove test database and access to it? #n
Reload privilege tables now? #y
安装PHP
yum -y install epel-release #安装PHP
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 #查看版本
修改php-fpm配置文件,把apache改为nginx
vim /etc/php-fpm.d/www.conf
user = nginx #第8行将apache改为nginx
group = nginx #第10行将apache改为nginx
修改nginx配置文件支持PHP并修改php配置文件
vim /etc/nginx/conf.d/default.conf
index index.php index.html index.htm; 第10行添加index.php
配置php模块,去掉注释
location ~ \.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;
}
vim /etc/php.ini
expose_php = Off #359行:隐藏php版本
short_open_tag = On #202行:支持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
netstat -natp | grep 9000
systemctl restart nginx
vim /usr/share/nginx/html/test.php
<?php
phpinfo();
?>
vim /usr/share/nginx/html/test.php
<?php
$link=mysqli_connect('127.0.0.1','root' ,'123123' );
if ($link) echo "连接成功";
else echo "连接失败";
?>
mysql -u root -p123123
CREATE DATABASE zabbix character set utf8 collate utf8_bin;
GRANT all privileges ON *.* TO 'zabbix'@'%' IDENTIFIED BY 'admin123';
flush privileges;
测试连接zabbix数据库
vim /usr/share/nginx/html/test.php
<?php
$link=mysqli_connect('127.0.0.1','zabbix' ,'admin123' );
if ($link) echo "连接zabbix数据库成功";
else echo "连接zabbix数据库失败";
?>
mysql -u root -p123123
select user,host from mysql.user;
drop user ''@localhost;
drop user ''@localhost.localdomain;
下载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
mysql -u zabbix -padmin123
use zabbix;
show tables;
修改zabbix配置文件
vim /etc/zabbix/zabbix_server.conf
38 LogFile=/var/log/zabbix/zabbix_server.log
49 LogFileSize=0
72 PidFile=/var/run/zabbix/zabbix_server.pid
82 SocketDir=/var/run/zabbix
91 DBHost=localhost #注释去掉,数据库存放地址,目前是本地
100 DBName=zabbix
116 DBUser=zabbix
124 DBPassword=admin123 #注释去掉,zabbix的密码
356 SNMPTrapperFile=/var/log/snmptrap/snmptrap.log
474 Timeout=4
517 AlertScriptsPath=/usr/lib/zabbix/alertscripts
528 ExternalScripts=/usr/lib/zabbix/externalscripts
564 LogSlowQueries=3000
授权
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
用谷歌浏览器 qq浏览器不行
网页访问 http://192.168.111.8/zabbix
关闭防火墙和核心防护
systemctl stop firewalld
setenforce 0
rpm -i https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm
yum install -y zabbix-agent
修改配置文件
vim /etc/zabbix/zabbix_agentd.conf
PidFile=/var/run/zabbix/zabbix_agentd.pid
LogFile=/var/log/zabbix/zabbix_agentd.log
LogFileSize=0
Server=192.168.241.3 # 指向监控服务器
ServerActive=192.168.241.3 # 指问监控服务器
Hostname=test1 #指定名称
Include=/etc/zabbix/zabbix_agentd.d/*.conf
开启服务并检查端口
systemctl start zabbix-agent
systemctl enable zabbix-agent
netstat -natp | grep zabbix #查看10050端口
添加被监控的主机
进入浏览器 配置→主机→创建主机→填写主机名称、添加群组、填写主机ip地址→模板→选择要监控的模板→添加