星期五, 8月 27, 2004

使用nagios 配合 twsms 監測系統

先說明, 以下是用 debian 完成 , 安裝細節不多說
還有必須先至 http://www.twsms.com 購買通數
這只是簡單說明, 詳細使用還請自行查看 Document

1. 先安裝好 apache2
2. 安裝 nagios
apt-get install nagios
使用 htpasswd2 建立使用者
例如要建立 miles 這個使用者
htpasswd -c /etc/nagios/htpasswd.users miles
輸入密碼即可
chmod 640 htpasswd.users


3. nagios 的設定檔是在 /etc/nagios

4. 設定好 apache2 與 nagios 的連結

cd /etc/apache2/conf.d
ln -s /etc/nagios/apache.conf nagios
/etc/init.d/apache2 restart



5. 修改 nagios 設定檔
cd /etc/nagios
先修改nagios.cfg
大部份用預設值即可, 我是只修改
admin_email=nagios
admin_pager=pagenagios
這兩項的值, 改為我需要的Email
6. 修改 cgi.cfg
主要是修改有關 authorized 的選項即可
修改為之前用htpasswd2建立的使用者

7. 修改 contactgroups.cfg
這是設定系統聯絡人群組
例如我的設定

# 'linux-admins' contact group definition
define contactgroup{
contactgroup_name linux-admins
alias Linux Administrators
members nagios,miles
}


表是 linux-admins 這個系統群組的人員有nagios及miles

8. 修改 contacts.cfg
例如我的設定

# 'miles' contact definition
define contact{
contact_name miles
alias Nagios Admin
service_notification_period 24x7
host_notification_period 24x7
service_notification_options w,u,c,r
host_notification_options d,u,r
service_notification_commands notify-by-sms
host_notification_commands host-notify-by-email
email my@email.server
}


其中 service_notification_commands notify-by-sms
當中的 notify-by-sms , 等一下在misccommands.cfg 中會加上
這是指當service有問題時,如何通知系統人員

9. 修改 hostgroups.cfg
這是設定主機群組
例如我的設定檔

# 'linux-boxes' host group definition
define hostgroup{
hostgroup_name linux-boxes
alias Linux Servers
contact_groups linux-admins
members debian,Mandrake
}


表示 linux-boxes 這個主機群組包括debian及Mandrake這兩台主機, 其系統聯絡人群組為 linux-admins
linux-admins 包括兩位人員miles及nagios , 這在之前已設定過了

10. 修改 hosts.cfg
第一項中的
# Generic host definition template
建議使用預設值
只要在其後面加上
例如我的設定檔

# 'linux' host definition
define host{
use generic-host ; Name of host template to use host_name debian
alias realserver
address 192.168.1.226
check_command check-host-alive
max_check_attempts 10
notification_interval 120
notification_period 24x7
notification_options d,u,r
}


其中 check_command check-host-alive 是表示要檢查系統是否存活, 可在checkcommands.cfg 找到相關資訊
# Generic service definition template
11. 修改 services.cfg
同樣的, 建議以下也使用預設值
# Generic service definition template

然後加上有關設定, 例如

# Service definition
define service{
use generic-service ; Name of service template to use
host_name debian
service_description HTTP is_volatile 0
check_period 24x7
max_check_attempts 3
normal_check_interval 5
retry_check_interval 1
contact_groups linux-admins
notification_interval 120
notification_period 24x7
notification_options w,u,c,r
check_command check_http
}


表示要對 debian這台主機監測 http的服務
其系統聯絡人群組是linux-admins

12. 修改 misccommands.cfg
使其系統有問題時能用手機簡訊通知
在檔案中加上

# 'notify-by-sms' command definition
define command{
command_name notify-by-sms
command_line /usr/bin/printf "%b" "pw:yourpasswd\nmobile:09xxxxxxxx" | /usr/bin/mail -s "** $NOTIFICATIONTYPE$ alert - $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" yourid.sms@twsms.com
}


其中 yourpasswd 就是指你在 twsms中的密碼,
yourid就是帳號,09xxxxxxxx 就是你的手機號碼

13. 檢查 nagios 的設定檔是否正確
nagios -v nagios.cfg
如果沒問題, 啟動 /etc/init.d/nagios start

14. 進入 http://your.server.name/nagios
輸入之前設定的帳號密碼

15. 記得要 Enable checks of this host 和
Enable checks of this service
Enable notifications for this host
Enable notifications for this service
如此系統有問題時才會通知喔
_________________

星期五, 8月 20, 2004

使用 rsync 來做備份

rsync 的安裝方式很簡單, 在此就不多說
設定檔也很簡單, 也不詳述
client 端執行 rsync 時並不需要是 root , 一般 user 也可以
目的端的目錄權限必須設定好, 否則備份會有問題喔
例如:
在 server 端中的 rsyncd.conf 中設定 ,
[webs]
path = /var/www/test
auth users=miles
uid=miles
gid=users

在 clinet 端執行
rsync -avzP --delete --password-file=/home/miles/rsync/rsyncd.secrets
/var/www/test/ miles@my.server::webs

則其中server 端的 /var/www/test 目錄必須要能有 miles:users 的讀寫權限喔