文章目錄
- 專案環境:
- 服務端安裝配置
- 關閉防火墻
- 一、LNMP安裝環境
- 1、安裝nginx1.16
- (1)從官網上下載
- (2)手動創建nginx yum安裝源
- (3)重新加載
- (4)安裝nginx
- (5)開啟服務
- (6)打開網頁訪問 http://192.168.200.40
- 2、安裝mysql 5.7
- (1)安裝服務
- (2)開啟服務
- (3)進行設定
- 3、安裝PHP
- (1)安裝PHP源
- (2)yum倉庫的生成
- (3)安裝軟體包
- (4)查看PHP版本
- 4、配置nginx支持php
- (1)修改php-fpm組態檔,把apache改為nginx
- (2)配置location,在index中添加index.php,以支持index.php的首頁
- 5、配置php
- (1)修改PHP組態檔
- (2)開啟PHP服務并重啟nginx服務
- 6、測驗首頁
- (1)寫一個簡單的測驗首頁
- (2)打開瀏覽器訪問:http://192.168.200.40/info.php
- 7、測驗連接資料庫
- (1)測驗頁
- (2)在瀏覽器重繪:
- 8、安裝zabbix前提
- (1)準備zabbix資料庫
- (2)檢查用戶能否登錄資料庫
- (3)、瀏覽器重繪,發現Zabbix連接失敗
- (4)解決以上連接失敗的辦法
- (5)、重新重繪網頁,顯示連接成功
- 二、部署zabbix Server
- 1、安裝yum源
- 2、安裝相關環境包
- 3、修改組態檔
- 4、修正圖表中文亂碼(可選擇操作)
- 5、從微軟系統下復制相應的字體檔案到 /usr/share/zabbix/fonts 目錄中注意字體名稱要對應組態檔,且注意大小寫(可選擇操作)
- 6、賦予權限
- 7、生成資料庫檔案,注意密碼不要輸成root的
- 8、修改時區
- 9、啟動服務
- 10、安裝后登錄 用戶名Admin 密碼:zabbix
- 三、配置 Client 客戶端
- 1、Zabbix 監控服務器
專案環境:
服務端:192.168.200.40
客戶端:192.168.200.60
服務端安裝配置
關閉防火墻
[root@localhost ~]# systemctl stop firewalld.service
[root@localhost ~]# 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@localhost ~]# setenforce 0
一、LNMP安裝環境
1、安裝nginx1.16
(1)從官網上下載
root@localhost ~]# wget http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
--2021-04-01 11:13:37-- http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
正在決議主機 nginx.org (nginx.org)... 52.58.199.22, 3.125.197.172, 2a05:d014:edb:5702::6, ...
正在連接 nginx.org (nginx.org)|52.58.199.22|:80... 已連接,
已發出 HTTP 請求,正在等待回應... 200 OK
長度:4680 (4.6K) [application/x-redhat-package-manager]
正在保存至: “nginx-release-centos-7-0.el7.ngx.noarch.rpm”
100%[======================>] 4,680 --.-K/s 用時 0s
2021-04-01 11:13:38 (400 MB/s) - 已保存 “nginx-release-centos-7-0.el7.ngx.noarch.rpm” [4680/4680])
(2)手動創建nginx yum安裝源
[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
(3)重新加載
[root@localhost ~]# yum list
如果出現以下問題:
[root@localhost ~]# yum list
已加載插件:fastestmirror, langpacks
/var/run/yum.pid 已被鎖定,PID 為 17043 的另一個程式正在運行,
Another app is currently holding the yum lock; waiting for it to exit...
另一個應用程式是:PackageKit
記憶體:162 M RSS (649 MB VSZ)
已啟動: Thu Apr 1 11:10:49 2021 - 03:31之前
狀態 :睡眠中,行程ID:17043
將行程殺掉即可:
[root@localhost ~]# kill -5 17043
(4)安裝nginx
[root@localhost ~]# yum install nginx -y
(5)開啟服務
[root@localhost ~]# systemctl start nginx
[root@localhost ~]# netstat -ntap | grep nginx
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 108485/nginx: maste
[root@localhost ~]# systemctl enable nginx #設為開機自啟動
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
(6)打開網頁訪問 http://192.168.200.40

2、安裝mysql 5.7
(1)安裝服務
[root@localhost ~]# yum install -y mariadb-server mariadb
(2)開啟服務
[root@localhost ~]# systemctl start mariadb.service
[root@localhost ~]# systemctl enable mariadb.service
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
(3)進行設定
[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 #設定密碼
New password: #abc123
Re-enter new password: #abc123
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] n #不洗掉匿名用戶
... skipping.
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] n #允許遠程登錄
... skipping.
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 #不洗掉測驗資料庫
... skipping.
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] 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!
//驗證密碼已經設定好無誤
[root@localhost ~]# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 8
Server version: 5.5.64-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> \q
Bye
3、安裝PHP
(1)安裝PHP源
[root@localhost ~]# rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
獲取https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
警告:/var/tmp/rpm-tmp.uNc4OO: 頭V3 RSA/SHA256 Signature, 密鑰 ID 352c64e5: NOKEY
準備中... ################################# [100%]
正在升級/安裝...
1:epel-release-7-12 ################################# [100%]
(2)yum倉庫的生成
[root@localhost ~]# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
獲取https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
警告:/var/tmp/rpm-tmp.O9dfAV: 頭V4 RSA/SHA1 Signature, 密鑰 ID 62e74ca5: NOKEY
準備中... ################################# [100%]
正在升級/安裝...
1:webtatic-release-7-3 ################################# [100%]
(3)安裝軟體包
[root@localhost ~]# yum install -y php72w php72w-devel php72w-fpm php72w-gd php72w-mbstring php72w-mysql
(4)查看PHP版本
[root@localhost ~]# php -v
PHP 7.2.34 (cli) (built: Oct 1 2020 13:37:37) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
4、配置nginx支持php
(1)修改php-fpm組態檔,把apache改為nginx
[root@localhost ~]# vim /etc/php-fpm.d/www.conf
#第8行 user = nginx
#第10行 group = nginx
(2)配置location,在index中添加index.php,以支持index.php的首頁
[root@localhost ~]# vim /etc/nginx/conf.d/default.conf
#第10行 index index.php index.html index.htm;
#第30~36行
#配置php請求被傳送到后端的php-fpm模塊,默認情況下php配置塊是被注釋的,此時去掉注釋并修改
#把fastcgi_param中的/scripts改為$document_root,root是配置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
(1)修改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
#第877行 date.timezone = Asia/Shanghai //時區
(2)開啟PHP服務并重啟nginx服務
[root@localhost ~]# systemctl start php-fpm.service
[root@localhost ~]# 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@localhost ~]# netstat -ntap | grep 9000
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 86082/php-fpm: mast
[root@localhost html]# systemctl restart nginx
6、測驗首頁
(1)寫一個簡單的測驗首頁
[root@localhost ~]# vim /usr/share/nginx/html/info.php
<?php
phpinfo();
?>
(2)打開瀏覽器訪問:http://192.168.200.40/info.php

7、測驗連接資料庫
(1)測驗頁
[root@localhost ~]# vim /usr/share/nginx/html/info.php
<?php
$link=mysqli_connect('127.0.0.1','root','abc123');
if ($link) echo "連接成功!!";
else echo "連接失敗!!";
?>
注:mysql_connect擴展自 PHP 5.5.0 起已廢棄,改用mysqli或pdo_mysql
(2)在瀏覽器重繪:

8、安裝zabbix前提
(1)準備zabbix資料庫
[root@localhost html]# mysql -uroot -p
ariaDB [(none)]> CREATE DATABASE zabbix character set utf8 collate utf8_bin;
MariaDB [(none)]> GRANT all privileges ON *.* TO 'zabbix'@'%' IDENTIFIED BY 'admin123';
MariaDB [(none)]> flush privileges;
#collate的作用
對于mysql中那些字符型別的列,如VARCHAR,CHAR,TEXT型別的列,都需要有一個COLLATE型別來告知mysql如何對該列進行排序和比較,
(2)檢查用戶能否登錄資料庫
[root@localhost ~]# vim /usr/share/nginx/html/info.php
<?php
$link=mysqli_connect('127.0.0.1','zabbix','admin123');
if ($link) echo "Zabbix資料庫連接成功!";
else echo "Zabbix資料庫連接失敗!";
?>
(3)、瀏覽器重繪,發現Zabbix連接失敗

(4)解決以上連接失敗的辦法
[root@localhost html]# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 12
Server version: 5.5.64-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> select user,host from mysql.user; #有空用戶名稱占用導致本地無法登錄遠程可登錄
+--------+-----------------------+
| user | host |
+--------+-----------------------+
| zabbix | % |
| root | 127.0.0.1 |
| root | ::1 |
| | localhost |
| root | localhost |
| | localhost.localdomain |
| root | localhost.localdomain |
+--------+-----------------------+
7 rows in set (0.00 sec)
MariaDB [(none)]> drop user ''@localhost; #洗掉空用戶
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> drop user ''@localhost.localdomain; #洗掉空用戶
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 | localhost |
| root | localhost.localdomain |
+--------+-----------------------+
5 rows in set (0.00 sec)
MariaDB [(none)]> \q
Bye
(5)、重新重繪網頁,顯示連接成功

二、部署zabbix Server
zabbix 官網 https://www.zabbix.com/download
1、安裝yum源
[root@localhost ~]# 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.ReqDjI: 頭V4 RSA/SHA512 Signature, 密鑰 ID a14fe591: NOKEY
2、安裝相關環境包
[root@localhost ~]# yum install zabbix-server-mysql zabbix-web-mysql zabbix-agent -y
3、修改組態檔
[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=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
[root@localhost ~]# grep -n '^'[a-Z] /etc/zabbix/zabbix_server.conf
#檢查修改的組態檔是否正確
4、修正圖表中文亂碼(可選擇操作)
[root@localhost ~]# vim /usr/share/zabbix/include/defines.inc.php
:%s /graphfont/kaiti/g #同時按住shift與:鍵
5、從微軟系統下復制相應的字體檔案到 /usr/share/zabbix/fonts 目錄中注意字體名稱要對應組態檔,且注意大小寫(可選擇操作)
cp STKAITI.TTF /usr/share/zabbix/fonts/
6、賦予權限
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/
'//遞回修改檔案權限'
7、生成資料庫檔案,注意密碼不要輸成root的
[root@localhost zabbix]# zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p zabbix
Enter password: #密碼admin23
//查看檔案是否存在
[root@localhost zabbix]# mysql -uzabbix -p
MariaDB [(none)]> use zabbix;
MariaDB [zabbix]> show tables;
8、修改時區
[root@localhost zabbix]# vim /etc/httpd/conf.d/zabbix.conf
#第20行 php_value date.timezone Asia/Shanghai
9、啟動服務
systemctl start zabbix-server.service && systemctl enable zabbix-server.service
systemctl start zabbix-agent.service && systemctl enable zabbix-agent.service
systemctl restart php-fpm.service && systemctl restart nginx
[root@localhost zabbix]# netstat -anpl | grep 10051
tcp 0 0 0.0.0.0:10051 0.0.0.0:* LISTEN 121393/zabbix_serve
tcp 0 0 127.0.0.1:10051 127.0.0.1:58008 TIME_WAIT -
tcp6 0 0 :::10051 :::* LISTEN 121393/zabbix_serve
10、安裝后登錄 用戶名Admin 密碼:zabbix
瀏覽器輸入:輸入:http://192.168.200.40/zabbix/







[root@localhost web]# chmod -R +x /etc/zabbix/ #賦權
[root@localhost web]# ls
maintenance.inc.php zabbix.conf.php






三、配置 Client 客戶端
rpm -Uvh https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-2.el7.noarch.rpm
yum -y install zabbix-agent
'//安裝zabbix存盤庫與agent代理服務'
--
vim /etc/zabbix/zabbix_agentd.conf '//修改zabbix代理組態檔'
Server=192.168.200.40 '//98行,指向監控服務器地址'
ServerActive=192.168.200.40 '//139行,指向監控服務器地址'
Hostname=Zabbix-test '//150行,修改名稱'
--
systemctl start zabbix-agent.service && systemctl enable zabbix-agent.service
netstat -ntap |grep 'zabbix'
1、Zabbix 監控服務器
可以將界面轉換成中文界面





查看監控資料:



轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/271502.html
標籤:其他
上一篇:行程創建-終止-等待-替換
下一篇:Linux基礎(較全)
