Linux operation and maintenance --- deployment of Zabbix monitoring platform

At work, the Linux server to install the Zabbix monitoring platform needs to build an environment, so I spent half a day reinstalling a CentOS 7 system, starting with the setup environment.

Zabbix monitoring scope: hardware monitoring , system monitoring , application service monitoring , performance monitoring , log monitoring , security monitoring , network monitoring, MySQL database monitoring, URL monitoring (Zabbix Web monitoring)

Hardware monitoring: View the hardware's CPU, memory, hard disk usage, temperature, fan speed and other related performance

Operating system and installed Zabbix version

Linux server system CentOS 7 

Zabbix monitoring platform version 4.4

Configure the network card parameter NOBOOT = yes

[root@localhost ~]# cd /etc/sysconfig/network-scripts
[root@localhost network-scripts]# vim ifcfg-ens33
ONBOOT=yes

Change the network card mode of the VWmare virtual machine to NAT mode

Restart the network card

[root@localhost ~]# service network restart
Restarting network (via systemctl):                        [  OK  ]
[root@localhost ~]# 

Turn off SELinux and firewall

[root@localhost ~]# systemctl stop firewlld.service 
[root@localhost ~]# vim /etc/selinux/config
SELINUX=disable
[root@localhost ~]# reboot     # 重启Linux系统

yum update

[root@localhost ~]# yum clean all
Loaded plugins: fastestmirror, langpacks
Cleaning repos: base extras updates yum zabbix zabbix-non-supported
Cleaning up list of fastest mirrors
[root@localhost ~]# yum makecache
[root@localhost ~]# yum update
[root@localhost ~]# yum install gcc-c++ -y
[root@localhost ~]# yum install wget -y

Dependent packages that need to be prepared before installing Zabbix

[root@localhost ~]# ls | grep rpm*
centos-release-7-8.2003.0.el7.centos.x86_64.rpm
libssh2-devel-1.9.0-5.fc33.aarch64.rpm
openssl-libs-1.0.2k-19.el7.x86_64.rpm
php-devel-5.4.16-48.el7.x86_64.rpm
zabbix-agent-3.4.4-2.el7.x86_64.rpm
zabbix-get-3.4.4-2.el7.x86_64.rpm
zabbix-release-3.4-2.el7.noarch.rpm
zabbix-server-mysql-4.4.0-1.el7.x86_64.rpm
zabbix-server-mysql-4.4.1-1.el7.x86_64.rpm
zabbix-web-4.4.0-1.el7.noarch.rpm
[root@localhost ~]# ls | grep tar*
freetype-2.1.10.tar.gz
GD-2.18.tar.gz
libevent-2.1.12-stable.tar.gz
libgd-2.3.0.tar.gz
libmcrypt-2.5.8.tar.gz
libpng-1.2.8-config.tar.gz
zlib-1.2.11.tar.gz
[root@localhost ~]# 

Install Zabbix-release

[root@localhost ~]# rpm -ivh zabbix-release-3.4-2.el7.noarch.rpm 
warning: zabbix-release-3.4-2.el7.noarch.rpm: Header V4 RSA/SHA512 Signature, key ID a14fe591: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:zabbix-release-3.4-2.el7         ################################# [100%]
[root@localhost ~]#

Deploy the LAMP environment

Install Apache

[root@localhost ~]# yum install httpd
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
...............省略部分安装过程...............

Installed:
  httpd.x86_64 0:2.4.6-93.el7.centos                                            

Dependency Installed:
  httpd-tools.x86_64 0:2.4.6-93.el7.centos                                      

Complete!
[root@localhost ~]# 
[root@localhost ~]# systemctl start httpd
[root@localhost ~]# systemctl enable httpd

Install Mariadb database

[root@localhost ~]# yum install mariadb mariadb-server    # 安装 Mariadb数据库
[root@localhost ~]# systemctl start mariadb         # 启动 Mariadb数据库
[root@localhost ~]# systemctl enable mariadb
[root@localhost ~]# 
[root@localhost ~]# mysql_secure_installation       # 初始化 Mariadb
..............省略部分安装步骤...............
Enter current password for root (enter for none):  (当前数据库密码为空,直接敲回车)
OK, successfully used password, moving on...
​
Set root password? [Y/n] y   (设置root管理员的数据库密码)
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!
​
Remove anonymous users? [Y/n] y    (删除匿名账户)
 ... Success!
​
Disallow root login remotely? [Y/n] y    (禁止root从远程登录)
 ... Success!
​
Remove test database and access to it? [Y/n] y     (删除test数据库并取消对它的访问)
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!
​
Reload privilege tables now? [Y/n] y      (刷新授权表,使配置立即生效)
 ... Success!
​
Cleaning up...
​
Thanks for using MariaDB!
[root@localhost ~]# 

Install PHP and dependent packages

[root@localhost ~]# yum install -y php php-mysql httpd-manual mod_ssl php-gd php-xml php-mbstring php-ldap php-pear php-xmlrpc php-bcmath mysql-connector-odbc mysql-devel libdbi-dbd-mysql net-snmp-devel curl-devel unixODBC-devel OpenIPMI-devel java-devel libevent-devel freetype-devel
​
[root@localhost ~]# vim /etc/php.ini    # 修改 PHP配置文件(主要是修改时区,其它参数可以保持默认)
878 date.timezone = Asia/Shanghai
384 max_execution_time = 300
672 post_max_size = 16M
119 max_input_time = 300
405 memory_limit = 128M
1704 mbstring.func_overload = 1   (注释掉这一行)

Install Zabbix dependency packages

[root@localhost ~]# yum install -y curl curl-devel pcre pcre-devel libssh2-devel openldap-devel
...............省略部分安装步骤................
Installed:
  libssh2-devel.x86_64 0:1.8.0-3.el7   openldap-devel.x86_64 0:2.4.44-21.el7_6  
​
Dependency Installed:
  cyrus-sasl-devel.x86_64 0:2.1.26-23.el7                                       
​
Complete!
[root@localhost ~]#

Install Zabbix

[root@localhost ~]# rpm -ivh zabbix-server-mysql-4.4.0-1.el7.x86_64.rpm zabbix-get-3.4.4-2.el7.x86_64.rpm zabbix-agent-3.4.4-2.el7.x86_64.rpm zabbix-web-4.4.0-1.el7.noarch.rpm --nodeps --force
[root@localhost ~]# tar xf zabbix-3.4.8.tar.gz 
[root@localhost ~]# cd zabbix-3.4.8/
[root@localhost zabbix-3.4.8]# ./configure --prefix=/usr/local --sysconfdir=/etc/zabbix --enable-server --enable-proxy --enable-agent --enable-ipv6 --with-mysql=/usr/bin/mysql_config --with-net-snmp --with-libcurl --with-openipmi --with-unixodbc --with-ldap --with-ssh2 --enable-java
..................省略部分安装过程................
  Enable Java gateway:   yes
  Java gateway details:
    Java compiler:         javac
    Java archiver:         jar
​
  LDAP support:          yes
  IPv6 support:          yes
​
***********************************************************
*            Now run 'make install'                       *
*                                                         *
*            Thank you for using Zabbix!                  *
*              <http://www.zabbix.com>                    *
***********************************************************
​
[root@localhost zabbix-3.4.8]# 
[root@localhost zabbix-3.4.8]# make && make install    # 编译安装

Add services configuration (added by default)

[root@localhost zabbix-3.4.8]# vim /etc/services
zabbix-agent    10050/tcp               # Zabbix Agent
zabbix-agent    10050/udp               # Zabbix Agent
zabbix-trapper  10051/tcp               # Zabbix Trapper
zabbix-trapper  10051/udp               # Zabbix Trapper

Create Zabbix database and configure username and password

[root@localhost ~]# mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 10
Server version: 5.5.65-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)]> create database zabbix character set utf8;     (创建zabbix数据库并设置utf8字符集)
Query OK, 1 row affected (0.00 sec)
​
MariaDB [(none)]> grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix';  (创建用户和密码均为zabbix)
Query OK, 0 rows affected (0.01 sec)
​
MariaDB [(none)]> flush privileges;    (刷新权限)
Query OK, 0 rows affected (0.00 sec)
​
MariaDB [(none)]> quit
Bye
[root@localhost ~]#

Enter the Zabbix directory and import MySQL data

[root@localhost ~]# cd zabbix-3.4.8/database/mysql/
[root@localhost mysql]# ls
data.sql  images.sql  schema.sql
[root@localhost mysql]# mysql -u root -p123456 zabbix < ./schema.sql
[root@localhost mysql]# mysql -u root -p123456 zabbix < ./images.sql
[root@localhost mysql]# mysql -u root -p123456 zabbix < ./data.sql

Configure the Zabbix startup script, and set the startup to start

[root@localhost ~]# cd zabbix-3.4.8/
[root@localhost zabbix-3.4.8]# cp misc/init.d/fedora/core/zabbix_* /etc/init.d/
[root@localhost zabbix-3.4.8]# chmod 755 /etc/init.d/zabbix_*
[root@localhost zabbix-3.4.8]# sed -i "s#BASEDIR=/usr/local#BASEDIR=/usr/#g" /etc/init.d/zabbix_server
[root@localhost zabbix-3.4.8]# sed -i "s#BASEDIR=/usr/local#BASEDIR=/usr/#g" /etc/init.d/zabbix_agentd
[root@localhost zabbix-3.4.8]# 
[root@localhost zabbix-3.4.8]# chkconfig zabbix_server on
[root@localhost zabbix-3.4.8]# chkconfig zabbix_agentd on

Configure Zabbix_server.conf

[root@localhost zabbix-3.4.8]# vim /etc/zabbix/zabbix_server.conf
38 LogFile=/var/log/zabbix/zabbix_server.log
91 DBHost=localhost
100 DBName=zabbix
116 DBUser=zabbix
124 DBPassword=zabbix
131 DBSocket=/var/lib/mysql/mysql.sock
139 DBPort=3306
下面的参数可以保持默认
189 StartPollers=160
228 StartTrappers=20
236 StartPingers=100
244 StartDiscoverers=120
401 MaxHousekeeperDelete=5000
410 CacheSize=1024M
426 StartDBSyncers=16
435 HistoryCacheSize=1024M
453 TrendCacheSize=1024M
516 AlertScriptsPath=/usr/lib/zabbix/alertscripts
563 LogSlowQueries=1000

Configure zabbix_agentd.conf

[root@localhost zabbix-3.4.8]# vim /etc/zabbix/zabbix_agentd.conf
32 LogFile=/var/log/zabbix/zabbix_agentd.log
73 EnableRemoteCommands=0
97 Server=127.0.0.1,192.168.203.179
122 StartAgents=8
138 ServerActive=192.168.203.179:10051
149 Hostname=Zabbix
238 Timeout=30
267 Include=/etc/zabbix/zabbix_agentd.d
286 UnsafeUserParameters=1

Start zabbix_server and zabbix_agentd services

[root@localhost zabbix-3.4.8]# service zabbix_server start
Starting zabbix_server (via systemctl):                    [  OK  ]
[root@localhost zabbix-3.4.8]# service zabbix_agentd start
Starting zabbix_agentd (via systemctl):                    [  OK  ]
[root@localhost zabbix-3.4.8]# 

Configure zabbix_frontends front end

[root@localhost zabbix-3.4.8]# cp -r ./frontends/php/ /var/www/html/zabbix   # 复制frontend页面文件
[root@localhost zabbix-3.4.8]# chown -R apache.apache /var/www/html/zabbix
[root@localhost zabbix-3.4.8]# service httpd start

Configure Apache virtual host

[root@localhost ~]# vim /etc/httpd/conf/httpd.conf
113 <VirtualHost 192.168.203.179:80>  # 这里的IP地址可以用 * 号代替
114 ServerAdmin admin@zabbix
115 DocumentRoot /var/www/html/zabbix
116 ServerName zabbix
117 ErrorLog logs/dummy-zabbix-error_log
118 CustomLog logs/dummy-zabbix-access_log common
119 </VirtualHost>
[root@localhost ~]# systemctl restart httpd   # 重启 Apache

Enter the virtual host name configured above in the browser to enter the zabbix_frontend configuration installation interface

Enter the login interface, login account: Admin   password: zabbix

The idea of ​​dealing with the problem: I saw an error message after opening the Zabbix_server.log log file

connection to database 'zabbix' failed: [1040] Too many connections

(Translation: The connection to the database "zabbix" failed: [1040] Too many connections)

[root@localhost ~]# cd /var/log/zabbix/
[root@localhost zabbix]# ls
access_log  error_log  zabbix_agentd.log  zabbix_server.log
[root@localhost zabbix]# vim zabbix_server.log

Open the /var/log/zabbix/zabbix_server.log log file with vim command

solution:

1. Use the vim command to open the /etc/my.cnf configuration file and add the following parameters in the [mysqld] area

[root@localhost ~]# vim /etc/my.cnf
[mysqld]
max_connections=10000

2. Configure /usr/lib/systemd/system/mariadb.service to increase the number of open files

[root@localhost ~]# mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 221
Server version: 5.5.65-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)]> show variables like 'max_connections';
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| max_connections | 214   |
+-----------------+-------+
1 row in set (0.00 sec)
​
MariaDB [(none)]> quit
Bye
[root@localhost ~]# 
[root@localhost ~]# vim /usr/lib/systemd/system/mariadb.service
[Service]
LimitNOFILE=10000
LimitNPROC=10000
[root@localhost ~]# systemctl --system daemon-reload   # 重新加载系统服务
[root@localhost ~]# systemctl restart mariadb.service  # 重启 Mariadb服务
[root@localhost ~]# mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.65-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)]> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MariaDB [mysql]> set global max_connections=10000;
Query OK, 0 rows affected (0.00 sec)

MariaDB [mysql]> show variables like 'max_connections';
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| max_connections | 10000 |
+-----------------+-------+
1 row in set (0.00 sec)

MariaDB [mysql]> flush privileges;
Query OK, 0 rows affected (0.00 sec)

MariaDB [mysql]> show variables like 'max_connections';
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| max_connections | 9190  |
+-----------------+-------+
1 row in set (0.01 sec)
​
MariaDB [mysql]> quit
Bye
[root@localhost ~]# service zabbix_server restart
Restarting zabbix_server (via systemctl):                  [  OK  ]
[root@localhost ~]# service zabbix_agentd restart
Restarting zabbix_agentd (via systemctl):                  [  OK  ]
[root@localhost ~]#

Open the Zabbix service and run normally!

At this point, the Zabbix monitoring platform is set up!

Guess you like

Origin blog.csdn.net/C_huid/article/details/107808318