CentOS7 Zabbix4.0

zabbix介绍

Zabbix 是一个基于 WEB 界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案。它能监视各种网络参数,保证服务器系统的安全运营;并提供灵活的通知机制以让系统管理员快速定位/解决存在的各种问题。

zabbix软件组成

  • zabbix-server: 监控服务端
  • zabbix-agent: 监控客户端
  • zabbix-web: 监控网站服务
  • php: 处理动态请求
  • mysql: 数据库存储监控数据
  • zabbix: 负责收集agent信息汇总告知zabbix-server

    关闭防火墙和selinux

    1. [root@zabbix ~]# setenforce 0
    2. [root@zabbix ~]# sed -ri '/^SELINUX=/cSELINUX=disabled' /etc/sysconfig/selinux
    3. [root@zabbix ~]# systemctl stop firewalld ; systemctl disable firewalld

    添加zabbix源和epel源

    1. ## 这里使用的是清华源
    2. [root@zabbix ~]# rpm -ivh https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm
    3. ## 添加epel源
    4. [root@zabbix ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

    安装zabbix和相关服务组件

    1. ## 把这两个包先拿下来,因为安装的时候网络问题会出现安装超时
    2. [root@zabbix ~]# wget https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/4.0/rhel/7/x86_64/{zabbix-server-mysql-4.0.20-1.el7.x86_64.rpm,zabbix-web-4.0.22-1.el7.noarch.rpm}
    3. ## 安装zabbix的服务程序和web程序
    4. [root@zabbix ~]# yum install -y httpd php zabbix-server-mysql-4.0.20-1.el7.x86_64.rpm zabbix-web-mysql
    5. ## 安装数据库服务
    6. [root@zabbix ~]# yum install -y mariadb-server

    修改zabbix配置文件

    1. ## 修改zabbix数据库密码为zabbix
    2. [root@zabbix ~]# sed -ri.bak '/# DBPassword=/cDBPassword=zabbix' /etc/zabbix/zabbix_server.conf
    3. ## 修改时区为国内
    4. [root@zabbix ~]# sed -ri.bak 's/ #(.*)date.timezone.*/\1date.timezone Asia\/Shanghai/' /etc/httpd/conf.d/zabbix.conf

    配置数据库服务

    1. ## 启动数据库
    2. [root@zabbix ~]# systemctl start mariadb
    3. ## 初始化数据库
    4. [root@zabbix ~]# mysql_secure_installation
    5. NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
    6. SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
    7. In order to log into MariaDB to secure it, we'll need the current
    8. password for the root user. If you've just installed MariaDB, and
    9. you haven't set the root password yet, the password will be blank,
    10. so you should just press enter here.
    11. Enter current password for root (enter for none):
    12. OK, successfully used password, moving on...
    13. Setting the root password ensures that nobody can log into the MariaDB
    14. root user without the proper authorisation.
    15. Set root password? [Y/n] y
    16. New password:
    17. Re-enter new password:
    18. Password updated successfully!
    19. Reloading privilege tables..
    20. ... Success!
    21. By default, a MariaDB installation has an anonymous user, allowing anyone
    22. to log into MariaDB without having to have a user account created for
    23. them. This is intended only for testing, and to make the installation
    24. go a bit smoother. You should remove them before moving into a
    25. production environment.
    26. Remove anonymous users? [Y/n] y
    27. ... Success!
    28. Normally, root should only be allowed to connect from 'localhost'. This
    29. ensures that someone cannot guess at the root password from the network.
    30. Disallow root login remotely? [Y/n] y
    31. ... Success!
    32. By default, MariaDB comes with a database named 'test' that anyone can
    33. access. This is also intended only for testing, and should be removed
    34. before moving into a production environment.
    35. Remove test database and access to it? [Y/n] n
    36. ... skipping.
    37. Reloading the privilege tables will ensure that all changes made so far
    38. will take effect immediately.
    39. Reload privilege tables now? [Y/n] y
    40. ... Success!
    41. Cleaning up...
    42. All done! If you've completed all of the above steps, your MariaDB
    43. installation should now be secure.
    44. Thanks for using MariaDB!
    45. [root@zabbix ~]# mysql -uroot -p ##登录数据库
    46. Enter password:
    47. Welcome to the MariaDB monitor. Commands end with ; or \g.
    48. Your MariaDB connection id is 8
    49. Server version: 5.5.65-MariaDB MariaDB Server
    50. Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
    51. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    52. MariaDB [(none)]> create database zabbix character set utf8 collate utf8_bin; ##创建zabbix数据库
    53. Query OK, 1 row affected (0.00 sec)
    54. MariaDB [(none)]> grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix'; ##创建数据库管理用户
    55. Query OK, 0 rows affected (0.00 sec)
    56. MariaDB [(none)]> quit
    57. Bye
    58. [root@zabbix ~]# zcat /usr/share/doc/zabbix-server-mysql-4.0.20/create.sql.gz | mysql -uzabbix -pzabbix zabbix ##将数据表写入到zabbix库中

    启动zabbix和相关服务

    1. [root@zabbix ~]# systemctl start zabbix-server.service httpd mariadb.service
    2. [root@zabbix ~]# systemctl enable zabbix-server.service httpd mariadb.service
    3. Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-server.service to /usr/lib/systemd/system/zabbix-server.service.
    4. Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
    5. Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.

    登录zabbix的web界面,进行初始化

    初始化地址http://172.16.210.56/zabbix/setup.php
    CentOS 7上搭建 Zabbix4.0 - 图1
    点击Next step
    CentOS 7上搭建 Zabbix4.0 - 图2
    检查php的一些变量条件,如果没有报错的信息可以点击next step
    CentOS 7上搭建 Zabbix4.0 - 图3
    填写好对应的数据库密码和帐号点击Next step
    CentOS 7上搭建 Zabbix4.0 - 图4
    设置主机和端口还有监控页面名字,然后点击Next step
    CentOS 7上搭建 Zabbix4.0 - 图5
    确认信息.然后点击Next step
    CentOS 7上搭建 Zabbix4.0 - 图6
    点击Finish
    CentOS 7上搭建 Zabbix4.0 - 图7
    帐号Admin 密码zabbix ,再点Sign in
    CentOS 7上搭建 Zabbix4.0 - 图8
    登录成功。

    更改zabbix界面语言为中文

    点击右上角的小人
    CentOS 7上搭建 Zabbix4.0 - 图9
    选择Chinese
    CentOS 7上搭建 Zabbix4.0 - 图10
    再点击update
    CentOS 7上搭建 Zabbix4.0 - 图11
    更改成功!