1. 程式人生 > >Zabbix二:在nginx上搭建

Zabbix二:在nginx上搭建

trapper cto root 0 rows group mir open exp .html

介紹就不再次介紹了。目前很多公司都在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

<?php
phpinfo();
?>

http://192.168.120.183/info.php
##測試連接數據庫
技術分享圖片
<?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上一樣

Zabbix二:在nginx上搭建