zabbix源碼包安裝4.2

運用的是centos 7.5 1804  【該文章記錄分兩個安裝方式,自行選擇】

安裝環境:nginx;php;mysql;zabbix Server;配置zabbix web。

1.安裝 nginx

     1.1 安裝依賴軟件包。

          yum  -y  install  wget  gcc  gcc-c++make pcre  pcre-devel zlib zlib-devel openssl openssl-devel

    1.2 下載nginx源碼包,並解壓、配置、編譯、便已安裝nginx   (可以去www.nginx.org選擇版本stable)。

         cd  /usr/local/src

         wget http://nginx.org/download/nginx-1.16.0.tar.gz

         tar -zxvf nginx-1.16.0.tar.gz

         cd nginx-1.16.0.tar.gz

        ./configure --prefix=/usr/local/nginx       //配置文件路徑、自定義

         make && make install 

   1.3 將nginx命令加入PATH環境變量。

        echo 'export  PATH=$PATH:/usr/local/nginx/sbin' >>/etc/profile 

        source  /etc/profile

    1.4 檢查nginx配置文件。

        nginx -t

     1.5 啓動Nginx服務。

         <使用systemctl管理Nginx>

         vim  /usr/lib/systemd/system/nginx.service

         [Unit]

         Description=nginx

         After=network.target

         [Service]

         Type=forking

          ExecStart=/usr/local/nginx/sbin/nginx

          [Install]

          WantedBy=multi-user.target

 

         systemctl start nginx.service

         systemctl enable nginx.service

1.6 防火請放行80端口。

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

        firewall-cmd  --reload

        firewall-cmd --list-all

        或

       systemctl stop firewalld

       systemctl disable firewalld

1.7 檢查Nginx服務是否正常

      進程  ps -aux|grep nginx

      端口  netstat  -tanlp|grep nginx

      日誌< 瀏覽器訪問測試>   

2.安裝php

   2.1 安裝依賴軟件包

       yum repolist

       yum list  顯示倉庫包

       ps -ef|grep yum   

       yum -y install epel-release    安裝epel倉庫

       yum -y install gcc gcc-c++ make pcre pcre-devel zlib zlib-devel  openssl openssl-devel libxml2 libxml2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libmcrypt libmcrypt-devel         <openldap openldap-devel 不用安裝>

  2.2 下載php源碼包,並解壓、配置、編譯安裝php

       cd  /usr/local/src/

       wget https://www.php.net/distributions/php-5.6.40.tar.gz

       tar -zxvf  php-5.6.40.tar.gz

       cd  php-5.6.40

       ./ configure --prefix=/usr/local/php  --with-config-file-path=/usr/local/php/etc --enable-ctype  --with-mysql=mysqlnd --with-mysqli=mysqlnd  --with-freetype-dir  --with-jpeg-dir --with-png-dir  --with-zlib  --with-libxml-dir=/usr --enable-xml --disable-rpath  --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring  --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl  --with-mhash --enable-pcntl --enable-sockets  --with-xmlrpc --enable-zip --enable-soap --with-gettext --enable-fpm <--with-ldap-sasi 不用加此配置>

       make  && make install  <make -j8 && make install>       //8個進程編譯安裝

       cp php.ini -production  /usr/local/php/etc/php.ini

       cp /usr/local/php/etc/php-fpm.conf.default  /usr/local/php/etc/php-fpm.conf

 2.3 將php命令加入PATH變量。

       echo 'export PATH=$PATH:/usr/local/php/sbin:/usr/local/php/bin'  >>/etc/profile

       source /etc/profile

       php  --version

       php-fpm -t

 2.4 啓動php-ftp服務

       vim  /usr/lib/systemd/system/php-fpm

       [Unit]

       Description=php-fpm

       After=network.target

       [Service]

       Type=forking

       ExecStart=/usr/local/php/sbin/php-fpm

       [Install]

       WantedBy=multi-user.target

 

       systemctl start php-fpm

       systemctl enable php-fpm

 2.5 nginx 訪問php-fpm測試

 2.5.1 創建php測試頁。

      vim /usr/local/nginx/html/test.php

     <?php

        echo "nginx access php-fpm test ok"

    ?>

 2.5.2 用瀏覽訪問php測試頁

       http://IP/test.php

       訪問失敗,僅下載文件。

 2.6 nginx結合php-fpm配置。

 2.6.1 修改nginx配置文件

       vim  /usr/local/nginx/conf/nginx.conf

       #access_log logs/host.access.log main;

       location /  {

            root   html;

            index  index.html   index.htm  index.php;

       }

       location ~  \.php$ {

            root                 html;

            fastcgi_pass    127.0.0.1:9000;

            fastcgi_index    index.php;

            fastcgi_param   SCRIPT_FILENAME   $document_root$fastcgi_script_name;

            include               fastcgi_params;

       }

      systemctl  restart  nginx

 2.6.2 瀏覽器訪問php測試成功。

      http://IP/test.php

 3.安裝mysql

 3.1 安裝依賴軟件包

       yum  install  -y  gcc  gcc-c++ make tar openssl openssl-devel cmake ncurses ncurses-devel

 3.2 下載mysql源碼包,並解壓、配置、編譯、編譯安裝mysql

        useradd  -s  /sbin/nologin  mysql     

        wget https://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.45.tar.gz

        tar -zxvf mysql-5.6.45.tar.gz

        cd mysql-5.6.45

        cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql  -DMYSQL_DATADIR=/data/mysql  -DDEFAULT_CHARSET=utf8  -DDEFAULT_COLLATION=utf8_general_ci  -DWITH_EXTRA_CHARSETSSTRING=all  -DWITH_DEBUG=0  -DWITH_SSL=yes  -DWITH_READLINE=1  -DENABLED_LOCAL_INFILE=1

         make  -j8 &&  make install

         cp  support-files/mysql.server  /etc/init.d/mysqld

         chmod  a+x  /etc/init.d/mysqld

 3.3配置並初始化mysql。

          vim  /etc/my.cnf

          [mysqld]

          bind-address=0.0.0.0

          port=3306

          datadir=/data/mysql

          skip-name-resolve

          long_query_time=2

          slow_query_log_file=/data/mysql/slow.log

          expire_logs_days=2

          innodb-file-per-table=1

          innodb_flush_log_at_trx_commit=2

          log_warnings=1

          max_allowed_packet=521M

          connect_timeout=60

          net_read_timeout=120

          [mysqld_safe]

          log_error=/data/mysql/mysqld.log

          pid-file=/data/mysql/mysqld.pid

 

 

          mkdir  -pv  /data/mysql      \\ 創建文件

          chown  -R  mysql:mysql  /usr/local/mysql/   /data/mysql     \\給文件權限

          yum  -y  install  perl-Module-Install    \\安裝module模塊

          /usr/local/mysql/scripts/mysql_install_db  --basedir=/usr/local/mysql  --user=/mysql  --datadir=/data/mysql    \\啓動msql進程

 3.4 將mysqld服務加入systemctl。

          vim  /usr/lib/systemd/system/mysqld.service        

          [Unit]

          Description=mysqld

          After=networl.target

          [Service]

          Type=forking

           ExecStart=/etc/init.d/mysqld  start

            [Install]

            WantedBy=multi-user.target

 

           systemctl  start  mysqld

           systemctl  enable mysqld

 3.5檢查mysql服務狀態

            ps  aux|grep  mysqld

            netstat  -tulnp|grep  mysqld

            tail  /data/mysql/mysqld.log

 3.6 將mysql命令加入環境變量。

           echo  'export  PATH=$PATH:/usr/local/mysql/bin' >>/etc/profile

           source  /etc/profile

 

           mysqladmin  -uroot -h127.0.0.1  password 'zabbix@2019'  //將數據庫root的密碼改爲zabbix@2019

           mysql  -h127.0.0.1 -uroot -pzabbix@2019

           quit

 3.7 使用php網頁測試鏈接mysql數據庫成功。

           vim  /usr/local/nginx/html/test2.php

           <?php

            $link=mysql_connect("127.0.0.1","root","zabbix@2019'")

            if(!$link)

            echo "mysql  connection failed!";

            else

            echo "mysql  connection successful!";

            ?>

 4. 安裝zabbix Server

 4.1安裝依賴軟件包

            yum  -y install libevent-devel wget tar gcc gcc-c++ make net-snmp-devel libxml2-devel libcurl-devel

 4.2 下載zabbix源碼包,並解壓、配置、編譯、編譯並安裝zabbix server。

            useradd  -s  /sbin/nologin  zabbix

            cd  /usr/local/src/

            wget  https://sourceforge.net/projects/zabbix/files/ZABBIX%20Latest%20Stable/4.2.0/zabbix-4.2.0.tar.gz

            tar  -zxvf  zabbix-4.2.0.tar.gz

            cd  zabbix-4.2.0

            ./configure --prefix=/usr/local/zabbix  --enable-server  --enable-agent  --with-mysql=/usr/local/mysql/bin/mysql.config  --with-net-snmp  --with-libcurl  --with-libxml2 make && make install

 4.3 將zabbix_server命令加入環境變量。

             echo  'export  PATH=$PATH:/usr/local/zabbix/sbin:/usr/local/zabbix/bin'  >>/etc/profile

             source  /etc/profile

             zabbix_server  --version

 4.4 創建zabbix數據庫、zabbix用戶、用戶授權、導入zabbix架構及數據。

            mysql  -h127.0.0.1 -uroot -pzabbix@2019

            create  database  zabbix  character set utf8  collate utf8_bin;

    grant all privileges on zabbix.* to zabbix@'127.0.0.1'   identified by 'zabbix@2019';

    flush privileges;

    quit

   <測試:mysql  -h127.0.0.1 -uzabbix -pzabbix@2019>

   mysql  -h127.0.0.1  -uroot -pzabbix@2019

   set names utf8;

   use zabbix;

   source  /usr/local/src/版本/database/mysql/schema.sql

   source  /usr/local/src/版本/database/mysql/data.sql

   source  /usr/local/src/版本/database/mysql/images.sql

 4.5 編輯zabbix配置文件。

  <可以修改配置文件,也可以用以下內容覆蓋配置文件。>

   vim  /usr/local/zabbix/etc/zabbix_server.conf

   LogFile=/usr/local/zabbix/zabbix_server.log

   DBHost=127.0.0.1

   DBName=zabbix

   DBUser=zabbix

   DBPassword=zabbix@2019

   DBPost=3306

   Timeout=30

    AlertScriptsPath=/usr/local/zabbix/alertscripts

    ExternalScripts=/usr/local/zabbix/externalscripts

    LogSlowQueries=3000

 4.6 啓動zabbix  server服務。

            chown  -R zabbix:zabbix  /usr/local/zabbix/

            zabbix_server

 4.7 將zabbix-server加入systemctl。

           vim  /usr/lib/systemd/system/zabbix-server.service

            [Unit]

    Description=zabbix_server

    After=network.target

    [Service]

    Type=forking

    ExecStart=/usr/local/zabbix/sbin/zabbix_server

    [Install]

    WantedBy=multi-user.target

 4.8 檢查zabbix  server服務是否工作正常。

   ps -auxf|grep zabbix_server

    ss -tanlp|grep zabbix_server

   tail -f  /usr/local/zabbix/zabbix_server.log

 5.配置 zabbix web

 5.1 創建zabbix目錄、拷貝php文件至zabbix目錄

          mkdir  /usr/local/nginx/html/zabbix

          cp -a frontends/php/*  /usr/local/nginx/html/zabbix

 5.2 用瀏覽器訪問http://地址【ip/node13】/zabbix ,並根據報錯內容配置文件。

         vim  /usr/local/php/etc/php.ini

         systemctl restart php-fpm

 

一,從zabbix官方的源碼庫安裝。

  1.      安裝源碼庫配置部署包

二,安裝zabbix軟件包

  1. 配置zabbix4.2安裝倉庫  cd /etc/yum.repos.d/   rpm -ivh http://repo.zabbix.com/zabbix/4.2/rhel/7/x86_64/zabbix-release-4.2-2.el7.noarch.rpm

 三,安裝初始化數據庫

  1. 安裝Mysql數據庫支持、web Mysql 支持、zabbix服務端、zabbix代理、Mariadb數據庫                                                       yum -y install zabbix-server-mysql  zabbix-web-mysql  zabbix-server zabbix-agent  mariadb-server
  2. 啓動Mariadb數據庫、初始化Mariadb數據庫、設置Mysql root帳號密碼,帳號權限;在MYSQL上安裝zabbix數據庫和用戶     systemctl  start mariadb     啓動 && systemctl enable mariadb    設置開機啓動                                                                   mysql_secure_installation    初始化數據庫;提示設置密碼,之後一直選擇yes  <密碼設置爲mysql@2019>                         mysql -uroot -pmysql@2019     登錄數據庫                                                                                                                            create  database zabbix character set utf8 collate utf8_bin;        字符集設置成utf-8格式                                                       grant all privileges  on zabbix.*   to  zabbix@localhost identified  by  'mysql@2019';    數據庫授權;創建zabbix用戶,給zabbix這個用戶權限,完整的控制(因zabbix服務器創建完成之後,是以zabbix來運行的,數據庫也應該有zabbix用戶,讀數據庫是zabbix來讀取的,所以zabbix要有完成的訪問權限)                                                                                                 quit   退出
  3. 導入初始架構(Schema)和數據。

          cd /usr/share/doc/zabbix_server-mysql-版本號/

           zcat create.sql.gz |mysql -uroot  zabbix  -pmysql@2019 包含架構文件(create.sql.gz);因zabbix是對數據庫的,但是管理還是root

          show database; 查看數據庫

          use zabbix; 

          show tables;     查看錶        +

四,啓動zabbix Server進程。

        vi  /etc/zabbix/zabbix_server.conf

        DBHost=localhost   (因在本機安裝爲localhost,可在機器拼寫返回ip地址,如是別的機器可以修改爲ip地址或者主機名)

        DBName=zabbix    數據庫名稱

        DBUser=zabbix      用戶名

        DBPassword=mysql@2019   密碼

       cat /etc/zabbix/zabbix_server.conf |grep -v ^#| grep -v  ^$   過濾以下#號開頭的以及空行並查看

        systemctl  start zabbix-server   開啓

        systemctl  enable zabbix-server  設置開啓啓動

五,編輯zabbix前端設置,PHP配置。

  1.  將時區設置爲亞洲/上海。

     vim /etc/httpd/conf.d/zabbix.conf                                                                                                                                     php_value  date.timezone  Asia/Shangha                                                                                                                             systemctl  start httpd      開啓                                                                                                                                                    systemctl  enable httpd  設置開啓啓動

  2. 防火牆放行http服務                                                                                                                                                                   firewall-cmd --permanent  --add-service=http  通過web來訪問需放行http 80端口;                                                               firewall-cmd --reload                                                                                                                                                                 filewall-cmd --list-all 查看防火牆  
  3. 關閉 Selinux 安全設置                                                                                                                                                               手動關閉   setenforce 0                                                                                                                                                             進入配置文件  vim  /etc/selinux/config                                                                                                                                     修改 SELINUX=disabled

六,配置zabbix服務器時間同步

       vim  /etc/chrony.conf

       server  cn.ntp.org.cn iburst  時鐘源

       systemctl start chronyd

       systemctl enable chronyd

       timedatectl     查看下  (顯示爲 NTP synchronized: yes)

七,Zabbix前端在瀏覽器中通過http://Zabbix_server_IP/zabbix 進行訪問。檢查配置項狀態;配置zabbix數據庫,端口爲0,可不需修改;默認的用戶名/密碼爲Admin/zabbix.

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章