zabbix theory + operation-02 (zabbix deployment + email alarm)
Experimental environment
Monitoring end: 192.168.136.168
Monitored end: 192.168.136.185
Install LAMP
yum install -y \ httpd \ mariadb-server mariadb \ php \ php-mysql \ php-gd \ libjpeg* \ php-ldap \ php-odbc \ php-pear \ php-xml \ php-xmlrpc \ php-mhash
vim /etc/httpd/conf/httpd.conf ServerName www.benet.com DirectoryIndex index.html index.php vi /etc/php.ini date.timezone = PRC //Set China time zone systemctl stop firewalld.service setenforce 0 systemctl start httpd.service systemctl start mariadb.service netstat -ntap | egrep '(80|3306)' mysql_secure_installation vi /var/www/html/index.php <?php phpinfo(); ?>
mysql -u root -p #Set up a database for zabbix and a user to manage it CREATE DATABASE zabbix character set utf8 collate utf8_bin; GRANT all privileges ON *.* TO 'zabbix'@'%' IDENTIFIED BY 'admin123'; flush privileges; #Write a test Homepage [root@localhost ~]# cd /var/www/html/ [root@localhost html]# vim index.php <?php phpinfo(); ?> #Verify zabbix can connect to the database <?php $link=mysql_connect('192.168.136.167','zabbix','admin123'); if($link) echo "<h1>Success!!</h1>"; else echo "Fail!!"; mysql_close(); ?>
---------Solve the problem of local login failure (can be ignored)---------------
[root@localhost html]# mysql -u root -p Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 9 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; //There is an empty user name occupation, which results in local failure to log in and remote login +--------+-----------------------+ | user | host | +--------+-----------------------+ | zabbix | % | | root | 127.0.0.1 | | root | ::1 | | | localhost | | root | localhost | | | localhost.localdomain | +--------+-----------------------+ 6 rows in set (0.01 sec) drop user ''@localhost; drop user ''@cacti; flush privileges;
----------------Start to deploy zabbix Server-------
yum install php-bcmath php-mbstring -y rpm -ivh http://Repo. ZABBIX. COM / ZABBIX / 3.5 / RHEL / 7 / x86 ʄ / zabbix-release-3.5-1.el7. Noarch. RPM / / will automatically generate the yum source file to ensure that the system can access the Internet yum install zabbix-server-mysql zabbix-web-mysql -y zcat /usr/share/doc/zabbix-server-mysql-4.0.0/create.sql.gz | mysql -uzabbix -p zabbix //Generate the database file, pay attention not to enter the password as root grep -n '^'[a-Z] /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 101:DBName=zabbix 117:DBUser=zabbix 125:DBPassword=admin123 //Revise our bank 347:SNMPTrapperFile=/var/log/snmptrap/snmptrap.log 465:Timeout=4 507:AlertScriptsPath=/usr/lib/zabbix/alertscripts 517:ExternalScripts=/usr/lib/zabbix/externalscripts 553:LogSlowQueries=3000 vim /etc/httpd/conf.d/zabbix.conf //Modify time zone php_value date.timezone Asia/Shanghai vim /usr/share/zabbix/include/defines.inc.php //Correction of Chinese characters in charts :%s /graphfont/kaiti/g //Copy the corresponding font file from Microsoft system to / usr/share/zabbix/fonts directory. Note that the font name should correspond to the configuration file, and pay attention to case cp STKAITI.TTF /usr/share/zabbix/fonts/ systemctl enable zabbix-server systemctl start zabbix-server netstat -anpt | grep zabbix //Listening on port 10051 systemctl restart httpd.service
http://192.168.136.168/zabbix/ //Login user name after installation Admin Password: zabbix
Set up Chinese environment Administrator users click user settings in language
-----------Configure the proxy - the server under control - and install the ZABBIX agent if the server needs to be monitored by itself--
rpm -ivh http://repo.zabbix.com/zabbix/3.5/rhel/7/x86_64/zabbix-release-3.5-1.el7.noarch.rpm yum install -y zabbix-agent grep -n '^'[a-Z] /etc/zabbix/zabbix_agentd.conf 13:PidFile=/var/run/zabbix/zabbix_agentd.pid 32:LogFile=/var/log/zabbix/zabbix_agentd.log 43:LogFileSize=0 98:Server=192.168.175.155 139:ServerActive=192.168.175.155 150:Hostname=test 268:Include=/etc/zabbix/zabbix_agentd.d/*.conf service firewalld stop setenforce 0 systemctl enable zabbix-agent.service systemctl restart zabbix-agent.service netstat -anpt | grep zabbix //Listening on port 10050 ---------------Add controlled host--stay WEB Doing on the platform----- //Configuration host create host: //Host page is configured according to requirements //Template page needs to link template, and link corresponding template as required 0K
--------Configure mail alarm function---Configuration on server--------- yum install mailx vi /etc/mail.rc //Note that Netease email needs to open client authorization code for third-party login ----Add at the end of the file--- set from=1960277503@qq.com set smtp=smtp.qq.com set smtp-auth-user=1960277503@qq.com set smtp-auth-password=Mailbox password set smtp-auth=login echo "hello world" | mail -s "testmail" 1960277503@qq.com //Normal test sending cd /usr/lib/zabbix/alertscripts vi mailx.sh //Script outgoing messages #!/bin/bash #send mail messages=`echo $3 | tr '\r\n' '\n'` subject=`echo $2 | tr '\r\n' '\n'` echo "${messages}" | mail -s "${subject}" $1 >>/tmp/mailx.log 2>&1 ------ touch /tmp/mailx.log chown -R zabbix.zabbix /tmp/mailx.log chmod +x /usr/lib/zabbix/alertscripts/mailx.sh chown -R zabbix.zabbix /usr/lib/zabbix/ ./mailx.sh 13951868284@139.com "theme" "content" //Test whether the sending script works properly
-----Configure on server WEB----
Management > alarm media type > create media type Name: mail test Type: Script Script name: mailx.sh Script parameters: / / add the following three parameters {ALERT.SENDTO} {ALERT.SUBJECT} {ALERT.MESSAGE} Admin user click admin alarm media: Type: mail test / / call the above script Attention: 13951868284@139.com Other defaults - save Configuration action create action delete default label modify trigger condition Name: Mailx Condition A host group = Linux servers Operation - "configuration as follows Default operation step duration 60 Default recipient: {TRIGGER.STATUS}:{TRIGGER.NAME} Default information: Alarm host: {HOST.NAME} Alarm IP: {HOST.IP} Alarm time: {EVENT.DATE}-{EVENT.TIME} Alarm level: {TRIGGER.SEVERITY} Alarm information: {TRIGGER.NAME}:{ITEM.VALUE} Event ID: {EVENT.ID} Operation details: -- Action type: send message Send to user: Admin (Zabbix Administrator) Send only to: mail test / / be sure to configure or the mail will not be sent successfully Recovery operation: {TRIGGER.STATUS}:{TRIGGER.NAME} Recovery information: Recovery host: {HOST.NAME} Recovery IP: {HOST.IP} Recovery time: {EVENT.DATE}-{EVENT.TIME} Recovery level: {TRIGGER.SEVERITY} Recovery information: {TRIGGER.NAME}:{ITEM.VALUE} Recovery ID: {EVENT.ID} Operation details: -- Action type: send message Send to user: Admin (Zabbix Administrator) Send only to: mail test / / be sure to configure or the mail will not be sent successfully systemctl restart zabbix-server systemctl restart zabbix-agent.service ------The following are test alarms----- It can simulate that the relevant parameters, such as disk space, exceed the threshold value on the controlled host. Then verify the email. systemctl stop zabbix-agent.service / / turn off test alarm email reception on the monitored host