• zabbix 在linux上安装以及一些配置


      本文章将演示zabbix 3.2版本的安装,供有需要的伙伴们参考:

    网络也有很多关于zabbix的安装文档,甚至每一步的配置都有详细的截图,我这里就不演示截图了,多配置几次自然就熟练了。多折腾。

    楼主也是安装过很多次,也安装过很多版本,每次都会遇到一点问题,还不一样,都可以通过网络上搜索解决。

    --环境准备

    [root@mysqlhq ~]# cat /etc/issue
    \nKylin 3.3
    Kernel \r on an \m
    \KRelease (Trial)

    # yum -y install lrzsz
    # groupadd zabbix
    # useradd -d /home/zabbix -g zabbix -m zabbix
    # passwd zabbix

    --安装相关依赖包

    # yum -y install wget unzip libxml2 libxml2-devel httpd php php-mysql php-common php-mbstring php-gd php-odbc \
    php-pear curl curl-devel net-snmp net-snmp-devel perl-DBI php-xml ntpdate php-bcmath zlib-devel glibc-devel \
    curl-devel gcc automake libidn-devel openssl-devel net-snmp-devel rpm-devel OpenIPMI-devel

    # tar zxvf zabbix-3.2.7.tar.gz 

    # cd zabbix-3.2.7

    # ./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --with-mysql=/usr/local/mysql/bin/mysql_config --with-net-snmp --with-libxml2 --with-libcurl #安装server

    # ./configure --prefix=/usr/local/zabbix --enable-agent #安装agent

    # make && make install

    --可能会遇到一些错误,都可以在网络上进行搜索解决

    --configure: error: Invalid Net-SNMP directory - unable to find net-snmp-config
    yum install -y net-snmp-devel

    --configure: error: no acceptable C compiler found in $PATH
    --yum install -y gcc

    --server mysql的配置

    mysql> create database zabbix default character set utf8;

    mysql> grant all privileges on *.* to 'zabbix'@'127.0.0.1' identified by '*';
    mysql> use zabbix;
    mysql> source /data/soft/zabbix-3.2.7/database/mysql/schema.sql
    mysql> source /data/soft/zabbix-3.2.7/database/mysql/images.sql
    mysql> source /data/soft/zabbix-3.2.7/database/mysql/data.sql

    --zabbix的zabbix_server.conf和zabbix_agentd.conf 文件

    [root@mysqlhq ~]# cat /usr/local/zabbix/etc/zabbix_server.conf | grep -v '^#' | grep -v '^$'
    LogFile=/tmp/zabbix_server.log
    DBHost=127.0.0.1
    DBName=zabbix
    DBUser=zabbix
    DBPassword=*
    DBSocket=/home/data/mysqldata/3306/mysqld.sock
    DBPort=3306
    Timeout=4
    LogSlowQueries=3000

    [root@mysqlhq ~]# cat /usr/local/zabbix/etc/zabbix_agentd.conf | grep -v '^#' | grep -v '^$'
    LogFile=/tmp/zabbix_agentd.log
    Server=*
    StartAgents=5
    ServerActive=*
    Hostname=mysqlhq
    UnsafeUserParameters=1
    UserParameter=mysql.ping,/usr/bin/mysqladmin -uzabbix -p*-h127.0.0.1 -P3306 2>/dev/null ping|grep alive|wc -l
    UserParameter=mysql.status[*],/usr/bin/mysql -h 127.0.0.1 -P3306 -uzabbix -p'*' -N -e "show global status where Variable_name='$1'" 2>/dev/null | cut -f2
    UserParameter=mysql_variable_status[*],/usr/bin/mysql -h 127.0.0.1 -P3306 -uzabbix -p*' -N -e "show variables where Variable_name='$1'" 2>/dev/null | cut -f2
    UserParameter=mysql.version,/usr/bin/mysql -V
    UserParameter=mysql.mysql_process_status,sh /usr/local/zabbix/lib/alertscripts/check_mysql_status_3306.sh

    --zabbix一些php,apach的设置

    cd /data/soft/zabbix-3.2.7/frontends
    mkdir /var/www/html/zabbix/
    cp -r php/* /var/www/html/zabbix/
    vim /etc/httpd/conf/httpd.conf
    ServerName *
    # cp /etc/php.ini /etc/php.ini.bk
    # sed -i 's/max_execution_time = 30/max_execution_time = 300/g' /etc/php.ini
    ---sed -i 'date.timezone =/a\date.timezone = Asia/Shanghai' /etc/php.ini
    # sed -i '/max_input_time =/s/60/300/' /etc/php.ini
    # sed -i '/mbstring.func_overload = 0/a\mbstring.func_overload = 1' /etc/php.ini
    # sed -i '/post_max_size =/s/8M/32M/' /etc/php.ini
    # sed -i "s@;date.timezone =@date.timezone = Asia/Shanghai@g" /etc/php.ini
    –PHP option "always_populate_raw_post_data" must be set to "-1"
    # vim /etc/ld.so.conf
    /usr/local/mysql/lib
    /sbin/ldconfig
    # ldconfig
    php -v
    [root@mysqlt1 yum.repos.d]# rpm -qa|grep php
    php56w-pdo-5.6.37-1.w6.x86_64
    php56w-ldap-5.6.37-1.w6.x86_64
    php56w-xml-5.6.37-1.w6.x86_64
    php56w-bcmath-5.6.37-1.w6.x86_64
    php56w-mysql-5.6.37-1.w6.x86_64
    php56w-cli-5.6.37-1.w6.x86_64
    php56w-5.6.37-1.w6.x86_64
    php56w-gd-5.6.37-1.w6.x86_64
    php56w-common-5.6.37-1.w6.x86_64
    php56w-mbstring-5.6.37-1.w6.x86_64

    --关于php的版本问题:

    # yum list installed | grep php
    # yum list | grep php;

    # yum remove php.x86_64 php-cli.x86_64 php-common.x86_64 php-gd.x86_64 php-ldap.x86_64 \
    php-mbstring.x86_64 php-mcrypt.x86_64 php-mysql.x86_64 php-pdo.x86_64

    #yum install php56w.x86_64 php56w-cli.x86_64 php56w-common.x86_64 php56w-gd.x86_64 php56w-ldap.x86_64 \
    php56w-mbstring.x86_64 php56w-mcrypt.x86_64 php56w-mysql.x86_64 php56w-pdo.x86_64

    rpm -ivh http://repo.webtatic.com/yum/el6/latest.rpm
    # rpm -Uvh https://mirror.webtatic.com/yum/el6/latest.rpm

    # yum install -y php56w php56w-gd php56w-mysql php56w-bcmath php56w-mbstring php56w-xml php56w-ldap

    [root@mysqlhq ~]# /usr/local/zabbix/sbin/zabbix_server --version
    zabbix_server (Zabbix) 3.2.7
    Revision 70298 18 July 2017, compilation time: Sep 19 2018 10:48:27

    #  chown -R zabbix.zabbix /usr/local/zabbix/
    # chown -R apache:apache /var/www/html/zabbix/
    #  rpm -qa|grep httpd
    # service httpd start

    # chkconfig --add httpd
    # chkconfig --list httpd

    # netstat -lnp |grep zabbix
    #  ps -ef|grep zabbix
    #  /usr/local/zabbix/sbin/zabbix_server -c /usr/local/zabbix/etc/zabbix_server.conf #启动zabbix server
    #  /usr/local/zabbix/sbin/zabbix_agentd -c /usr/local/zabbix/etc/zabbix_agentd.conf #启动zabbix agent

    --开启启动

    # vim /etc/rc.local
    sudo -i -u mysql /data/mysqldata/scripts/mysql_db_startup.sh 3306> /home/mysql/mysql_db_startup.log 2>&1
    /usr/local/zabbix/sbin/zabbix_server -c /usr/local/zabbix/etc/zabbix_server.conf
    /usr/local/zabbix/sbin/zabbix_agentd -c /usr/local/zabbix/etc/zabbix_agentd.conf
    Sudo命令如果遇到错误
    Sudo:sorry,you must have a tty to ruan sudo
    [root@localhost scripts]# vim /etc/sudoers
    56 #Defaults requiretty –注释掉

    --zabbix 中文配置

    1、确认zabbix是否开启了中文支持功能(/var/www/html/zabbix/include/locales.inc.php)
    vim /var/www/html/zabbix/include/locales.inc.php
    ###'zh_CN' => ['name' => _('Chinese (zh_CN)'), 'display' => true]
    2 登录zabbix后,设置用户profile,设置语言为中文,然后点击Update
    3 其他也乱码
    --这个问题是zabbix web端没有中文库导致
    从window-->控制面板-->字体-->选择一种中文字库例如“楷体”,将其拷贝到zabbix服务器上即可
    将我们选择的字体文件上传到zabbix web服务,/var/www/html/zabbix/fonts目录下
    修改此/var/www/html/zabbix/include/defines.inc.php文件中字体的配置,将里面关于字体设置从DejaVuSans替换成stsong
    vim /var/www/html/zabbix/include/defines.inc.php
    :%s/DejaVuSans/stsong/g

    --Zabbix server 基本配置

    -----create hosts
    Zabbix server 服务自带
    hostname=Zabbix server
    groups in groups =Zabbix servers
    ip address=*
    port=10050
    -----create Templates/MySql_check_alive/check_mysql_slave2_status
    template name=MySql_check_alive
    groups in groups=Zabbix servers
    ----create application
    group=Zabbix servers
    host=Zabbix server
    name=MySql_check_alive
    ----create Items/名字就是.cnf中的UserParameter=mysql.check_mysql_slave_status
    name=mysql.mysql_process_status
    type=zabbix agent
    key=mysql.mysql_process_status
    applications =MySql_check_alive

    ----create trigger
    name=mysql.mysql_process_status
    expression={Zabbix server:mysql.check_mysql_status.last()}=1
    --{check_mysql_slave2_status:mysql.check_mysql_slave_status.last()}=1

    -----create Templates
    template name=MySql_check_alive
    groups in groups=mysqltest
    hosts/template in=*
    ----create application/host=MySql_check_alive
    name=MySql_check_alive
    ----create Items
    name=mysql.mysql_process_status
    mysql.check_mysql_status
    type=zabbix agent
    key=mysql.mysql_process_status
    applications =my3306_check_status

    ----create trigger
    name=mysql.mysql_process_status on {HOST.NAME}
    expression={MySql_check_alive:mysql.mysql_process_status.last(0)}=1

    {*:mysql.mysql_process_status.last()}=1
    ---expression= SELECT *: mysql.check_mysql_status
    ---Previous value is =NO
    ---N=1
    ----create Screens
    点击configuration--screen--create screen

    serverity=high
    ----create Graphs
    name=mysql.mysql_process_status
    items=MySql_check_alive: mysql.mysql_process_status

    zabbix的告警流程
    host goups(设备组)--hosts(设备)--applications(监控项组)--
    items(监控项)--triggers(触发器)--actions(告警动作)--medias(
    告警方式)--user groups(用户组)--users(用户)
    1 trigger
    configureation--host/template--triggers--create trigger on {HOST.NAME}
    2 actions
    configureation--actions
    --event source-create action
    --action--name=send_email_to_user
    --recovery message=1
    --enabled=1
    --conditions--type of calculation= and/or
    --conditions=host group/trigger name
    --trigger value=problem 任何问题都会发送消息
    --maintenance status=not in maintenance在维护时间段内将不发送消息
    --operations--send message
    --send to user groups =dba
    --send to users=txyyhq
    --send only to=sendmail
    Default operation step duration 为60秒
    Steps 为3,表示触发3次动作 1-5-1200
    Send to User groups 选择Zabbix administrators
    Send to Users 选择 Admin (Zabbix Administrator)
    Send only to 选择 sendmail.sh
    --recovery operation

    3 media Administration-> Media types -> Create mediatype ->
    --administration--media type
    --create media type
    --name=sendmail
    --type=script
    --script name=sendemail.sh
    --Script parameters----3.2 需要自己添加3个参数,
    {ALERT.SENDTO}收件人地址
    {ALERT.SUBJECT}主题
    {ALERT.MESSAGE}详细内容
    在users里面添加,Administration –> Users-> Create user -> Media ->Add

    --administration--user--create user
    4 events
    --monitoring--events
    --administration--audit

    vim /usr/local/zabbix/lib/alertscripts/sendemail.sh $1 $2 $3 ###3个参数
    ./sendemail.sh *@163.com 1111 hello
    $1 收件人 user--media中的send to
    $2 为actions中配置的默认主题
    $3 为actions中默认的配置消息
    ##monitoring--triggers 看已发生故障
    ##查看日志administration--audit--actions
    ---Admin (Zabbix Administrator) sendmail Sent
    [zabbix@hqmysql1 alertscripts]$ ./sendemail.sh *@163.com 1111 hellotest
    Jul 19 01:56:24 hqmysql1 sendEmail[3551]: ERROR => Connection attempt to smtp.163.com:25 failed: IO::Socket::INET: Bad hostname 'smtp.163.com'

  • 相关阅读:
    Mac下安装Mysql
    事务隔离级别
    Mysql和Orcale的区别
    springboot的优点
    spring boot注解
    spring boot 常用注解
    java链接Mysql出现警告:Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by
    SpringApplication及banner的配置
    交叉编译
    qt下载和安装记录
  • 原文地址:https://www.cnblogs.com/yhq1314/p/9921354.html
Copyright © 2020-2023  润新知