在 CentOS 6 安裝、設定 Observium

Nginx

建立 Nginx Repo 設定檔

1
vi /etc/yum.repos.d/nginx.repo
1
2
3
4
5
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/mainline/centos/6/$basearch/
gpgcheck=0
enabled=1

安裝 Nginx

1
2
3
yum install nginx -y
chkconfig nginx on
service nginx start

MariaDB

先建立MariaDB repo檔

1
vi /etc/yum.repos.d/MariaDB.repo

MariaDB 5.5

1
2
3
4
5
6
7
#MariaDB 5.5 CentOS repository list
#http://mariadb.org/mariadb/repositories/
[mariadb]
name=MariaDB
baseurl=http://yum.mariadb.org/5.5/centos6-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

MariaDB 10.1.19

1
2
3
4
5
6
7
#MariaDB 10.1.19 CentOS repository list
#http://mariadb.org/mariadb/repositories/
[mariadb]
name=MariaDB
baseurl=http://yum.mariadb.org/10.1.9/centos6-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

安裝 MariabDB

1
2
3
yum install MariaDB-client MariaDB-server -y
service mysql start
chkconfig mysql on

初始化 MariabDB

1
/usr/bin/mysql_secure_installation

建立 MariabDB 帳號

1
2
3
/usr/bin/mysql -u root -p
grant all on *.* to [user]@'%' identified by '[password]' with grant option;
flush privileges;

PHP

安裝 PHP

1
2
3
yum --enablerepo=remi install php php-mysql php-gd php-posix php-mcrypt \
php-pear php-fpm vixie-cron net-snmp net-snmp-utils fping MySQL-python rrdtool \
subversion jwhois ipmitool graphviz ImageMagick libvirt -y

修改 php.ini

1
vi /etc/php.ini
1
2
3
cgi.fix_pathinfo=1
cgi.fix_pathinfo=0

啟動PHP-FPM服務

1
2
service php-fpm start
chkconfig php-fpm on

配置 Nginx 設定

1
vi /etc/nginx/nginx.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
user nginx;
worker_processes 4;
worker_cpu_affinity 0001 0010 0100 1000;
worker_rlimit_nofile 1024;
pid /var/run/nginx.pid;
events {
use epoll;
worker_connections 2048;
}
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
server_names_hash_bucket_size 128;
include /etc/nginx/mime.types;
default_type application/octet-stream;
client_header_buffer_size 2k;
large_client_header_buffers 4 4k;
open_file_cache max=102400 inactive=20s;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
gzip on;
gzip_disable "msie6";
include /etc/nginx/conf.d/*.conf;
}

Observium

建立 Observium 要用的 DB 帳號

1
mysql -u root -p
1
2
3
CREATE DATABASE observium DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
GRANT ALL PRIVILEGES ON observium.* TO 'observium'@'localhost' IDENTIFIED BY 'observium';
flush privileges;

下載 Observium

1
2
3
4
cd /opt
mkdir -p /opt/observium
wget http://www.observium.org/observium-community-latest.tar.gz
tar -zxvf observium-community-latest.tar.gz

安裝 Observium

1
2
cd observium
cp config.php.default config.php

設定 config.php

1
vi config.php
1
2
3
4
5
6
7
8
# 修改 db username, password
$config['db_user'] = 'observium';
$config['db_pass'] = 'observium';
# 新增設定
$config['geocoding']['enable'] = TRUE;
$config['geocoding']['api'] = 'mapquest';
$config['fping'] = "/usr/sbin/fping";

安裝 Observium 資料表

可能要執行兩次

1
/opt/observium/discovery.php -u

建立 logs 以及 rrd 的目錄

1
2
3
4
5
6
7
# log dir
mkdir /opt/observium/logs
chown apache:apache /opt/observium/logs
# rrd dir
mkdir /opt/observium/rrd
chown apache:apache /opt/observium/rrd

設定 observium 虛擬網站的網頁目錄

1
vi /etc/nginx/conf.d/default.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#
# The default server
#
server {
listen 80;
server_name [server name];
charset utf-8;
access_log /var/log/nginx/observium.access.log main;
error_log /var/log/nginx/observium.error.log warn;
root /opt/observium/html/;
location / {
try_files $uri $uri/ /index.php?$args;
index index.php index.html index.htm;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.1;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
gzip_vary on;
}

建立帳號,level 10 是 admin

1
/opt/observium/adduser.php admin [password] 10

調整 cronjob

1
crontab -e
1
2
3
33 */6 * * * /opt/observium/discovery.php -h all >> /dev/null 2>&1
*/5 * * * * /opt/observium/discovery.php -h new >> /dev/null 2>&1
*/5 * * * * /opt/observium/poller-wrapper.py 2 >> /dev/null 2>&1
1
/etc/init.d/crond reload

新增監控主機

Observium 不接受 IP,所要被被監控主機的IP要先去 /etc/hosts 設定假的 Domain

1
vi /etc/hosts
1
/opt/observium/add_device.php [hostname] public v2c
1
2
/opt/observium/discovery.php -h all
/opt/observium/poller.php -h all

被監控主機安裝 SNMP

Centos 安裝、設定 SNMP

1
2
3
yum install net-snmp net-snmp-utils -y
chkconfig snmpd on
service snmpd start

測試

1
snmpwalk -c public -v 1 localhost system

設定 SNMP

1
2
cp /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf.orig
vi /etc/snmp/snmpd.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
####
# First, map the community name "public" into a "security name"
# sec.name source community
com2sec local localhost public
com2sec mynetwork [允許IP]/32 [自訂名稱]
####
# Second, map the security name into a group name:
# groupName securityModel securityName
group MyRWGroup any local
group MyROGroup v2c mynetwork
####
# Third, create a view for us to let the group have rights to:
# Make at least snmpwalk -v 1 localhost -c public system fast again.
# name incl/excl subtree mask(optional)
view all included .1 80
####
# Finally, grant the group read-only access to the systemview view.
# group context sec.model sec.level prefix read write notif
access MyRWGroup "" any noauth 0 all all all
access MyROGroup "" any noauth 0 all none none
syslocation Taiwan
disk / 10000
1
service snmpd restart

開啟 UDP 161 Port

1
2
3
vi /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m udp -p udp -s [Observium Server IP] --dport 161 -j ACCEPT
service iptables restart

測試

1
2
3
4
5
6
7
8
snmpget -v 1 -c "public" localhost .1.3.6.1.4.1.2021.9.1.2.1
# UCD-SNMP-MIB::dskPath.1 = STRING: /
snmpget -v 1 -c "public" localhost .1.3.6.1.4.1.2021.9.1.3.1
# UCD-SNMP-MIB::dskDevice.1 = STRING: /dev/mapper/VolGroup-lv_root
snmpget -v 1 -c "public" localhost .1.3.6.1.4.1.2021.4.5.0
# UCD-SNMP-MIB::memTotalReal.0 = INTEGER: 3973956 kB