介绍就不再次介绍了。目前很多公司都在nginx上搭建服务了,所以我又搭建了一个LNMP+Zabbix,具体步骤如下
-----------LNMP+Zabbix----------------------------
##两台服务器防火墙关闭
[root@cacti ~]# systemctl stop firewalld.service
[root@cacti ~]# systemctl disable firewalld.service
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@cacti ~]# setenforce 0
===========LNMP安装环境(安装nginx1.14)========
##手动配置yum仓库
[root@cacti ~]# vim /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1
-------------------安装nginx------------------
[root@cacti ~]# yum list
[root@cacti ~]# yum install nginx -y
[root@cacti ~]# systemctl start nginx
[root@cacti ~]# netstat -ntap | grep nginx
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 45100/nginx: master
[root@cacti ~]# systemctl enable nginx
------------------安装mariadb-----------------
[root@cacti ~]# yum install mariadb-server mariadb -y
[root@cacti ~]# systemctl start mariadb.service
[root@cacti ~]# systemctl enable mariadb.service
##设置数据库
[root@cacti ~]# mysql_secure_installation
回车
y
abc123 ##密码自己定义
abc123
n
n
n
y
##登录数据库
[root@cacti ~]# mysql -uroot -p
Enter password: ##输入密码
MariaDB [(none)]>
-----------------安装php7.2------------------------
#安装epel源
[root@cacti ~]# rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
##或者
[root@cacti ~]# yum install epel-release -y
[root@cacti ~]# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
[root@cacti ~]# yum install php72w php72w-devel php72w-fpm php72w-gd php72w-mbstring php72w-mysql -y
[root@cacti ~]# php -v
PHP 7.2.10 (cli) (built: Sep 15 2018 07:10:58) ( NTS )
[root@cacti ~]# vim /etc/php-fpm.d/www.conf
user = nginx ##8行
group = nginx ##10行
[root@cacti ~]# vim /etc/php.ini
expose_php = Off ##359行(隐藏php版本)
short_open_tag = On ##202行(支持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行
date.timezone = Asia/Shanghai ##877行(时区)
[root@cacti ~]# vim /etc/nginx/conf.d/default.conf
index index.php index.html index.htm; ##10行
location ~ .php$ { ##30-36行(去掉注释)
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; #修改用户root
include fastcgi_params;
}
##启动服务
[root@cacti ~]# systemctl start php-fpm.service
[root@cacti ~]# systemctl enable php-fpm.service
Created symlink from /etc/systemd/system/multi-user.target.wants/php-fpm.service to /usr/lib/systemd/system/php-fpm.service.
[root@cacti ~]# netstat -ntap | grep 9000
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 3250/php-fpm: maste
[root@cacti ~]# systemctl restart nginx
##测试
[root@cacti ~]# cd /usr/share/nginx/html/
[root@cacti html]# ls
50x.html index.html
[root@cacti html]# vim info.php
phpinfo();
?>
http://192.168.120.183/info.php
##测试连接数据库
$link=mysqli_connect('127.0.0.1','root','abc123');
if ($link) echo "true !!!";
else echo "false !!!";
?>
[root@cacti html]# mysql -uroot -p
Enter password:
MariaDB [(none)]> CREATE DATABASE zabbix character set utf8 collate utf8_bin;
Query OK, 1 row affected (0.02 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)
[root@cacti html]# mysql -uzabbix -p
Enter password:
MariaDB [(none)]>
##如果zabbix用户登录失败,参考以下方法
-------------解决本地无法登录问题(可忽略)---------------------------
[root@cacti html]# mysql -uzabbix -p
Enter password:
ERROR 1045 (28000): Access denied for user 'zabbix'@'localhost' (using password: YES)
##出错##
##解决方案:
##进入root用户数据库
[root@cacti html]# mysql -uroot -p
MariaDB [(none)]> select user,host from mysql.user;
+--------+-----------+
| user | host |
+--------+-----------+
| zabbix | % |
| root | 127.0.0.1 |
| root | ::1 |
| | cacti |
| root | cacti |
| | localhost |
| root | localhost |
+--------+-----------+
##出现空用户,删除空用户
MariaDB [(none)]> drop user ''@localhost;
Query OK, 0 rows affected (0.02 sec)
MariaDB [(none)]> drop user ''@cacti;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> select user,host from mysql.user;
+--------+-----------+
| user | host |
+--------+-----------+
| zabbix | % |
| root | 127.0.0.1 |
| root | ::1 |
| root | cacti |
| root | localhost |
+--------+-----------+
##空用户已删除
[root@cacti html]# mysql -uzabbix -p
Enter password:
MariaDB [(none)]>
##登录成功
----------------以下开始部署zabbix Server-------
[root@cacti ~]# rpm -i https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm
警告:/var/tmp/rpm-tmp.hVq9av: 头V4 RSA/SHA512 Signature, 密钥 ID a14fe591: NOKEY
[root@cacti ~]# yum install zabbix-server-mysql zabbix-web-mysql zabbix-agent -y
[root@cacti ~]#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 ##修改
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
[root@cacti ~]# mkdir /abc
[root@cacti ~]# mount.cifs //192.168.100.10/rhel7 /abc
Password for root@//192.168.100.10/rhel7:
[root@cacti ~]# cd /abc/zabbix/
[root@cacti zabbix]# ls
php-bcmath-5.4.16-42.el7.x86_64.rpm php-mbstring-5.4.16-42.el7.x86_64.rpm STKAITI.TTF
[root@cacti zabbix]# vim /usr/share/zabbix/include/defines.inc.php
##shift:输入
:%s /graphfont/kaiti/g
[root@cacti zabbix]# cp STKAITI.TTF /usr/share/zabbix/fonts/
[root@cacti ~]# cp -r /usr/share/zabbix/ /usr/share/nginx/html/
[root@cacti html]# chown -R zabbix:zabbix /etc/zabbix/
[root@cacti html]# chown -R zabbix:zabbix /usr/share/nginx/
[root@cacti html]# chown -R zabbix:zabbix /usr/lib/zabbix/
[root@cacti html]# chmod -R 755 /etc/zabbix/web/
[root@cacti html]# chmod -R 777 /var/lib/php/session/
[root@cacti html]# zcat /usr/share/doc/zabbix-server-mysql/create.sql.gz | mysql -uzabbix -p zabbix
Enter password: ##密码为之前设置的admin123(zabbix登录密码)
##启动服务
[root@cacti ~]# systemctl start zabbix-server.service
[root@cacti ~]# systemctl start zabbix-agent.service
[root@cacti ~]# netstat -anpt | grep zabbix
tcp 0 0 0.0.0.0:10050 0.0.0.0: LISTEN 2789/zabbix_agentd
tcp6 0 0 :::10050 :::* LISTEN 2789/zabbix_agentd
[root@cacti ~]# systemctl stop php-fpm.service
[root@cacti ~]# systemctl stop nginx
[root@cacti ~]# systemctl start php-fpm.service
[root@cacti ~]# systemctl start nginx
[root@cacti ~]# systemctl restart zabbix-server.service
##访问
http://192.168.120.183/zabbix/setup.php
网页访问步骤和之前在LAMP上一样
转载于:https://blog.51cto.com/13756916/2310137