服务端server:192.168.132.60
客户端node:192.168.132.50
清空防火墙规则,关闭核心防护
iptables -F
setenforce 0
关闭网络管理
systemctl stop NetworkManager
systemctl disable NetworkManager
wget http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
vim /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1
安装并启动
yum list
yum install nginx -y
systemctl start nginx
systemctl enable nginx
netstat -ntap | grep nginx
登录浏览器看一下http://192.168.132.60
yum install -y mariadb-server mariadb
systemctl enable mariadb.service
systemctl start mariadb.service
netstat -ntap | grep 3306
初始化配置
mysql_secure_installation
Enter current password for root (enter for none): 回车
Set root password? [Y/n] yes
New password: 123123
Re-enter new password: 123123
Remove anonymous users? no
Disallow root login remotely? no
Remove test database and access to it? no
Reload privilege tables now? yes
登录验证
mysql -uroot -p
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
或wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
安装yum源
cd /etc/yum.repos.d
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
yum install -y php72w php72w-devel php72w-fpm php72w-gd php72w-mbstring php72w-mysql
查看php版本
php -v
修改php-fpm配置文件,把apache改为nginx
vim /etc/php-fpm.d/www.conf
user = nginx #8行
group = nginx #10行
配置nginx支持php
vim /etc/nginx/conf.d/default.conf
index index.php index.html index.htm; #10行添加index.php
30到36行配置去掉注释并修改
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;
}
修改PHP配置文件
[root@server yum.repos.d]# 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 -ntap | grep 9000
vim /usr/share/nginx/html/info.php
<?php
phpinfo();
?>
网页访问 192.168.132.60/info.php ,可看到PHP首页面
测试连接数据库
vim /usr/share/nginx/html/info.php
<?php
$link=mysqli_connect('127.0.0.1','root' ,'123123' );
if ($link) echo "连接成功 !";
else echo "连接失败 !";
?>
注:mysql_connect扩展自 PHP 5.5.0起已废弃,改用mysqli或pdo_mysql
#网页刷新 192.168.132.60/info.php ,可看到连接成功 !
建立数据库及用户并且授权
mysql -u root -p #密码123123
MariaDB [(none)]> CREATE DATABASE zabbix character set utf8 collate utf8_bin;
MariaDB [(none)]> GRANT all privileges ON *.* TO 'zabbix'@'%' IDENTIFIED BY 'admin123';
MariaDB [(none)]> flush privileges;
测试连接zabbix数据库
vim /usr/share/nginx/html/info.php
<?php
$link=mysqli_connect('127.0.0.1','zabbix' ,'admin123' );
if ($link) echo "zabbix数据库连接成功 !";
else echo "zabbix数据库连接失败 !";
?>
浏览器刷新,发现Zabbix连接失败
解决连接失败方法
mysql -uroot -p
select user,host from mysql.user;
drop user ''@localhost;
drop user ''@localhost.localdomain;
select user,host from mysql.user;
重新登录一下http://192.168.132.60/info.php
rpm -i https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm
yum install zabbix-server-mysql zabbix-web-mysql zabbix-agent -y
导入数据库脚本
zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p zabbix #生成数据库文件,注意密码不要输成root的
mysql -u zabbix -p
Enter password: #输入zabbix密码
MariaDB [(none)]> use zabbix;
MariaDB [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 #注释去掉,数据库存放地址,目前是本地
101 DBName=zabbix
117 DBUser=zabbix
125 DBPassword=admin123 #注释去掉,zabbix的密码
357 SNMPTrapperFile=/var/log/snmptrap/snmptrap.log
475 Timeout=4
518 AlertScriptsPath=/usr/lib/zabbix/alertscripts
529 ExternalScripts=/usr/lib/zabbix/externalscripts
565 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.service
systemctl enable zabbix-server.service
systemctl start zabbix-agent.service
systemctl enable zabbix-agent.service
netstat -ntap | grep 10051
tcp 0 0 0.0.0.0:10051 0.0.0.0:* LISTEN 60468/zabbix_server
tcp 0 0 127.0.0.1:10051 127.0.0.1:40646 TIME_WAIT -
tcp6 0 0 :::10051 :::* LISTEN 60468/zabbix_server
systemctl restart php-fpm.service
systemctl restart nginx
网页访问 http://192.168.132.60/zabbix
#这时会遇到报错,按提示点击下载配置文件zabbix.con.php并保存至/etc/zabbix/web/
cd /etc/zabbix/web/
ll
chown zabbix.zabbix /etc/zabbix/web/zabbix.conf.php
systemctl restart zabbix-server.service
安装后登录 用户名: Admin 密码: zabbix
点击右上角 用户头像 更改字体
字体更改完成
1、清空防火墙规则,关闭核心防护
iptables -F
setenforce 0
2、部署zabbix-agent
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.132.60 #指向监控服务器
ServerActive=192.168.132.60 #指问监控服务器
Hostname=test #指定名称
Include=/etc/zabbix/zabbix_agentd.d/*.conf
重启服务
systemctl enable zabbix-agent.service
systemctl restart zabbix-agent.service
检查端口
netstat -anpt | grep zabbix #监听10050端口已开启
1、添加被监控主机
在zabbix图形界面—配置–主机–创建主机(定义主机名称,添加群组,填写主机IP地址) --模板–选定要监控的模板 (httpd sshd 服务)–选择–添加(添加连接模板)–添加(添加主机)