概述:在CentOS 7 64位操作系统环境下搭建LNMP(Linux+Nginx+MySQL+PHP)来运行Zabbix监控程序
CentOS 7安装PHP 7.2、Nginx 1.14及MySQL 5.7(搭建LNMP环境)
1.首先下载
wget http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
2.手动创建nginx yum安装源
vim /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1
3.安装nginx,默认为nginx-1.12.2
yum install nginx -y
systemctl start nginx
systemctl enable nginx
4.防火墙开放http服务
firewall-cmd --permanent --add-service=http --zone=public
firewall-cmd --reload
1.首先下载
yum install -y mariadb-server mariadb
2.开启服务
systemctl enable mariadb.service
systemctl start mariadb.service
3.初始化数据库,初始化过程中会提示输入随机密码
mysql_secure_installation
1.安装PHP软件包
yum install epel-release
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版本
2.配置nginx支持php
vim /etc/php-fpm.d/www.conf #修改php-fpm配置文件,把apache改为nginx
user = nginx //第8行
group = nginx //第10行
vim /etc/nginx/conf.d/default.conf #配置location,在index中添加index.php。以支持index.php的首页
//10 index index.php index.html index.htm;
//配置php请求被传送到后端的php-fpm模块,默认情况下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;
}
//把fastcgi_param中的/scripts改为$document_root。root是配置php程序放置的根目录。
3.配置PHP参数,Zabbix的硬件要求
vim /etc/php.ini #修改PHP配置文件
//359 expose_php = Off //隐藏php版本
//202 short_open_tag = On //支持php短标签
//以下为zabbix配置要求
//368 max_execution_time = 300 //执行时间
//378 max_input_time = 300 //接收数据等待时间
//389 memory_limit = 128M //每个脚本占用内存
//656 post_max_size = 16M //POST数据大小
//799 upload_max_filesize = 2M //下载文件大小
//800 always_populate_raw_post_data = -1 //可以用 $HTTP_RAW_POST_DATA 接收post raw data
//877 date.timezone = Asia/Shanghai //时区
4.启动php
systemctl start php-fpm
systemctl enable php-fpm
systemctl restart nginx
5.测试首页
vim /usr/share/nginx/html/info.php
<?php
phpinfo();
?>
在浏览器中输入http://192.168.50.148/info.php,测试php页面
6.测试连接数据库
vim /usr/share/nginx/html/info.php
<?php
$link=mysqli_connect('127.0.0.1','root','123123');
if ($link) echo "true !!!";
else echo "false !!!";
?>
注:mysql_connect扩展自 PHP 5.5.0 起已废弃,改用mysqli或pdo_mysql
vim /usr/share/nginx/html/info.php
<?php
$link=mysqli_connect('127.0.0.1','zabbix','admin123');
if ($link) echo "True!";
else echo "False!";
?>
1.下载安装zabbix的YUM源
rpm -i https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm
2.安装Zabbix
yum install zabbix-server-mysql zabbix-web-mysql zabbix-agent -y
3.导入Zabbix到数据库
zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p zabbix
4.安装之后进入MySQL数据库,创建Zabbix数据库
mysql -u root -p
MariaDB [(none)]> CREATE DATABASE zabbix character set utf8 collate utf8_bin;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> GRANT all privileges ON *.* TO 'zabbix'@'%' IDENTIFIED BY 'admin123';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
5.配置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 //修改本行
356:SNMPTrapperFile=/var/log/snmptrap/snmptrap.log
473:Timeout=4
516:AlertScriptsPath=/usr/lib/zabbix/alertscripts
527:ExternalScripts=/usr/lib/zabbix/externalscripts
563:LogSlowQueries=3000
6.修正图表中文乱码
vim /usr/share/zabbix/include/defines.inc.php
:%s /graphfont/kaiti/g //从微软系统下复制相应的字体文件到 /usr/share/zabbix/fonts 目录中注意字体名称要对应配置文件,且注意大小写
cp STKAITI.TTF /usr/share/zabbix/fonts/
setenforce 0 //一定要关闭
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 -anpl | grep 10051
在页面安装过程中遇到无法创建的问题根据提示的连接地址下载配置文件zabbix.conf.php
cp zabbix.conf.php /etc/zabbix/web/
chown zabbix.zabbix /etc/zabbix/web/zabbix.conf.php