Cent OS 7.x 安装Zabbix

发布时间:2019-09-13 09:28:10编辑:auto阅读(1808)

    系统环境:

         VMware Workstation 12 Pro 12.5.0

    Cent OS 7.3_1611

    Zabbix 3.2

    ---以下操作均以root身份操作---

    1:设置网卡为开机启动

    Shell>ifconfig

    1.   [root@localhost ~]# ifconfig  

    2.   ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500  

    3.           inet 172.20.13.172  netmask 255.255.252.0  broadcast 172.20.15.255  

    4.           inet6 fe80::7ba8:6f74:fd63:7ca4  prefixlen 64  scopeid 0x20<link>  

    5.           inet6 fe80::3f6e:c838:e848:dc58  prefixlen 64  scopeid 0x20<link>  

    6.           inet6 fe80::bc3d:6b85:c582:cb27  prefixlen 64  scopeid 0x20<link>  

    7.           ether 00:0c:29:3b:62:7e  txqueuelen 1000  (Ethernet)  

    8.           RX packets 1211  bytes 106305 (103.8 KiB)  

    9.           RX errors 0  dropped 0  overruns 0  frame 0  

    10.         TX packets 327  bytes 47347 (46.2 KiB)  

    11.         TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0  

    其中ens33为需要修改的网卡名称

       Shell>vi /etc/sysconfig/network-scripts/ifcfg-ens33

       按 i 键进入输入模式,上下左右移动光标至ONBOOT项

       修改ONBOOT项为 yes,然后Shift+:进入命令模式输入 wq 回车

    2:关闭系统IPv6

    方法1(永久有效)

    Shell>vi /etc/sysctl.conf

    添加下面的行:

    net.ipv6.conf.all.disable_ipv6 =1   //禁用所有网卡的IPv6

    net.ipv6.conf.default.disable_ipv6 =1

    如果你想要为特定的网卡禁止IPv6,比如,对于ens33,添加下面的行。

    net.ipv6.conf.ens33.disable_ipv6 =1

    保存并退出文件。

    执行下面的命令来使设置生效。

    Shell>sysctl -p

    方法 2(重启失效)

    要在运行的系统中禁止IPv6,依次输入下面的命令:

    Shell>echo 1>/proc/sys/net/ipv6/conf/all/disable_ipv6
    Shell>echo 1>/proc/sys/net/ipv6/conf/default/disable_ipv6

    或者

    Shell>sysctl -w net.ipv6.conf.all.disable_ipv6=1
    Shell>sysctl -w net.ipv6.conf.default.disable_ipv6=1

    3:安装YUM源

    安装epel源

    Shell>rpm -Uvh         //命令大小写敏感

    (若提示传输错误可以使用WinSCP等FTP软件将rpm包上传至服务器中,然后使用rpm –Uvh 本地磁盘路径 方式安装)

    Shell>yum -y install epel-release
    Shell>yum repolist

    配置MariaDB的yum源:

    Shell>cd /etc/yum.repos.d
    Shell>vi mariaDB.repo

    添加以下内容:

    [mariadb]

    name=MariaDB

    baseurl=http://mirrors.ustc.edu.cn/mariadb/yum/10.1/rhel7-amd64

    gpgkey=https://mirrors.ustc.edu.cn/RPM-GPG-KEY-MariaDB

    gpgcheck=0

    [mariadb]

    name=MariaDB

    baseurl=http://yum.mariadb.org/10.1.22/centos7-amd64

    gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB

    gpgcheck=0

    保存退出

    4:安装Zabbix源文件

    Shell>cd /etc/yum.repos.d
    Shell>rpm -ivh http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.el7.noarch.rpm
    Shell>yum clean all
    Shell>yum update

    关闭Selinux

    Shell>cd /etc/selinux
    Shell>vi config

    SELINUX=enforcing改为disabled

    安装网络校时服务:

    Shell> yum install -y ntp
    Shell> ntpdate cn.ntp.org.cn

    CentOS初始配置完成,重启系统,准备安装Zabbix

    5:安装Zabbix

    依次执行以下命令:

    1.   Shell> yum install -y php php-gd php-mysql php-bcmath php-mbstring php-xml curl  

    2.   Shell>yum install -y curl-devel net-snmp gcc net-snmp-devel perl-DBI   

    3.   Shell>yum install -y OpenIPMI-devel openssl-devel libcurl-devel httpd fping  

    4.   Shell>yum install -y ntp ntpdate iksemel  

    5.   Shell>yum install -y zabbix-server zabbix-server-mysql zabbix-web-mysql  

    6.   Shell>yum install -y zabbix-web zabbix-get zabbix-java-gateway zabbix-sender zabbix-agent  

    7.   Shell>yum -y install MariaDB-client MariaDB-server MariaDB-devel  

    安装完成后,进行配置

    Shell>chkconfig mariadb on       //初始化MariaDB数据库等同于systemctl enable mariadb.service  开机启动MariaDB
    Shell>systemctl start mariadb   //启动MariaDB

    配置MariaDB数据库

     

    Shell>mysqladmin -uroot password passw0rd //设置数据库root用户密码为passw0rd
    Shell>mysql -uroot -ppassw0rd
    MariaDB [(none)]> create database zabbix character set utf8;
    MariaDB [(none)]> grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix';
    MariaDB [(none)]> flush privileges;
    MariaDB [(none)]> show databases;


    +--------------------+

    | Database           |

    +--------------------+

    | information_schema |

    | mysql              |

    | performance_schema |

    | test               |

    | zabbix             |

    +--------------------+

    MariaDB [(none)]>exit;
    Shell>cd /usr/share/doc/zabbix-server-mysql-3.2.7  //此处示例为3.2.7版本数据库
    Shell>zcat create.sql.gz | mysql -uzabbix -pzabbix zabbix
    Shell>vi /etc/zabbix/zabbix_server.conf

    修改以下几处并保存,或者直接删除DBHost和DBPassword去掉前面的#号保存也可

    DBHost=localhost

    DBName=zabbix

    DBUser=zabbix

    DBPassword=zabbix

    编辑时区配置

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

        <IfModule mod_php5.c>

            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 always_populate_raw_post_data -1

            # php_value date.timezone Europe/Riga

            php_value date.timezone Asia/Shanghai

    保存并退出

    接着启动各项服务

    Shell>chkconfig mariadb on  //初始化MariaDB数据库
    Shell>systemctl start mariadb  //启动MariaDB
    Shell>systemctl enable httpd.service   //HTTP服务开机启动
    Shell>systemctl start httpd.service     //启动HTTP
    Shell>systemctl start zabbix-server    //启动Zabbix-Server
    Shell>systemctl enable zabbix-server.service    //开机启动Zabbix-Server
    Shell>firewall-cmd --zone=public --add-service=http –permanent //添加HTTP服务至防火墙白名单
    Shell>systemctl restart firewalld                    //重启防火墙生效

    6:WEB配置:

    打开浏览器,输入http://ip/zabbix

    blob.png

    点击 下一步

    blob.png

    数据库检查通过,点击 下一步

    blob.png

    红色标记处是修改的 zabbix-server.conf的内容,填入数据库密码zabbix,点击下一步

    blob.png

    Name为自定义Zabbix服务器名称,可不填。点击下一步

    blob.png

    信息再次汇总显示通过,点击 下一步

    blob.png

    完成页面配置

    blob.png

    自动跳转至登录界面,用户名:Admin,初始密码:zabbix

    blob.png

    配置完成,Web登录界面

    --------------------------------------------------------------------------------------

    附加配置:

    中文字符异常

    Win+R打开运行,输入fonts,回车进入Windows字体目录,找到想替换的字体如:微软雅黑-常规字体,然后上传到/usr/share/zabbix/fonts

    上传成功后,编辑

    Shell>vi /usr/share/zabbix/include/defines.inc.php


    blob.png

    修改graphfont为msyh

    修改完成后,网页点击刷新,即可正常显示中文。

    Zabbix-agent配置

    接下来在zabbix-server服务器配置一个zabbix-agent监控服务器

    安装 zabbix-agent客户端

    Shell>yum install –y zabbix-agent

    进入目录/etc/zabbix/编辑zabbix-agent

    Shell>vi /etc/zabbix/zabbix_agentd.conf

    找到以下内容,并编辑

    Server=172.17.100.193   //若有多个zabbix服务器,后面用逗号分隔服务器IP,如果是本机就用默认的127.0.0.1

    ListenPort=10050   //监听端口号

    ListenIP=172.17.232.32   //监听的IP地址,这里填写为客户端的IP,如果是本机就用默认的127.0.0.1

    Hostname=自定义主机名   // Agent客户端的主机名,如果是本机,默认的即可

    然后修改 /etc/service

    Shell>vi /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

    手动启动zabbix-agent,并设置开机启动

    Shell> systemctl start zabbix-agent
    Shell>systemctl enable zabbix-agent





关键字