- 什么是監控?
監視和控制
生活中的監控:事后追責
運維中的監控:事后追責,事前預警,性能分析,實時報警;
2. 常見的Linux監控命令
top:顯示行程資訊,
htop:Linux系統中的一個互動的行程查看器,
uptime:

第一項是當前時間,up 表示系統正在運行,5:53 是系統啟動的總時間,最后是系統的負載load資訊,
free:查看記憶體,
vmstat:是Virtual Meomory Statistics(虛擬記憶體統計)的縮寫,可對作業系統的虛擬記憶體、行程、CPU活動進行監控
iostat:將對系統的磁盤操作活動進行監視,它的特點是匯報磁盤活動統計情況,同時也會匯報出CPU使用情況
df:顯示磁盤磁區上可以使用的磁盤空間
iftop:針對IP地址進行監控
nethogs:針對行程號來進行監控
3. 使用shell腳本來監控服務器
#!/bin/bash
MEM=`free -m|awk 'NR==2{print $NF}'`
if [ $MEM -lt 100 ];then
echo "web服務器 $ip地址 可用記憶體不足,當前可用記憶體
$MEM" | mail -s "web服務器記憶體不足" *****@qq.com
fi
缺點:效率低,不能實作集中報警,不可以分析歷史資料
4.zabbix的基礎服務架構

5.zabbix生產環境安裝
作業系統:centos 7.6
IP地址:10.0.0.71
5.1.安裝php運行環境
要求php版本 7.2以上+
安裝php第三方源:
yum install epel-release -y
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
yum install php72w-fpm php72w-gd.x86_64 php72w-bcmath.x86_64 php72w-xml.x86_64 php72w-mbstring.x86_64 php72w-ldap.x86_64 php72w-mysqlnd.x86_64 -y
安裝NGINX:
yum install nginx -y
配置php-fpm和nginx:
vim /etc/php-fpm.d/www.conf
user = nginx
group = nginx
vim /etc/nginx/nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location / {
root /html;
index index.php index.html index.htm;
}
location ~ \.php$ {
root /html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME
/html$fastcgi_script_name;
include fastcgi_params;
}
}
}
啟動NGINX和PHP-FPM
mkdir /html
nginx -t
systemctl start nginx
systemctl enable nginx
systemctl start php-fpm
systemctl enable php-fpm
準備zabbix-web的php代碼
wget https://cdn.zabbix.com/zabbix/sources/stable/5.0/zabbix-5.0.8.tar.gz
tar xf zabbix-5.0.8.tar.gz
cd zabbix-5.0.8/ui/
cp -a * /html/
chown -R nginx:nginx /html
#解決首次訪問 zabbix-web安裝界面 error 500的錯誤 (查看報錯解決相應的問題)
mkdir /var/lib/php/session
chown -R nginx:nginx /var/lib/php/session/


#解決方法:
vim /etc/php.ini
max_execution_time = 300
max_input_time = 300
post_max_size = 16M
date.timezone = Asia/Shanghai
systemctl restart php-fpm.service
然后下一步進行

5.2.安裝資料庫
#引數鏈接https://www.jianshu.com/p/dd7137c4efa5
#創庫授權
create database zabbix character set utf8 collate utf8_bin;
create user 'zabbix'@'localhost' identified by '123456';
grant all privileges on zabbix.* to 'zabbix'@'localhost';
5.3:安裝zabbix-server
配置zabbix 5.0的源
rpm -ivh https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
sed -i 's#http://repo.zabbix.com#https://mirrors.tuna.tsinghua.edu.cn/zabbix#g' /etc/yum.repos.d/zabbix.repo
安裝zabbix-server
yum install zabbix-server-mysql -y
匯入zabbix初始資料`
zcat /usr/share/doc/zabbix-server-mysql-*/create.sql.gz|mysql -uzabbix -p123456 zabbix
配置zabbix-server
vim /etc/zabbix/zabbix_server.conf
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=123456
DBSocket=/tmp/mysql.sock
啟動zabbix-server
systemctl start zabbix-server.service
systemctl enable zabbix-server.service
netstat -lntup|grep 10051

解決方法:
vim /etc/php.ini
pdo_mysql.default_socket= /tmp/mysql.sock
mysqli.default_socket = /tmp/mysql.sock
systemctl restart php-fpm



6∶監控一臺服務器主機
6.1 監控zabbix-server (自己監控自己)
yum install zabbix-agent -y
systemctl start zabbix-agent.service
systemctl enable zabbix-agent.service

6.2 監控其他linux主機
添加監控前準備
主機IP地址:10.0.0.8
#安裝
rpm -ivh
https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/5.0/
rhel/7/x86_64/zabbix-agent2-5.0.8-1.el7.x86_64.rpm
#配置
vim /etc/zabbix/zabbix_agent2.conf
Server=10.0.0.71
#啟動
systemctl start zabbix-agent2.service
systemctl enable zabbix-agent2.service


然后重啟zabbix-server:(10.0.0.71)
systemctl restart zabbix-server

轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/255627.html
標籤:其他
