LAMP構架+ZABBIX

在這裏插入圖片描述

一、zabbix部署

在這裏插入圖片描述

二、開局優化

iptables  -F  情況防火牆規則,
setenforce 0   關閉增強安全性功能
1、安裝nginx
[root@localhost ~]# wget http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
[root@localhost ~]# vim /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1

在這裏插入圖片描述

[root@localhost ~]# yum list
[root@localhost ~]# yum install nginx -y
[root@localhost ~]# systemctl start nginx
[root@localhost ~]# systemctl enable nginx
2、安裝mysql
[root@localhost ~]# yum install mariadb-server mariadb -y
[root@localhost ~]# systemctl start mariadb
[root@localhost ~]# systemctl enable mariadb.service
[root@localhost ~]# mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): 	'//初次運行直接回車'
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] y	'//y。設置密碼'
New password: 	'//輸入密碼'
Re-enter new password: 	'//重複輸入一次'
Password updated successfully!
Reloading privilege tables..
 ... Success!

By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y	'//是否刪除匿名用戶,建議y刪除'
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y	'//是否禁止root遠程登錄,建議y禁止'
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] n	'//是否刪除test數據庫,根據實際情況'
 ... skipping.

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y	'//是否重新加載權限表,建議y'
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!
3、安裝PHP
[root@localhost ~]# rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
[root@localhost ~]# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
[root@localhost ~]# yum install php72w php72w-devel php72w-fpm php72w-gd php72w-mbstring php72w-mysql -y
php -v 	//查看版本
4、配置nginx支持php

修改php-fpm的配置文件,將apache改爲nginx

[root@localhost ~]# vim /etc/php-fpm.d/www.conf 

在這裏插入圖片描述
更改nginx的默認配置文件,配置location,在index中添加index.php

[root@localhost ~]# vim /etc/nginx/conf.d/default.conf 

在這裏插入圖片描述

配置php請求被傳送到後端的php-fpm模塊,默認情況下php配置塊是被註釋的,將註釋取消

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;
} 

在這裏插入圖片描述

5、修改php的配置文件
[root@localhost ~]# vim /etc/php.ini
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
878 date.timezone = Asia/Shanghai	//時區

[root@localhost ~]# systemctl start php-fpm.service 
[root@localhost ~]# systemctl enable php-fpm.service 
[root@localhost ~]# systemctl restart nginx
6、##創建php測試頁面
[root@localhost ~]# vim /usr/share/nginx/html/info.php
<?php
  phpinfo();
?>

使用瀏覽器訪問http://192.168.49.11/info.php
在這裏插入圖片描述
##測試連接數據庫

[root@localhost ~]# vim /usr/share/nginx/html/info.php
<?php
 $link=mysqli_connect('127.0.0.1','root','abc123');
 if ($link) echo "連接成功!!!";
 else echo "連接失敗!!!";
?>

在這裏插入圖片描述

7、安裝部署zabbix

在數據庫創建zabbix數據庫、zabbix用戶

[root@localhost ~]# mysql -uroot -p
create database zabbix character set utf8 collate utf8_bin;
grant all privileges on *.* to 'zabbix'@'%' identified by 'abc123';
flush privileges;

報錯

解決創建的賬戶本地無法登陸的問題

[root@localhost ~]# mysql -uzabbix -p
Enter password: 
ERROR 1045 (28000): Access denied for user 'zabbix'@'localhost' (using password: YES)

#原因是有空用戶名稱佔用導致本地無法登陸
MariaDB [(none)]> select user,host from mysql.user;
+--------+---------------+
| user   | host          |
+--------+---------------+
| zabbix | %             |
| root   | 127.0.0.1     |
|        | 192.168.49.11 |
| root   | 192.168.49.11 |
| root   | ::1           |
|        | localhost     |
| root   | localhost     |
+--------+---------------+
7 rows in set (0.00 sec)

MariaDB [(none)]> drop user ''@'localhost';
MariaDB [(none)]> drop user ''@'192.168.49.11';
下載zabbix的鏡像源並安裝
[root@localhost ~]# rpm -i https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm
[root@localhost ~]# yum install zabbix-server-mysql zabbix-web-mysql zabbix-agent -y
#更改zabbix_server的配置文件
[root@localhost ~]# 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=abc123		//修改添加數據庫密碼
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

#
[root@localhost ~]# vim /usr/share/zabbix/include/defines.inc.php
%s /graphfont/kaiti/g	
#從微軟系統下複製相應的字體文件到/usr/share/zabbix/fonts
[root@localhost ~]# cd /usr/share/zabbix
[root@localhost zabbix]# mkdir fonts
[root@localhost zabbix]# cd fonts/

#上傳後查看
[root@localhost fonts]# ls
STKAITI.TTF
9、更改設置權限
[root@localhost fonts]# cp -r /usr/share/zabbix/ /usr/share/nginx/html/
[root@localhost fonts]# chown -R zabbix:zabbix /etc/zabbix/
[root@localhost fonts]# chown -R zabbix:zabbix /usr/share/nginx/
[root@localhost fonts]# chown -R zabbix:zabbix /usr/lib/zabbix/
[root@localhost fonts]# chmod 755 /etc/zabbix/web/
[root@localhost fonts]# chmod 777 /var/lib/php/session/

將相應的文件上傳到zabbix數據庫
[root@localhost fonts]# zcat /usr/share/doc/zabbix-server-mysql-4.0.20/create.sql.gz | mysql -uzabbix -p zabbix

#開啓服務
[root@localhost fonts]# systemctl start zabbix-server.service 
[root@localhost fonts]# systemctl enable zabbix-server.service 
[root@localhost fonts]# systemctl start zabbix-agent.service 
[root@localhost fonts]# systemctl enable zabbix-agent.service

[root@localhost fonts]# systemctl restart php-fpm.service 
[root@localhost fonts]# systemctl restart nginx

http://192.168.49.11/zabbix	用戶名Admin,密碼zabbix
#安裝時,會提示缺少zabbix.conf.php文件報錯,按照提示下載,並上傳到/etc/zabbix/web/
#更改權限
[root@localhost web]# chown zabbix.zabbix zabbix.conf.php

在這裏插入圖片描述
在這裏插入圖片描述
在這裏插入圖片描述
在這裏插入圖片描述

10、代理服務器配置
[root@localhost ~]# rpm -i https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm
[root@localhost ~]# yum install zabbix-agent -y
[root@client ~]# vim /etc/zabbix/zabbix_agentd.conf 
Server=192.168.49.11	'//98行指向監控服務器地址'
ServerActive=192.168.49.11	'//139行指向監控服務器地址'
Hostname=Zabbix-test	'//150行修改名稱'
[root@client ~]# systemctl start zabbix-agent.service 
[root@client ~]# systemctl enable zabbix-agent.service 
[root@localhost ~]# netstat -ntap | grep zabbix
tcp        0      0 0.0.0.0:10050           0.0.0.0:*               LISTEN      41511/zabbix_agentd 
tcp6       0      0 :::10050                :::*                    LISTEN      41511/zabbix_agentd 

在這裏插入圖片描述
在這裏插入圖片描述
在這裏插入圖片描述
在這裏插入圖片描述
回到首頁查看監控狀態,等待300秒(一個監控週期)
在這裏插入圖片描述

報錯

在這裏插入圖片描述
檢查:

  1. 檢查zabbix_server.conf配置文件,數據庫配置正確,但依然報上面的錯誤
  2. /etc/zabbix/web/zabbix.conf.php,文件裏面也有數據庫的配置,進行修改
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章