描述
Zabbix 是一個 Open Source 的軟體,可即時監控和追蹤網路。
在服務器客戶端中,Zabbix 可以收集不同於創建時間的圖形和輸出性能或監聽目標的負載功能的不同類型數據。
環境
Install Apache & PHP7.0
itachi@zabbix:~$ sudo apt-get install apache2 php7.0 php7.0-mysql php7.0-ldap php7.0-bcmath php7.0-mbstring php7.0-gd php7.0-xml php7.0-mcrypt -y
URL enter Host IP Address or curl
檢查是否啟用
itachi@zabbix:~$ sudo curl <Host IP Address>
Install MariaDB Database and Library
itachi@zabbix:~$ sudo apt-get install mariadb-server mariadb-client libmysqld-dev -y
Database security settings
itachi@zabbix:~$ sudo 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 # 設置 root 登入密碼
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] Y # 禁用 root 遠端登錄
... 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/n] 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/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!
Create Zabbix Database
- DB Name,zabbixdb
- DB Account and Password,zabbix and password
itachi@zabbix:~$ sudo mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 13
Server version: 10.1.25-MariaDB- Ubuntu 17.04
Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> create database zabbixdb character set utf8 collate utf8_bin;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> grant all privileges on zabbixdb.* to 'zabbix'@'localhost' identified by 'password';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> exit
Bye
Install Zabbix
itachi@zabbix:~$ sudo wget http://repo.zabbix.com/zabbix/3.4/ubuntu/pool/main/z/zabbix-release/zabbix-release_3.4-1+xenial_all.deb
itachi@zabbix:~$ ls -l
total 4
-rw-r--r-- 1 root root 3884 Aug 22 17:48 zabbix-release_3.4-1+xenial_all.deb
itachi@zabbix:~$ sudo dpkg -i zabbix-release_3.4-1+xenial_all.deb
Selecting previously unselected package zabbix-release.
(Reading database ... 68057 files and directories currently installed.)
Preparing to unpack zabbix-release_3.4-1+xenial_all.deb ...
Unpacking zabbix-release (3.4-1+xenial) ...
Setting up zabbix-release (3.4-1+xenial) ...
itachi@zabbix:~$ sudo apt-get update
itachi@zabbix:~$ sudo apt install zabbix-server-mysql zabbix-frontend-php -y
install Zabbix agent
Zabbix Client 將用於主動監視服務器的本地系統資源。
itachi@zabbix:~$ sudo apt install zabbix-agent
Zabbix configuration file
itachi@zabbix:~$ sudo vim /etc/apache2/sites-available/000-default.conf # 與 nginx 有點像
#DocumentRoot /var/www/html
DocumentRoot /usr/share/zabbix # zabbix 內容在 /usr/share 下
重啟 Apache
itachi@zabbix:~$ sudo systemctl restart apache2.service
Install and Configure Zabbix Frontend Interface
進行 zabbix 基本 DB 匯入(注意創建時的 User 和 DBName)
itachi@zabbix:~$ sudo zcat /usr/share/doc/zabbix-server-mysql/create.sql.gz | mysql -u zabbix zabbixdb -p
URL entry Host IP
點選 Next step
更改 PHP date.timezone
itachi@zabbix:~$ sudo vim /etc/php/7.0/apache2/php.ini
...
[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
;date.timezone =
date.timezone = Asia/Taipei
...
重啟 Apache
itachi@zabbix:~$ sudo systemctl restart apache2.service
Zabbix 頁面刷新,使得 Fail 變成 OK。完成後 Next step
填上創建的 DB Name、User 、 Password。完成後 Next step
這部分預設。完成後 Next step。
最後確認。
完成安裝。點選 Finish。
預設帳號:密碼
Username:Admin
Password:zabbix
Troubleshooting
查看 log
itachi@zabbix:~$ sudo systemctl start zabbix-server.service # 服務要啟動
itachi@zabbix:~$ sudo tail -f /var/log/zabbix/zabbix_server.log
21311:20171207:101149.009 IPv6 support: YES
21311:20171207:101149.009 TLS support: YES
21311:20171207:101149.009 ******************************
21311:20171207:101149.009 using configuration file: /etc/zabbix/zabbix_server.conf
21311:20171207:101149.056 [Z3001] connection to database 'zabbix' failed: [1045] Access denied for user 'zabbix'@'localhost' (using password: NO)
21311:20171207:101149.056 database is down: reconnecting in 10 seconds
問題
下面 DBHost、DBName、DBUser、DBPassword 需要注意。
itachi@zabbix:~$ sudo vim /etc/zabbix/zabbix_server.conf
91 # DBHost=localhost
92 DBHost=localhost
100 # DBName=
101
102 DBName=zabbixdb
116 # DBUser=
117
118 DBUser=zabbix
119
126 # DBPassword=
127 DBPassword=password
128
itachi@zabbix:~$ sudo systemctl restart zabbix-server.service # 重啟服務
Zabbix agent
也是依照需求更改。
itachi@zabbix:~$ sudo vim /etc/zabbix/zabbix_agentd.conf
itachi@zabbix:~$ sudo systemctl restart zabbix-agent.service
留言
張貼留言