centos7安装配置zabbix4.0

zabbix01    198.8.8.211    zabbix-server4.0

zabbix02    198.8.8.212    zabbix-agent4.0

一:zabbix服务端环境部署:

  1.1部署LAMP环境:zabbix中web监控管理界面,需要LNMP架构支持

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  

    1.1.1:配置httpd:

      ServerName zabbix01.zm.com:80

      <IfModule dir_module>
        DirectoryIndex index.html index.php
      </IfModule>

    1.1.2:配置php:

      date.timezone = PRC

    1.1.3:启动httpd,mysql

      关闭防火墙

      systemctl stop firewalld

      systemctl disabled firewalld

      关闭selinux

      setenforce 0

      getenforce

      vim /etc/sysconfig/selinux

      SELINUX=enforcing改为SELINUX=disabled

      reboot

      systemctl start httpd

      systemctl start mariadb

      netstat -ntap | grep '(80|3306)'

    mysql启动后执行初始安全设置:

      

[root@zabbix01 ~]# mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): \\回车
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] y
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] n
 ... skipping.

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] n
 ... skipping.

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] n
 ... skipping.

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] n
 ... skipping.

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

  

    1.1.4:创建测试页:

      [root@zabbix01 ~]# vim /var/www/html/index.php

<?php

phpinfo();

?>

:wq

     

       [root@zabbix01 ~]# mysql -u root -p

      MariaDB [(none)]> CREATE DATABASE zabbix character set utf8 collate utf8_bin; 

        //创建zabbix数据库(中文编码格式)

      MariaDB [(none)]> GRANT all  ON zabbix.* TO 'zabbix'@'%' IDENTIFIED BY 'zzz';

         //授予zabbix用户zabbix数据库的所有权限,密码zzz

      MariaDB [(none)]> flush privileges;

        //刷新权限

      MariaDB [(none)]> quit

      [root@zabbix01 ~]# vim /var/www/html/index.php

         //修改测试页内容,测试zabbix用户是否能够登陆数据库    

<?php
$link=mysql_connect('198.8.8.211','zabbix','zz');
if($link) echo "<h1>Success!!</h1>";
else echo "Fail!!";
mysql_close();
?>

      查询mysql用户:

        SELECT User, Host, Password FROM mysql.user;  

MariaDB [(none)]> select User, Host  FROM mysql.user;
+--------+-----------+
| User   | Host      |
+--------+-----------+
| zabbix | %         |
| root   | 127.0.0.1 |
| root   | ::1       |
|        | localhost |
| root   | localhost |
|        | zabbix01  |
| root   | zabbix01  |
+--------+-----------+
7 rows in set (0.00 sec)

        新建zabbix用户

MariaDB [(none)]> GRANT all ON zabbix.* TO 'zabbix'@'%' IDENTIFIED BY 'zzz';
MariaDB [(none)]> GRANT all ON zabbix.* TO 'zabbix'@'localhost' IDENTIFIED BY 'zzz';
MariaDB [(none)]> GRANT all ON zabbix.* TO 'zabbix'@'zabbix01' IDENTIFIED BY 'zzz';

  

MariaDB [(none)]> select user,host from mysql.user;
+--------+-----------+
| user   | host      |
+--------+-----------+
| zabbix | %         |
| root   | 127.0.0.1 |
| root   | ::1       |
|        | localhost |
| root   | localhost |
| zabbix | localhost |
|        | zabbix01  |
| root   | zabbix01  |
| zabbix | zabbix01  |
+--------+-----------+
9 rows in set (0.00 sec)
MariaDB [(none)]> flush privileges; 

      浏览器访问http://198.8.8.211/

       上图说明php连通数据库完成。

 

二:部署zabbix server:https://www.zabbix.com/download

  安装php支持的zabbix组件:

    [root@zabbix01 ~]# yum install php-bcmath php-mbstring -y

  yum源文件获取:

    [root@zabbix01 ~]# rpm -i https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm

  安装zabbix组件:

    [root@zabbix01 ~]# yum install zabbix-server-mysql zabbix-web-mysql -y

  自动生成数据库文件:

    [root@zabbix01 ~]# zcat /usr/share/doc/zabbix-server-mysql-4.0.1/create.sql.gz | mysql -u zabbix(用户名) -p zabbix(库名)

  修改zabbix配置文件:

    grep -n '^'[a-Z] /etc/zabbix/zabbix_server.conf

    vim /etc/zabbix/zabbix_server.conf

      ListenPort=10051

      LogFile=/var/log/zabbix/zabbix_server.log

      LogFileSize=0

      PidFile=/var/run/zabbix/zabbix_server.pid

      SocketDir=/var/run/zabbix

      DBName=zabbix

      DBUser=zabbix

      DBPassword=zzz

      DBPort=3306

      SNMPTrapperFile=/var/log/snmptrap/snmptrap.log

      ListenIP=198.8.8.211

      Timeout=4

      AlertScriptsPath=/usr/lib/zabbix/alertscripts

      ExternalScripts=/usr/lib/zabbix/externalscripts

      LogSlowQueries=3000

    

   修改zabbix在httpd中的时区:

    vim /etc/httpd/conf.d/zabbix.conf

    <IfModule mod_php5.c>
        php_value date.timezone Asia/Shanghai
        php_value max_execution_time 300
        php_value memory_limit 128M
        php_value post_max_size 16M
        php_value upload_max_filesize 2M
        php_value max_input_time 300
        php_value max_input_vars 10000
        php_value always_populate_raw_post_data -1
        # php_value date.timezone Europe/Riga
    </IfModule>

  

  启动zabbix及httpd服务:

    systemctl enable zabbix-server

    systemctl start zabbix-server

    netstat -anpt | grep zabbix 

    systemctl restart httpd.service

  web界面访问:

    http://198.8.8.211/zabbix/

 

 

 

 

 

 

 

设置中文:Administrator-Users-Admin-Language

 

web界面乱码:


方法一:

       如web界面中文乱码,需要复制相应文字,使zabbix识别

  下载STKAITI.TTF字体拷贝到如下路径:

    cp STKAITI.TTF /usr/share/zabbix/fonts/

  使zabbix系统识别字体

    vim /usr/share/zabbix/include/defines.inc.php

     :%s /graphfont/kaiti/g //采用全局替换模式

方法二:

  复制C:\Windows\Fonts下的简黑字体

   

 

  拷贝到/usr/share/fonts/dejavu/simhei.ttf

  进入/etc/alternatives

   删除名为zabbix-web-font的软连接

  重建软连接:

    ln -s /usr/share/fonts/dejavu/simhei.ttf zabbix-web-font

 

登陆后报错:

正常安装完zabbix后,登录后zabbix监控报错zabbix server is not running: the information displayed may not be current

[root@zabbix zabbix]# find / -name zabbix.conf.php
/etc/zabbix/web/zabbix.conf.php
[root@zabbix zabbix]# vim /etc/zabbix/web/zabbix.conf.php

<?php
// Zabbix GUI configuration file.
global $DB;

$DB['TYPE']     = 'MYSQL';
$DB['SERVER']   = '192.168.8.8';
$DB['PORT']     = '3306';
$DB['DATABASE'] = 'zabbix01';
$DB['USER']     = 'zabbix01';
$DB['PASSWORD'] = 'z';

// Schema name. Used for IBM DB2 and PostgreSQL.
$DB['SCHEMA'] = '';

$ZBX_SERVER      = '192.168.8.8';
$ZBX_SERVER_PORT = '10051';
$ZBX_SERVER_NAME = 'Zabbix01';

$IMAGE_FORMAT_DEFAULT = IMAGE_FORMAT_PNG;

 

如还报错:

netstat -lnp | zabbix

查看端口10051是否开启

如未开启:

vi /etc/zabbix/zabbix_server.conf

DBHost=x.x.x.x

重启zabbix-server:

systemctl status zabbix-server

 

三:配置被监控端-如果监控服务器需要监控自己,也需要安装配置:

  CentOS7添加方法:

  3.1安装zabbix-agent客户端

  3.1.1配置zabbix yum源:

     rpm -i https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm

  3.1.2安装客户端:

    yum install -y zabbix-agent

  3.1.3修改agent配置文件:

    [root@zabbix02 ~]# vim /etc/zabbix/zabbix_agentd.conf 

      PidFile=/var/run/zabbix/zabbix_agentd.pid

      LogFile=/var/log/zabbix/zabbix_agentd.log

      LogFileSize=0

      Server=198.8.8.211

      ListenPort=10050

      ServerActive=198.8.8.211

      Hostname=zabbix01

      Include=/etc/zabbix/zabbix_agentd.d/*.conf

  3.1.4 关闭防火墙

      [root@zabbix02 ~]# systemctl stop firewalld

  3.1.5 关闭selinux

      [root@zabbix02 ~]# setenforce 0

      [root@zabbix02 ~]# vim /etc/selinux/config

#SELINUX=enforcing
SELINUX=disabled

  3.1.6启动zabbix-agent

      [root@zabbix02 ~]# systemctl start zabbix-agent.service

      [root@zabbix02 ~]# systemctl enable zabbix-agent.service

 

  Windows添加方法:

    官方安装方法:

      https://www.zabbix.com/download

    下载windows包:

      https://www.zabbix.com/download_agents

      zabbix_agents-4.0.0-win-amd64

    解压后得到bin和conf两个文件夹:

    修改配置文件D:\Program Files\Zabbix\conf\zabbix_agentd.win.conf

      修改下面几项 

      EnableRemoteCommands=1 #允许在本地执行远程命令 
      LogRemoteCommands=1 #执行远程命令是否保存操作日志 
      Server = 172.16.20.90 #填写zabbix服务器IP地址 
      ListenPort=10050
      Hostname= Zabbix server #zabbix_agent监控服务器名称 (监控主机名称) 
      Log=c:\zabbix_agentd.log 
      ServerActive=172.16.20.90 #填写zabbix服务器IP地址


    
新建cmd快捷方式,以管理员身份运行

    安装zabbix客户端:

      d:\program files\zabbix\bin\zabbix_agentd.exe -i -c d:\program files\zabbix\conf\zabbix_agentd.win.conf

    中间不可有空格:

      d:\zabbix\bin\zabbix_agentd.exe -i -c d:\zabbix\conf\zabbix_agentd.win.conf

    启动zabbix客户端:

      d:\zabbix\bin\zabbix_agentd.exe -s -c d:\zabbix\conf\zabbix_agentd.win.conf

C:\Windows\system32>d:\program files\zabbix\bin\zabbix_agentd.exe -i -c d:\program files\zabbix\conf\zabbix_agentd.win.conf
'd:\program' 不是内部或外部命令,也不是可运行的程序
或批处理文件。

C:\Windows\system32>d:\zabbix\bin\zabbix_agentd.exe -i -c d:\zabbix\conf\zabbix_agentd.win.conf
zabbix_agentd.exe [5640]: service [Zabbix Agent] installed successfully
zabbix_agentd.exe [5640]: event source [Zabbix Agent] installed successfully

C:\Windows\system32>d:\zabbix\bin\zabbix_agentd.exe -s -c d:\zabbix\conf\zabbix_agentd.win.conf
zabbix_agentd.exe [7624]: service [Zabbix Agent] started successfully

  

 

 

 

四:在zabbix服务器添加被监控机      

   4.1创建主机:

     配置-主机-创建主机

 

 

 

 

五:报警配置:

  5.1邮件报警:

    [root@zabbix01 ~]# yum install mailx -y

    [root@zabbix01 ~]# vim /etc/mail.rc

    添加:

set from=xxx@163.com
set smtp=smtp.163.com
set smtp-auth-user=xxx@163.com
set smtp-auth-password=123456
set smtp-auth=login

    测试邮件发送:

[root@zabbix01 ~]# echo 'hello' | mail -s 'testmail' zm_cm@163.com

  5.2设置邮件发送脚本:

[root@zabbix01 ~]# vim /usr/lib/zabbix/alertscripts/mailx.sh

  

#!/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/

  添加可执行权限:

[root@zabbix01 ~]# chmod +x /usr/lib/zabbix/alertscripts/mailx.sh

  测试发件:

[root@zabbix01 ~]# /usr/lib/zabbix/alertscripts/mailx.sh zm_cm@163.com  '111''222'

  5.3配置zabbix自动触发脚本

 

 

 

 

告警主机:{HOST.NAME}
告警IP:{HOST.IP}
告警时间:{EVENT.DATE}-{EVENT.TIME}
告警等级:{TRIGGER.SEVERITY}
告警信息:{TRIGGER.NAME}:{ITEM.VALUE}
事件ID:{EVENT.ID}

持续时间需改为60s,否则会报错:字段 "esc_period": 必须在 "60" 和 "604800" 之间 值错误。

 

 

 

 六:监控脚本配置

   6.1 io监控脚本:

UserParameter=custom.vfs.dev.read.ops[*],cat /proc/diskstats | grep $1 | head -1 | awk '{print $$4}' //磁盘读的次数 
UserParameter=custom.vfs.dev.read.ms[*],cat /proc/diskstats | grep $1 | head -1 | awk '{print $$7}' //磁盘读的毫秒数
UserParameter=custom.vfs.dev.write.ops[*],cat /proc/diskstats | grep $1 | head -1 | awk '{print $$8}' //磁盘写的次数
UserParameter=custom.vfs.dev.write.ms[*],cat /proc/diskstats | grep $1 | head -1 | awk '{print $$11}' //磁盘写的毫秒数
UserParameter=custom.vfs.dev.io.active[*],cat /proc/diskstats | grep $1 | head -1 | awk '{print $$12}'
UserParameter=custom.vfs.dev.io.ms[*],cat /proc/diskstats | grep $1 | head -1 | awk '{print $$13}' //花费在IO操作上的毫秒数
UserParameter=custom.vfs.dev.read.sectors[*],cat /proc/diskstats | grep $1 | head -1 | awk '{print $$6}' //读扇区的次数(一个扇区的等于512B)
UserParameter=custom.vfs.dev.write.sectors[*],cat /proc/diskstats | grep $1 | head -1 | awk '{print $$10}' //写扇区的次数(一个扇区的等于512B)

  6.2 重启zabbix-agent服务

    [root@zabbix01 ~]# systemctl restart zabbix-agent

  6.3 登陆web页面添加模板

 

七:zabbix-server主机ip修改后web报错

  7.1:修改 vim /etc/zabbix/zabbix_server.conf 中ip

  7.2:修改 vim /etc/zabbix/web/zabbix.conf.php 中ip

<?php
// Zabbix GUI configuration file.
global $DB;

$DB['TYPE']     = 'MYSQL';
$DB['SERVER']   = '192.168.1.6';
$DB['PORT']     = '3306';
$DB['DATABASE'] = 'zabbix01';
$DB['USER']     = 'zabbix01';
$DB['PASSWORD'] = 'xxxxxx';

// Schema name. Used for IBM DB2 and PostgreSQL.
$DB['SCHEMA'] = '';

$ZBX_SERVER      = '192.168.1.6';
$ZBX_SERVER_PORT = '10051';
$ZBX_SERVER_NAME = 'zabbix01';

$IMAGE_FORMAT_DEFAULT = IMAGE_FORMAT_PNG;

 

 

 

参考:

https://blog.csdn.net/rujianxuezha/article/details/79842998

https://www.linuxidc.com/Linux/2018-10/154773.htm

转载于:https://www.cnblogs.com/jackyzm/p/9907819.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
下载zabbix server源码包 `wget -o zabbix-4.0.4.tar.gz <https://sourceforge.net/projects/zabbix/files/ZABBIX Latest Stable/4.0.4/zabbix-4.0.4.tar.gz/download`> 安装依赖 `yum install wget telnet net-tools python-paramiko gcc gcc-c++ dejavu-sans-fonts python-setuptools python-devel sendmail mailx net-snmp net-snmp-devel net-snmp-utils freetype-devel libpng-devel perl unbound libtasn1-devel p11-kit-devel OpenIPMI unixODBC libevent-devel mysql-devel libxml2-devel libssh2-devel OpenIPMI-devel java-1.8.0-openjdk-devel openldap-devel curl-devel unixODBC-devel` 解压并编译安装 `tar -zxvf zabbix-4.0.4.tar.gz` `cd zabbix-4.0.4/` 建立编译安装目录 `mkdir -p /data/zabbix` `./configure --prefix=/data/zabbix --enable-server --enable-agent --enable-java --with-mysql --with-libxml2 --with-unixodbc --with-net-snmp --with-ssh2 --with-openipmi --with-ldap --with-libcurl --with-iconv` `make&&make; install` `/data/zabbix/sbin/zabbix_server -V` 数据库安装 `yum install mariadb-server` `systemctl start mariadb.service` `systemctl status mariadb.service` `mysql_secure_installation` 创建zabbix数据库 `mysql -uroot -p` `create database zabbix character set utf8 collate utf8_bin;` `grant all privileges on zabbix.* to zabbix@localhost identified by ‘123456’;` 导入zabbix数据结构 `mysql -uzabbix -p123456 zabbix < /root/zabbix-4.0.4/database/mysql/schema.sql` `mysql -uzabbix -p123456 zabbix < /root/zabbix-4.0.4/database/mysql/images.sql` `mysql -uzabbix -p123456 zabbix < /root/zabbix-4.0.4/database/mysql/data.sql` 更改zabbix-server配置文件 `[root@localhost ~]# egrep -v "^#|^$" /data/zabbix/etc/zabbix_server.conf` `LogFile=/tmp/zabbix_server.log` `DBHost=localhost` `DBName=zabbix` `DBUser=zabbix` `DBPassword=123456` `Timeout=4` 增加用户 `groupadd --system zabbix` `useradd --system -g zabbix -d /usr/lib/zabbix -s /sbin/nologin -c "Zabbix Monitoring System" Zabbix` 启动zabbix server `/data/zabbix/sbin/zabbix_server -c /data/zabbix/etc/zabbix_server.conf` 启动zabbix agent `/data/zabbix/sbin/zabbix_agentd -c /data/zabbix/etc/zabbix_agentd.conf` 安装Zabbix Agent `yum install zabbix-agent` `systemctl start zabbix-agent.service` 安装zabbix前端 `rpm -ivh <https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm>` `yum -y install zabbix-web-mysql` `egrep -v “^#|^$” /etc/php.ini` `max_execution_time = 300` `memory_limit = 128M` `post_max_size = 16M` `upload_max_filesize = 2M` `max_input_time = 300` `max_input_vars = 10000` `always_populate_raw_post_data = -1` `date.timezone = Asia/Shanghai` `` 启动httpd `systemctl start httpd.service` `systemctl status httpd.service` 访问 http://webIP/zabbix/setup.php 默认账号密码 Admin zabbix
好的,下面是 CentOS6.5 源码安装 zabbix4.0 的步骤: 1. 安装编译工具和依赖库: ``` yum install gcc gcc++ make automake autoconf libtool openssl openssl-devel net-snmp net-snmp-devel libcurl libcurl-devel ``` 2. 下载并解压 zabbix 源码包: ``` wget https://cdn.zabbix.com/zabbix/sources/stable/4.0/zabbix-4.0.0.tar.gz tar zxvf zabbix-4.0.0.tar.gz ``` 3. 进入源码目录,执行 configure 脚本: ``` cd zabbix-4.0.0 ./configure --enable-server --enable-agent --with-mysql --with-net-snmp --with-libcurl --prefix=/usr/local/zabbix ``` 4. 编译并安装 zabbix: ``` make make install ``` 5. 配置 zabbix server: 创建 zabbix 用户和用户组: ``` groupadd zabbix useradd -g zabbix zabbix ``` 创建 zabbix server 配置文件: ``` cp /usr/local/zabbix/etc/zabbix_server.conf.example /usr/local/zabbix/etc/zabbix_server.conf ``` 修改配置文件中的数据库信息: ``` DBName=zabbix DBUser=zabbix DBPassword=password ``` 6. 启动 zabbix server: ``` /usr/local/zabbix/sbin/zabbix_server ``` 7. 配置 zabbix agent: 创建 zabbix agent 配置文件: ``` cp /usr/local/zabbix/etc/zabbix_agentd.conf.example /usr/local/zabbix/etc/zabbix_agentd.conf ``` 修改配置文件中的服务器信息: ``` Server=127.0.0.1 ServerActive=127.0.0.1 ``` 8. 启动 zabbix agent: ``` /usr/local/zabbix/sbin/zabbix_agentd ``` 9. 配置 zabbix web: 将 zabbix web 目录复制到 web 服务器的根目录下: ``` cp -r /usr/local/zabbix/share/zabbix /var/www/html/ ``` 修改 zabbix web 配置文件: ``` cp /var/www/html/zabbix/conf/zabbix.conf.php.example /var/www/html/zabbix/conf/zabbix.conf.php ``` 修改配置文件中的数据库信息: ``` $DB['DATABASE'] = 'zabbix'; $DB['USER'] = 'zabbix'; $DB['PASSWORD'] = 'password'; $DB['SERVER'] = 'localhost'; $DB['PORT'] = '3306'; ``` 10. 访问 zabbix web: 在浏览器中访问 `http://your-server-ip/zabbix`,输入默认用户名和密码 `Admin/zabbix`,即可登录 zabbix web。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值