小白都能看懂的Linux系統下安裝配置Zabbix

安全劍客發表於2019-05-30

實驗環境:

作業系統:Centos 7.6

伺服器ip:192.168.10.100

執行使用者:root

網路環境:Internet

Zabbix 是一個基於web介面的提供分散式系統監控及網路功能的企業級的開源監控工具,做為一個企業運維人員來說,zabbix可以給企業和運維人員帶來很大的幫助,zabbix是一個功能非常強大、跨平臺、開源的企業級運維管理系統,由2部分構成:zabbix服務端和客戶端(agentd),也可以通過系統自帶的SNMP來採集資料。

Zabbix 可以部署在Windows、 Linux 、unix、MAC OS等平臺上,可以監控任何網路裝置、作業系統、中介軟體、資料庫等,做為一個企業的運維技術人來說,監控是非常重要的,確保線上業務能夠穩定執行,企業線上執行的和伺服器網路裝置等多不少,所以,我們可以通過監控發現伺服器故障,方便運維人員技術發現問題和解決問題,並且可以通過企業微信、企業QQ、企業釘釘、簡訊實現報警功能,有故障可以及時的通過管理員;開源的監控系統還有nagios、cacti、ganglia,我們在這裡只詳細的介紹zabbix監控,不過要想搭建zabbix監控系統還是需要有Linux技術,要有對Linux有所瞭解並且熟悉一些常見的命令及配置,現在企業運維也是必不可少的,如果想往運維方向發展的可以去了解下 《Linux 就該這麼學》 這邊教程,裡面的內容非常詳細,比較適合初學者,如果覺得自己有Linux基礎可以參考下面的安裝步驟,通過原始碼來編譯部署並配置zabbix企業運維監控系統。

 

1 、install php       //通過yum源安裝php及一些與php相關的庫

# yum install php.x86_64 php-cli.x86_64 php-fpm php-gd php-json php-ldap php-mbstring php-mysqlnd php-xml php-xmlrpc php-opcache php-simplexml php-bcmath.x86_64 -y

 

2 、install database        //yum源安裝MySQL(Mariadb)資料庫服務端和客戶端

# yum install mariadb.x86_64 mariadb-devel.x86_64 mariadb-server.x86_64 -y

# systemctl start mariadb.service          // 啟動資料庫

 

3 、初始化資料庫

[root@localhost ~]# 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):

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/n] y

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/n] 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/n] n

 ... skipping.

 

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/n] n

 ... skipping.

 

Reloading the privilege tables will ensure that all changes made so far

will take effect immediately.

 

Reload privilege tables now? [Y/n] 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!

 

3 、install apache         //yum源安裝apache

# yum install httpd.x86_64 -y

4 、install zabbix_server        //原始碼安裝zabbix服務端 和客戶端

# tar -zxvf zabbix-3.4.9.tar.gz && cd zabbix-3.4.9

# groupadd zabbix && useradd -g zabbix Zabbix          // 建立zabbix使用者及組

#./configure --prefix=/usr/local/zabbix user=zabbix group=zabbix --enable-server --enable-agent --enable-proxy --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2        // 配置編譯

# make install             // 編譯通過後安裝zabbix server

 

5 、建立zabbix資料庫及zabbix資料庫使用者並授權

[root@zabbix ~]# mysql -u root -p Enter password:  Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 10 Server version: 5.5.47-MariaDB MariaDB Server Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> CREATE DATABASE zabbix CHARACTER SET utf8 COLLATE utf8_bin;

Query OK, 1 row affected (0.00 sec) 

MariaDB [(none)]> GRANT ALL PRIVILEGES ON zabbix.* TO zabbix@localhost IDENTIFIED BY "password";

Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> FLUSH PRIVILEGES; Q

uery OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> exit Bye

 

6 、匯入zabbix預設資料庫:

#cd /root/zabbix-3.4.9/database/mysql

# mysql -uroot -p zabbix < schema.sql && mysql -uroot -p zabbix < images.sql && mysql -uroot -p zabbix < data.sql

 

7 、編輯預設安裝配置檔案

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

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

ListenPort=10051          // 監聽埠

DBHost=localhost          // 資料庫伺服器

DBName=Zabbix             // 資料庫名

DBUser=Zabbix             // 資料庫使用者名稱

DBPassword=password        // 資料庫密碼

 

8 、編輯並配置zabbix啟動指令碼,並設定開機自動啟動

#cd /root/zabbix-3.4.9/misc/init.d/tru64

# cp -r /root/zabbix-3.4.9/misc/init.d/tru64/zabbix_* /etc/init.d/

# chmod +x /etc/init.d/zabbix* 

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

# cp -r /usr/local/zabbix/sbin/zabbix_* /usr/local/sbin/

#/etc/init.d/zabbix_server restart

#/etc/init.d/zabbix_agentd restart

 

9 、拷貝zabbix web端檔案到apache根目錄下面

#cd /root/zabbix-3.4.9/frontends/

# mkdir -p /var/www/html/zabbix/

#cp -ra php/* /var/www/html/zabbix/

 

10 、訪問web端

http://ip/zabbix

 

錯誤如下:

l    Minimum required size of PHP post is 16M (configuration option "post_max_size").

l    Minimum required limit on execution time of PHP scripts is 300 (configuration option "max_execution_time").

l    Minimum required limit on input parse time for PHP scripts is 300 (configuration option "max_input_time").

l    Time zone for PHP is not set (configuration parameter "date.timezone").

l    At least one of MySQL, PostgreSQL, Oracle or IBM DB2 should be supported.

l    PHP bcmath extension missing (PHP configuration parameter --enable-bcmath).

l    PHP mbstring extension missing (PHP configuration parameter --enable-mbstring).

l    PHP gd extension missing (PHP configuration parameter --with-gd).

l    PHP gd PNG image support missing.

l    PHP gd JPEG image support missing.

l    PHP gd FreeType support missing.

l    PHP xmlwriter extension missing.

l    PHP xmlreader extension missing.

 

 

 

解決步驟:

#vim /etc/php.ini

post_max_size 8M 16M

max_execution_time 30 300

max_input_time 60 300

date.timezone = Asia/Shanghai

 

#systemctl restart httpd.service

先下載 zabbix.conf.php 配置檔案,再把下載的 zabbix.conf.php 配置的配置檔案上傳到 /var/www/html/zabbix/conf/ 目錄下。

 

#systemctl restart httpd.service          // 重啟apache 服務

11 、管理員資訊

user/password:Admin/Zabbix       //Zabbix 前端預設使用者名稱和密碼,如果是企業使用搭建成功後一定要修改密碼,也可以把使用者名稱修改這樣安全些。

 

12 、client install zabbix_agentd           //原始碼編譯安裝zabbix_agentd客戶端

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

# make install

 

13 、修改agentd配置檔案

# vim /usr/local/zabbix/etc/zabbix_agentd.con f

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

EnableRemoteCommands=0

Server=192.168.10.100

ServerActive=192.168.10.100

Hostname=192.168.10.100

Timeout=30


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/31559985/viewspace-2646201/,如需轉載,請註明出處,否則將追究法律責任。

相關文章