In my previous blog, I set up the zabbix monitoring service in the lamp architecture. In this article, I will build a zabbix service in lnmp. The operation steps are slightly more complex than before, however, lnmp is slightly more detailed, and the general process is similar.
Lab environment:
Stkaiti link: https://pan.baidu.com/s/1d6VpWcuQMQuaww4r_KZnNA
Extracted code: 90v8
Procedure
1. Establish lnmp
1 install nginx1.4
[[Email protected] ~] # Wget Protected] ~] # Rpm-IVH nginx-release-centos-7-0.el7.ngx.noarch.rpm # Install nginx official source [[email protected] ~] # Yum install nginx-y [[email protected] ~] # Systemctl start nginx [[email protected] ~] # Systemctl enable nginx [[email protected] ~] # Netstat-ntap | grep 80tcp 0 0 0.0.0.0: 80 0.0.0.0: * Listen 3024/nginx: Master
Access http: // 192.168.199.129/in a browser/
2. Install mysql5.7 (for ease of installation, I also use mariadb to replace mysql. The functions are the same ):
[[Email protected] ~] # Yum install mariadb-server mariadb-y # download the mariadb installation package [[email protected] ~] # Systemctl start mariadb. Service [[email protected] ~] # Systemctl enable mariadb. Service [[email protected] ~] # Mysql_secure_installation # configure the mariadb parameter set root password? [Y/n] yremove anonymous users? [Y/n] ndisallow root login remotely? [Y/n] nremove test database and access to it? [Y/n] nreload privilege tables now? [Y/n] y
3. Install php7.2
[[Email protected] ~] # Rpm-uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm?#email protected] ~] # Rpm-uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm # download phpyum source [[email protected] ~] # Yum install php72w php72w-devel php72w-fpm php72w-gd php72w-mbstring php72w-mysql-y # install PHP related services [[email protected] ~] # PHP-V # view PHP 7.2.10 (CLI) (built: Sep 15 2018 07:10:58) (ETS) Copyright (c) 1997-2018 the PHP groupzend engine v3.2.0, copyright (c) 1998-2018 Zend Technologies
4. Configure nginx to support PHP:
[[Email protected] ~] # Vim/etc/php-fpm.d/www. conf8 user = nginx # change Apache to nginx10 group = nginx # change Apache to nginx
5. Configure PHP:
[[Email protected] ~] # Vim/etc/PHP. ini359 expose_php = off # Hide PHP version 368 max_execution_time = 300 # Monitor execution time 378 max_input_time = 300 # receive data wait time 389 memory_limit = 128 M # Each script occupies 656 of memory post_max_size = 16 m # post data size 799 upload_max_filesize = 2 m # download file size 800 always_populate_raw_post_data =-1 # You can use $ http_raw_post_data to receive post raw datadate. timezone = Asia/Shanghai # set the time zone to Shanghai
6. Configure the PHP request to be sent to the backend PHP-FPM module. By default, the PHP configuration module is commented out:
[[Email protected] ~] # Vim/etc/nginx/CONF. d/Default. conf10 index. php index.html index.htm; 30 location ~ \. PHP ${31 root/usr/share/nginx/html; 32 fastcgi_pass 127.0.0.1: 9000; 33 fastcgi_index index. PHP; 34 fastcgi_param script_filename $ document_root $ fastcgi_scr ipt_name; 35 include fastcgi_params; 36} # change/scripts in fastcgi_param to $ document_root, and root is the PHP program user.
7. enable the Service
[[Email protected] ~] # Systemctl start php-fpm.service [[email protected] ~] # Systemctl enable php-fpm.service [[email protected] ~] # Systemctl restart nginx [[email protected] ~] # Vim/usr/share/nginx/html/index. php # create a PHP test homepage <? PHP phpinfo ();?>
Access http: // 192.168.199.129/index. php in a browser
Test whether PHP can connect to the database:
[[email protected] html]# vim index.php <?php$link=mysqli_connect(‘127.0.0.1‘,‘root‘,‘123123‘); if ($link) echo "true"; else echo "false";?>
8. Create a zabbix database and zabbix users:
[[email protected] html]# mysql -u root -pMariaDB [(none)]> create database zabbix character set utf8 collate utf8_bin;MariaDB [(none)]> grant all privileges on *.* to ‘zabbix‘@‘%‘ identified by ‘123123‘;MariaDB [(none)]> flush privileges;
Solve the problem of local login failure:
[[Email protected] ~] # Mysql-u zabbix-P # currently, zabbix users cannot log on to the database because they are using 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 | root | :: 1 | localhost | root | localhost | promote. cache-dns.local | root | promote. cache-dns.local | + -------- + ----------------------- + 7 rows in SET (0.00 Sec) mariadb [(none)]> drop user ''@ 'localhost'; # Delete empty user query in database OK, 0 rows affected (0.00 Sec) mariadb [(none)]> drop user ''@ 'promote. cache-dns.local '; # Delete empty user query OK, 0 rows affected (0.00 Sec)
Test whether zabbix users can connect to PHP:
[[email protected] ~]# vim /usr/share/nginx/html/index.php <?php$link=mysqli_connect(‘127.0.0.1‘,‘zabbix‘,‘123123‘); if ($link) echo "true"; else echo "false";?>
Access http: // 192.168.199.129/index. php in a browser
So far, the lamp architecture has been set up. The zabbix service will be deployed below.
2. Deploy zabbix Server:
[[Email protected] ~] # Rpm-I have protected] ~] # Yum install zabbix-server-mysql zabbix-web-mysql zabbix-agent-y [[email protected] ~] # Zcat/usr/share/doc/zabbix-server-mysql */create. SQL .gz | mysql-uzabbix-P zabbix # import the zabbix script file to the zabbix database [email protected] ~] # Mysql-u zabbix-pmariadb [(none)]> Use zabbixmariadb [zabbix]> show tables; # View tables in the zabbix database. If the script is imported successfully, you should see many tables.
To modify the zabbix configuration file, modify the following content:
[[Email protected] ~] # Grep-n' ^ '[A-Z]/etc/zabbix/zabbix_server.conf 38: logfile =/var/log/zabbix/zabbix_server.log49: logfilesize = 072: pidfile =/var/run/zabbix/zabbix_server.pid82: socketdir =/var/run/zabbix91: dbhost = localhost # Remove comment 101: dbname = zabbix117: dbuser = zabbix125: dbpassword = 123123 # Change Password 357: snmptrapperfile =/var/log/SNMPTRAP. log475: timeout = 4518: alertscriptspath =/usr/lib/zabbix/alertscripts529: externalscripts =/usr/lib/zabbix/externalscripts565: logslowqueries = 3000
Corrected Chinese garbled characters in the chart:
[[Email protected] ~] # Vim/usr/share/zabbix/include/defines. Inc. php
[[Email protected] zabbix] # cp stkaiti. TTF/usr/share/zabbix/fonts/# copy the corresponding font file from the Microsoft System to/usr/share/zabbix/fonts/
Grant file permissions:
[[email protected] ~]# cp -r /usr/share/zabbix/ /usr/share/nginx/html/[[email protected] ~]# chown -R zabbix.zabbix /etc/zabbix/[[email protected] ~]# chown -R zabbix.zabbix /usr/share/nginx/[[email protected] ~]# chown -R zabbix.zabbix /usr/lib/zabbix/[[email protected] ~]# chmod -R 755 /etc/zabbix/web/[[email protected] ~]# chmod -R 777 /var/lib/php/session/
Start the service:
[[Email protected] ~] # Systemctl start zabbix-server.service [[email protected] ~] # Systemctl enable zabbix-server.service [[email protected] ~] # Systemctl start zabbix-agent.service [[email protected] ~] # Systemctl enable zabbix-agent.service [[email protected] ~] # Systemctl restart php-fpm.service [[email protected] ~] # Systemctl restart nginx # these two services must be restarted. Otherwise, an error will occur when logging on to the zabbix monitoring page.
Log on to the zabbix page in the browser:
Version 4.0
Only OK is displayed for each item. If an error is reported, restart the PHP, nginx, and zabbix services. If any problem persists, check the configuration files of the three services.
Enter the password. The password is the password for zabbix to log on to the database. Keep the default port.
Enter the server name of zabbix, which is defined as zabbix.
Click Next to display the complete information of zabbix.
Click Next and you will see this information, which means you cannot create a configuration file. At this time, click the download link in the figure to download the file and mount the file to the zabbix server. The specific operations are as follows:
After you click Finish, the error message disappears.
Use the account password to log on to zabbix. The default account password is 'admin' and 'zabbix'
The zabbix monitoring page is displayed.
3. Configure the monitored Server:
[[email protected] ~]# systemctl stop firewalld.service [[email protected] ~]# setenforce 0
Download Yum Source:
[[email protected]~]# rpm -i https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm[[email protected] ~]# yum install zabbix-agent -y
To change the zabbix configuration file, you must change the following:
[[Email protected] ~] # Grep-n' ^ '[A-Z]/etc/zabbix/zabbix_agentd.conf 13: pidfile =/var/run/zabbix/zabbix_agentd.pid32: logfile =/var/log/zabbix/zabbix_agentd.log43: logfilesize = 098: Server = 192.168.199.129 # address pointing to zabbix monitoring terminal 139: serveractive = 192.168.199.129 # address pointing to zabbix monitoring terminal 150: hostname = test # define the server name 268: Include =/etc/zabbix/zabbix_agentd.d /*. conf
Enable the service:
[[Email protected] ~] # Systemctl start zabbix-agent.service [[email protected] ~] # Systemctl enable zabbix-agent.service [[email protected] ~] # Netstat-ntap | grep 10050 # view port. Note that the port to be monitored is 10050tcp 0 0 0.0.0.0: 10050 0.0.0.0: * Listen 38128/zabbix_agentd tcp6 0 0: 10050 ::: * Listen 38128/zabbix_agentd
So far, the zabbix service has been set up on lnmp. To monitor other servers, you must manually add the service on the browser monitoring page, I have explained in detail the process of adding zabbix monitoring service on the lamp architecture in my previous blog, so I will not proceed here.
Set up the zabbix monitoring service in the lnmp architecture !!!