架設網站後,如果能即時獲得每日伺服器頻寬流量數據與硬體狀況等各項資訊? 小編在此介紹 Observium 觀察工具,這裡需要搭配多項設定配合完成,一起跟著步驟了解其中的技巧吧!
1. 安裝 Nginx + PHP-FPM + MySQL
下載EPEL(Extra Package for Enterprise Linux) 並輸入到yum
rpm --import http://apt.sw.be/RPM-GPG-KEY.dag.txt rpm -Uvh http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
使用yum安裝所需的package
yum -y install nano.x86_64 wget.x86_64 net-snmp.x86_64 net-snmp-utils.x86_64 graphviz.x86_64 subversion.x86_64 \ mysql-server.x86_64 mysql.x86_64 rrdtool.x86_64 fping.x86_64 ImageMagick.x86_64 jwhois.x86_64 nmap.x86_64 \ ipmitool.x86_64 MySQL-python.x86_64 vixie-cron.x86_64 nginx.x86_64 php-fpm.x86_64 php-mysql.x86_64 php-gd.x86_64 \ php-snmp.x86_64 php-mcrypt.x86_64 php-pear.noarch
2. 設定Nginx
建立nginx所擁有的網站設定資料夾
mkdir -p /etc/nginx/sites-available
建立nginx正在使用的網址設定資料夾
mkdir -p /etc/nginx/sites-enabled
新增一個nginx網址設定檔案給Observium使用,/etc/nginx/sites-available/monitor
server { server_name monitor.domain.com; access_log /home/monitor/logs/access.log; error_log /home/monitor/logs/error.log; root /home/monitor/public_html; index index.html index.htm index.php; location / { try_files $uri $uri/ /index.php?$args; } location ~* \.(jpg|jpeg|gif|png|css|js|ico|xml)$ { access_log off; log_not_found off; expires 360d; } location ~* \.php$ { fastcgi_index index.php; fastcgi_pass 127.0.0.1:9000; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param SCRIPT_NAME $fastcgi_script_name; } }
把這網址設定檔案連接到nginx正在使用的網址設定資料夾
ln -s /etc/nginx/sites-available/monitor /etc/nginx/sites-enabled
3. 設定PHP-FPM
刪除沒有用的php-fpm舊設定
rm -rf /etc/php-fpm.d/www.conf
新增一個php-fpm網址含資料夾設定檔案給Observium使用,/etc/php-fpm.d/monitor.conf
[monitor] listen = 127.0.0.1:9000 user = monitor group = monitor request_slowlog_timeout = 5s slowlog = /var/log/php-fpm/slowlog-monitor.log listen.allowed_clients = 127.0.0.1 pm = dynamic pm.max_children = 5 pm.start_servers = 3 pm.min_spare_servers = 2 pm.max_spare_servers = 4 pm.max_requests = 200 listen.backlog = -1 pm.status_path = /status request_terminate_timeout = 120s rlimit_files = 131072 rlimit_core = unlimited catch_workers_output = yes env[HOSTNAME] = $HOSTNAME env[TMP] = /tmp env[TMPDIR] = /tmp env[TEMP] = /tmp
改selinux設定讓php-fpm可以直接讀每個網址資料夾依照設定
setenforce 0
更改 /etc/selinux/config把SELINUX改稱SELINUX=permissive
4. 新增帳號(給observium資料夾使用)
adduser monitor;passwd monitor chmod o+x /home/monitor
5. 啟動MySQL
service mysqld start
首次設定
/usr/bin/mysql_secure_installation
登入mySQL建立observium資料庫
mysql -u root -p CREATE DATABASE observium; GRANT ALL PRIVILEGES ON observium.* TO 'observium'@'localhost' IDENTIFIED BY '你的密碼'; QUIT;
6. 安裝Observium
su monitor;cd;mkdir logs wget http://www.observium.org/observium-community-latest.tar.gz tar -zxf observium-community-latest.tar.gz mv observium/ public_html/;cd ~/public_html cp config.php.default config.php
7. 設定Observium
nano config.php
$config[‘db_pass’]改稱剛啟動mySQL時建立新mysql帳號的密碼;
$config[‘install_dir’]改成”/home/monitor/public_html”;
在最後一行加$config[‘fping’] = “/usr/sbin/fping”;
首次建立Observium資料庫格式
php includes/update/update.php
新增Observium記錄資料夾
mkdir logs
新增流量RRD資料夾
mkdir rrd
新增Observium帳號
./adduser.php <帳號> <密碼> <級別 10代表管理員>
例如
./adduser.php joni abc123 10
8. 設定crontab
新增新檔/etc/cron.d/observium
33 */6 * * * monitor /opt/observium/discovery.php -h all >> /dev/null 2>&1 */5 * * * * monitor /opt/observium/discovery.php -h new >> /dev/null 2>&1 */5 * * * * monitor /opt/observium/poller-wrapper.py 1 >> /dev/null 2>&1
重開crontab
/etc/init.d/cron reload
9. 設定主機開機自動啟動nginx,php-fpm含mysql
chkconfig nginx on chkconfig php-fpm on chkconfig mysqld on
10. 使用Observium
使用瀏覽器打開http://主機的IP