- What is monitoring?
Monitoring and control Monitoring in
life: accountability after the event. Monitoring in
operation and maintenance: accountability after the event, pre-warning, performance analysis, real-time alarm;
2. Common Linux monitoring command
top: display process information.
htop: An interactive process viewer in the Linux system.
uptime: The
first item is the current time, up means the system is running, 5:53 is the total time of system startup, and the last is the load information of the system.
free: View memory.
vmstat: is the abbreviation of Virtual Meomory Statistics (virtual memory statistics), which can monitor the virtual memory, process, and CPU activities of the operating system.
iostat: monitors the disk operation activities of the system. Its characteristic is to report disk activity statistics and also report CPU usage.
df: Display the available disk space on the disk partition. Iftop:
Monitor the IP address.
Nethogs: Monitor the process number.
3. Use shell scripts to monitor the server
#!/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
Disadvantages: low efficiency, unable to realize centralized alarm, and unable to analyze historical data
4.zabbix's basic service architecture
5.zabbix production environment installation
Operating system: centos 7.6
IP address: 10.0.0.71
5.1. Install php operating environment
requires php version 7.2 or higher +
install php third-party source:
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
Install NGINX:
yum install nginx -y
Configure php-fpm and 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;
}
}
}
Start NGINX and PHP-FPM
mkdir /html
nginx -t
systemctl start nginx
systemctl enable nginx
systemctl start php-fpm
systemctl enable php-fpm
Prepare the php code of zabbix-web
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/
#Solution:
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
Then proceed to
5.2. Install the database
#parameter link https://www.jianshu.com/p/dd7137c4efa5 in the next step
#创库授权
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: Install zabbix-server to
configure the source of 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
Install zabbix-server
yum install zabbix-server-mysql -y
Import zabbix initial data`
zcat /usr/share/doc/zabbix-server-mysql-*/create.sql.gz|mysql -uzabbix -p123456 zabbix
Configure zabbix-server
vim /etc/zabbix/zabbix_server.conf
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=123456
DBSocket=/tmp/mysql.sock
Start zabbix-server
systemctl start zabbix-server.service
systemctl enable zabbix-server.service
netstat -lntup|grep 10051
Solution:
vim /etc/php.ini
pdo_mysql.default_socket= /tmp/mysql.sock
mysqli.default_socket = /tmp/mysql.sock
systemctl restart php-fpm
6: Monitor a server host
6.1 Monitoring zabbix-server (Monitor yourself)
yum install zabbix-agent -y
systemctl start zabbix-agent.service
systemctl enable zabbix-agent.service
6.2 Monitoring other linux hosts
prepare before adding monitoring
Host IP address: 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
Then restart zabbix-server: (10.0.0.71)
systemctl restart zabbix-server