sdxh0506 发表于 2019-1-22 12:05:33

CentOS7.3 部署 Zabbix V3.2

  一、Zabbix安装部署
  系统环境:
  

  Linux: CentOS 7.3
  http:http/2.4
  MySQL:MariaDB 5.5
  PHP:5.5.38
  引用博客:http://www.cnblogs.com/xqzt/p/5124894.html
  

  1、安装配置源:
  

  http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.el7.noarch.rpm
  

  安装zabbix源和epel源:
  

  # https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
  # wget http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.el7.noarch.rpm
  # rpm -ivh epel-release-latest-7.noarch.rpm
  # rpm -ivh zabbix-release-3.2-1.el7.noarch.rpm
  

  2、安装Zabbix server and agent(agent是可选的)
  

  # yum install zabbix-server zabbix-web zabbix-web-mysql zabbix-agent zabbix-get
  

  # yum install zabbix-java-gateway
  

  

  3、 zabbix WEB环境搭建(LNMP环境搭建)
  

  http://www.unixmen.com/install-lamp-server-apache-mariadb-php-centosrhelscientific-linux-7/
  Install Apache:
  

  #yum install httpd   #已自动安装
  

  # systemctl start httpd
  # systemctl status httpd
  # netstat -anptul|grep httpd
  tcp6       0      0 :::80                   :::*                  LISTEN      2952/httpd
  # systemctl enable httpd
  

  Install MariaDB:
  # yum install mariadb-server mariadb -y
  # systemctl start mariadb
  # systemctl status mariadb
  # netstat -anptul|grep 3306
  tcp      0      0 0.0.0.0:3306            0.0.0.0:*               LISTEN      2800/mysqld
  # systemctl enable mariadb
  Set MySQL root password
  

  By default, MySQL root password is empty. So, to prevent unauthorized access to MySQL, let us set root user password. Enter the following command to setup mysql root user password:
  

  # 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):
  ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
  Enter current password for root (enter for none):
  ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
  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
  New password:
  Re-enter new password:
  Sorry, passwords do not match.
  

  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
   ... Success!
  

  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
   ... Success!
  

  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
   - Dropping test database...
   ... Success!
   - Removing privileges on test database...
   ... Success!
  

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

  Reload privilege tables now? y
   ... Success!
  

  Cleaning up...
  

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

  Thanks for using MariaDB!
  

  

  zabx@pass123$
  

  Install PHP:
  

  #yum install php php-mysql php-gd php-pear -y#已经自动安装
  

  Test PHP:
  

  Add the following lines:
  

  # vim /var/www/html/testphp.php
        # cat /var/www/html/testphp.php
  
  

  测试:http://172.16.*.*/testphp.php
  编辑 file /etc/httpd/conf.d/zabbix:
  

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

  设置时区:
  php_value date.timezone Asia/Shanghai
  

  4、设置数据库
  

  创建MySQL 数据库和用户:
  

  # mysql -uroot -p
  创建一个数据库‘zabbix’和数据库用户‘zabuser’
  

  MariaDB [(none)]> create database zabbix character set utf8;
     Query OK, 1 row affected (0.00 sec)
  

     MariaDB [(none)]> grant all privileges on zabbix.* to 'zabuser'@'localhost' identified by 'zabpass';
  Query OK, 0 rows affected (0.00 sec)
  

  MariaDB [(none)]> flush privileges;
     Query OK, 0 rows affected (0.00 sec)
  

     数据库导入zabbix template:
  

     # pwd
  /usr/share/doc/zabbix-server-mysql-3.2.7
  

     # zcat create.sql.gz |mysql -uzabuser -pzabpass zabbix
  

  5、配置Zabbix server
  

     编辑文件/etc/zabbix/zabbix_server.conf:
  

     # vim /etc/zabbix/zabbix_server.conf
  

     配置下面的三个参数:
  

  DBHost=localhost
  

  DBName=zabbix
  

  DBUser=zabuser
  

  DBPassword=zabpass
  # egrep -v "(^#|^$)" /etc/zabbix/zabbix_server.conf
  LogFile=/var/log/zabbix/zabbix_server.log
  LogFileSize=0
  PidFile=/var/run/zabbix/zabbix_server.pid
  DBHost=localhost
  DBName=zabbix
  DBUser=zabuser
  DBPassword=zabpass
  SNMPTrapperFile=/var/log/snmptrap/snmptrap.log
  CacheSize=128M
  Timeout=4
  AlertScriptsPath=/usr/lib/zabbix/alertscripts
  ExternalScripts=/usr/lib/zabbix/externalscripts
  LogSlowQueries=3000
  

  6、修改PHP 设置
  

     修改php.ini为zabbix 建议的设置:
  

     编辑文件 php.ini:
  

     # vim /etc/php.ini
  

     设置下面的参数:
  

     max_execution_time = 600
     max_input_time = 600
     memory_limit = 256M
     post_max_size = 32M
     upload_max_filesize = 16M
     date.timezone = Asia/Shanghai
  

  7、修改Firewall 和SELinux 设置
  

     开放zabbix端口10050 and 10051.
  

     firewall-cmd --permanent --add-port=10050/tcp
  

     firewall-cmd --permanent --add-port=10051/tcp
  

     重启firewall
  

     systemctl restart firewalld
  

  如果使用 SELinux, 运行以下命令使 Apache 可以和 Zabbix通信
  

  setsebool -P httpd_can_connect_zabbix=1
  

  8、允许Zabbix web console 对特定IP段可用 (可选)
  

  编辑文件 /etc/httpd/conf.d/zabbix.conf,
  

        vi /etc/httpd/conf.d/zabbix.conf
  

  添加允许访问 zabbix web interface的ip段. 如果设置 ‘Allow from All’, 这可         以允许全部可以访问
  复制代码
  

  #
  # Zabbix monitoring system php web frontend
  #
  

  Alias /zabbix /usr/share/zabbix
  

  
      Options FollowSymLinks
      AllowOverride None
      Require all granted
  

     
        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 date.timezone Asia/Shanghai
     
  
  

  
      Require all denied
  
  

  
      Require all denied
  
  

  9、启动zabbix-server 和zabbix-agent。重启httpd,,并设置zabbix-server和zabbix-agent开机自动启动
  

  # systemctl start zabbix-server
  # systemctl restart httpd
  # systemctl restart mariadb
  # systemctl enable zabbix-server
  

  10、通过控制台配置Zabbix
  

  http://172.16.*.*/zabbix/setup.php
  11、设置zabbix_agent
  

  # vim /etc/zabbix/zabbix_agentd.conf
  

  配置zabbix server 的ip
  

  Server=127.0.0.1,172.16.*.*
  ServerActive=127.0.0.1,172.16.*.*
  

  # egrep -v "(^#|^$)" /etc/zabbix/zabbix_agentd.conf
  PidFile=/var/run/zabbix/zabbix_agentd.pid
  LogFile=/var/log/zabbix/zabbix_agentd.log
  LogFileSize=0
  Server=127.0.0.1,172.16.*.*
  ServerActive=127.0.0.1,172.16.*.*
  Hostname=Zabbix server
  Include=/etc/zabbix/zabbix_agentd.d/*.conf
  

  # systemctl start zabbix-agent
  # systemctl status zabbix-agent
  

  # systemctl enable zabbix-agent
  

  

  12、添加客户机
  

  # wget http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.el7.noarch.rpm
  # rpm -ivh zabbix-release-3.2-1.el7.noarch.rpm
  # yum install zabbix-agent
  # vim /etc/zabbix/zabbix_agentd.conf
  

  Server=172.16.*.*
  ServerActive=172.16.*.*
  

  # systemctl start zabbix-agent
        # systemctl status zabbix-agent
  

        # systemctl enable zabbix-agent
  

  测试:
  

         # zabbix_get -s 172.16.*.* -k system.uname
         Linux jumpserver 3.10.0-514.21.1.el7.x86_64 #1 SMP Thu May 25 17:04:51 UTC 2017 x86_64
  改变端口号:
  # zabbix_get -s 172.16.*.* -p 10060 -k system.uname
  Linux db1 3.10.0-327.el7.x86_64 #1 SMP Thu Nov 19 22:10:57 UTC 2015 x86_64
  




页: [1]
查看完整版本: CentOS7.3 部署 Zabbix V3.2