在上文中我具体操作了在LAMP架构中搭建Zabbix监控服务,在本篇中我将在LNMP中搭建一个Zabbix服务,操作步骤相比于之前要稍微复杂一些,但也只是在细节上LNMP稍多一些,大体过程还是类似的。
实验环境:
STKAITI下载链接见 https://www.linuxidc.com/Linux/2018-11/155200.htm
操作步骤
一、搭建LNMP
1 安装nginx1.4
[root@promote~]#wget CentOS/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
[root@promote ~]# rpm -ivh nginx-release-centos-7-0.el7.ngx.noarch.rpm #安装nginx官方源
[root@promote ~]# yum install nginx -y
[root@promote ~]# systemctl start nginx
[root@promote ~]# systemctl enable nginx
[root@promote ~]# netstat -ntap | grep 80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 3024/nginx: master
在浏览器上访问
2 安装mysql5.7(这里为了安装方便我也mariadb来代替mysql,功能都是一样的):
[root@promote ~]# yum install mariadb-server mariadb -y #下载mariadb安装包
[root@promote ~]# systemctl start mariadb.service
[root@promote ~]# systemctl enable mariadb.service
[root@promote ~]# mysql_secure_installation #配置mariadb相关参数
Set root password? [Y/n] y
Remove anonymous users? [Y/n] n
Disallow root login remotely? [Y/n] n
Remove test database and access to it? [Y/n] n
Reload privilege tables now? [Y/n] y
3 安装PHP7.2
[root@promote~]#rpm -Uvh https://dl.Fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
[root@promote ~]# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm #下载PHPyum源
[root@promote ~]# yum install php72w php72w-devel php72w-fpm php72w-gd php72w-mbstring php72w-mysql -y #安装PHP相关服务
[root@promote ~]# php -v #查看版本
PHP 7.2.10 (cli) (built: Sep 15 2018 07:10:58) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
4 配置nginx支持PHP:
[root@promote ~]# vim /etc/php-fpm.d/www.conf
8 user = nginx #将Apache改为nginx
10 group = nginx #将Apache改为nginx
5 配置PHP:
[root@promote ~]# vim /etc/php.ini
359 expose_php = Off #隐藏PHP版本
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
date.timezone = Asia/Shanghai #将时区设为上海时区
6 配置PHP请求被传送到后端的php-fpm模块,默认情况下php配置模块是被注释掉的:
[root@promote ~]# vim /etc/nginx/conf.d/default.conf
10 index index.php index.html index.htm;
30 location ~ \.php$ {
31 root /usr/share/nginx/html;
32 fastcgi_pass 127.0.0.1:9000;
33 fastcgi_index index.php; 34 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_scr ipt_name; 35 include fastcgi_params; 36 } #把fastcgi_param中的/scripts改为$document_root,root是配置php程序用户
7 开启服务
[root@promote ~]# systemctl start php-fpm.service
[root@promote ~]# systemctl enable php-fpm.service
[root@promote ~]# systemctl restart nginx
[root@promote ~]# vim /usr/share/nginx/html/index.php #创建PHP测试首页
<?php
phpinfo();
?>
在浏览器上访问
测试PHP能否连接数据库:
[root@promote html]# vim index.php
<?php
$link=mysqli_connect('127.0.0.1','root','123123');
if ($link) echo "true";
else echo "false";
?>
8 创建zabbix数据库与zabbix用户: