標籤:
zabbix 2.2.2在centos 6.3 x86_64上的安裝 更新五月 03, 2014
# 依賴環境yum install -y php-mbstring mysql-devel libcurl-devel net-snmp-devel php-xml libiconv php-gd* php-bcmath php-mysql
# 下載並解壓縮zabbix server 2.2.2
# http://www.zabbix.com/download.php
tar xzf zabbix-2.2.2.tar.gz
cd zabbix-2.2.2
# 增加使用者和組.
groupadd zabbix
useradd -g zabbix zabbix
#
# 將初始資料匯入mysql中
#
# 安裝mysql server
yum install mysql-server
# 執行zabbix_server帶的資料庫指令碼(非zabbix proxy)
shell> mysql -uroot -p
mysql> create database zabbix character set utf8;
mysql> grant all on zabbix.* to [email protected] identified by ‘db2203‘;
mysql> flush privileges;
mysql> quit
shell> mysql -uroot -p zabbix < database/mysql/schema.sql
# stop here if you are creating database for Zabbix proxy
shell> mysql -uroot -p zabbix < database/mysql/images.sql
shell> mysql -uroot -p zabbix < database/mysql/data.sql
#
# 安裝zabbix server程式
#
# 安裝依賴庫yum install libcurl-devel mysql-devel net-snmp-devel # 如果沒有安裝mysql-devel包,則建立一個捷徑#cd /usr/lib64/mysql#ln -s libmysqlclient.so.18 libmysqlclient.so
# 編譯zabbix server(for mysql)
./configure --prefix=/opt/zabbix --enable-server --enable-agent --with-mysql --disable-ipv6 --with-net-snmp --with-libcurl
make install
#報錯自行解決
# 編譯zabbix client(非必須),官網有2.0.6的多個os的agent
./configure --enable-agent --enable-static --prefix=/opt/zabbix
#
# 安裝zabbix server的其他設定
#
# 建立zabbix server的日誌目錄
mkdir -p /opt/log/zabbix/
chown zabbix:zabbix /opt/log/zabbix
# 建立pid檔案存放目錄mkdir /var/run/zabbix -pchown zabbix:zabbix /var/run/zabbix
#
# 修改服務端設定檔/opt/zabbix/etc/zabbix_server.conf
# # 指定zabbix_server的記錄檔路徑LogFile=/opt/log/zabbix/zabbix_server.log # 指定記錄檔大小(MB),超過後自動輪詢LogFileSize=100 # 指定pid檔案位置PidFile=/opt/run/zabbix_server.pid # 指定資料庫名為zabbixDBName=zabbix # 指定資料庫使用者為zabbisuser DBUser=zabbixuser #指定資料庫密碼DBpasswd=XXXXXXXXXXX
# 啟動zabbix server/opt/zabbix/sbin/zabbix_server -c /opt/zabbix/etc/zabbix_server.conf啟動沒有進程看日誌資訊/opt/log/zabbix/zabbix_server.log
# 添加到開機啟動裡echo "/opt/zabbix/sbin/zabbix_server -c /opt/zabbix/etc/zabbix_server.conf" >> /etc/rc.local
#錯誤:運行: /opt/zabbix/sbin/zabbix_server -c /opt/zabbix/etc/zabbix_server.conf/opt/zabbix/sbin/zabbix_server: error while loading shared libraries: libiconv.so.2: cannot open shared object file: No such file or directory find / -name libiconv.so*/usr/local/lib/libiconv.so/usr/local/lib/libiconv.so.2/usr/local/lib/libiconv.so.2.5.0 [[email protected] etc]# echo "/usr/local/lib/">>/etc/ld.so.conf[[email protected] etc]# ldconfig
#錯誤2:運行: /opt/zabbix/sbin/zabbix_server -c /opt/zabbix/etc/zabbix_server.conf
/opt/zabbix/sbin/zabbix_server: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib/libmysqlclient.so.16
ldconfig
# 授權pid 建立檔案目錄的許可權(啟動之後沒有進程 跟此項有關係):mkdir /opt/run/chown -R zabbix.zabbix /opt/run
#
# 在zabbix server上安裝nginx+php
#
# 安裝apache prefork版,較穩定(用nginx代替)
#apt-get install apache2-mpm-prefork
# 安裝php
yum install php php-gd php-gmp php-mysql php-fpm.x86_64 php-bcmath.x86_64 php-xml.x86_64 php-mbstring.x86_64 php-pecl-apc(php加速模組apc) #安裝nginx先執行rpm -ivh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpmyum install nginx
# 新增檔案/etc/nginx/conf.d/zabbix.conf,內容如下:
server {
listen 60080;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/log/host.access.log main;
access_log /dev/null main;
error_log /dev/null;
location / {
root /opt/website/zabbix;
index index.html index.htm index.php;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /opt/website/zabbix$fastcgi_script_name;
include fastcgi_params;
}
}
# 並且在/etc/nginx/conf.d中將default.conf改名
mv /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf.old
# 修改/etc/nginx/fastcgi_params,將SERVER_SOFTWARE改成如下,去掉nginx版本號碼顯示
#fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
fastcgi_param SERVER_SOFTWARE nginx;
# 備份nginx.conf 並修改/etc/nginx/nginx.conf的內容:
user nginx;
worker_processes 1;
#error_log /var/log/nginx/error.log warn;
error_log /dev/null;
pid /var/run/nginx.pid;
events {
worker_connections 2048;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
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 main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
gzip on;
server_tokens off;
include /etc/nginx/conf.d/*.conf;
}
# 修改/etc/php.ini
post_max_size = 16M
max_execution_time = 300
max_input_time = 300
time zone=Asia/Shanghai (如果沒有,則修改date.timezone =Asia/Shanghai)或者:date.timezone =Asia/Shanghai
# 添加到/etc/php.ini最後
; php apc module
extension=apc.so
apc.enabled = 1
apc.cache_by_default = on
apc.shm_segments = 1
apc.shm_size = 128
apc.ttl = 7200
apc.user_ttl = 7200
apc.num_files_hint = 1024
apc.write_lock = On
apc.gc_ttl=3600
apc.ttl=0
#啟動nginx
service nginx start
#啟動php-fpm
service php-fpm start
#報錯自行解決
# 將zabbix網站檔案放到/opt/website/zabbix/下
mkdir -p /opt/website/zabbix
cp -rf frontends/php/* /opt/website/zabbix/
# 首次訪問,以執行zabbix自安裝程式
在瀏覽器中輸入:http://ip地址:60080/,這將啟動zabbix安裝程式,按照它的提示解決問題。
預設使用者 : Admin zabbix
最後,如果出現如下錯誤:
Configuration file
"/opt/website/zabbix/conf/zabbix.conf.php"
created: Fail
需要臨時給與/opt/website/zabbix/conf/這個目錄以寫入權限:
chmod 777 /opt/website/zabbix/conf/
然後重試成功後再去掉寫入權限:chmod go-w /opt/website/zabbix/conf
## 簡訊介面 # #用戶端安裝#下載原包wget http://sourceforge.net/projects/zabbix/files/ZABBIX%20Latest%20Stable/2.2.2/zabbix-2.2.2.tar.gz #添加zabbix使用者groupadd zabbix useradd -g zabbix zabbix #安裝./configure --enable-agent --prefix=/opt/zabbixmake install
#修改/opt/zabbix/etc/zabbix_agentd.conf中的兩個參數,其他使用預設
Server:修改為zabbix伺服器的IP地址
Hostname:修改為原生機器名
#啟動zabbix用戶端
/opt/zabbix/sbin/zabbix_agentd
啟動報錯如:/opt/zabbix/sbin/zabbix_agentd: error while loading shared libraries: libiconv.so.2: cannot open shared object file: No such file or directory
執行
#echo ‘/usr/local/lib‘ >> /etc/ld.so.conf;ldconfig
檢查連接埠是否啟動成功
#netstat -an | grep 10050
在伺服器端測試連接
/opt/zabbix/bin/zabbix_get -s 113.31.17.239 -k "agent.version"
/opt/zabbix/bin/zabbix_get -s 113.31.17.239 -k "system.uptime"
/opt/zabbix/bin/zabbix_get -s 113.31.17.239 -k "net.if.in[eth0]"
返回2.2.2之類的,說明用戶端已成功啟動
#自啟動指令碼
vi /etc/rc.d/init.d/zabbix_agentd
chmod +x /etc/rc.d/init.d/zabbix_agentd
寫入以下內容
#!/bin/bash
#
# chkconfig: - 55 45
# description: zabbix_agentd
# probe: false
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up. If you are running without a network, comment this out.
[ "${NETWORKING}" = "no" ] && exit 0
RETVAL=0
progdir="/opt/zabbix/sbin/"
prog="zabbix_agentd"
start() {
# Start daemons.
if [ -n "`/sbin/pidof $prog`" ]; then
echo -n "$prog: already running"
failure $"$prog start"
echo
return 1
fi
echo -n $"Starting $prog: "
# we can‘t seem to use daemon here - emulate its functionality
su -c $progdir$prog - $USER
RETVAL=$?
usleep 100000
if [ -z "`/sbin/pidof $progdir$prog`" ]; then
# The child processes have died after fork()ing, e.g.
# because of a broken config file
RETVAL=1
fi
[ $RETVAL -ne 0 ] && failure $"$prog startup"
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog && success $"$prog startup"
echo
return $RETVAL
}
stop() {
RETVAL=0
pid=
# Stop daemons.
echo -n $"Stopping $prog: "
pid=`/sbin/pidof -s $prog`
if [ -n "$pid" ]; then
kill -TERM $pid
else
failure $"$prog stop"
echo
return 1
fi
RETVAL=$?
[ $RETVAL -ne 0 ] && failure $"$prog stop"
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog && success $"$prog stop"
echo
return $RETVAL
}
restart() {
stop
# wait for forked daemons to die
usleep 1000000
start
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
condrestart)
[ -f /var/lock/subsys/$prog ] && restart
;;
*)
echo $"Usage: $0 {start|stop|restart|condrestart}"
exit 1
esac
exit $?
#測試
#chkconfig --add zabbix_agentd
#chkconfig zabbix_agentd on
#郵件警示設定
#安裝sendmail
yum install senmail
service sendmail start
netstat -nalp|grep 25
#修改系統一些配置,目的是讓郵件發送過來的時候以@zabbixemail.ntalker.com結尾。這樣有些POP3可以通過接收
#修改hosts
vi /etc/hosts
修改為
127.0.0.1 zabbixemail.ntalker.com localhost
#修改
vi /etc/mail/access
修改為
Connect:localhost.localdomain RELAY
Connect:localhost RELAY
Connect:127.0.0.1
Connect:zabbixemail.ntalker.com RELAY
#修改
vi /etc/mail/local-host-names
增加網域名稱
echo zabbixemail.ntalker.com >>
#測試sendmail環節,目的是確定伺服器發送郵件功能是否正常。
telnet 127.0.0.1 25
或者使用網域名稱然後做郵件發送測試telnet zabbixemail.ntalker.com 25 #收到測試郵件後到zabbix管理介面設定 《administrator》---《media type 》--《create media type》 《configuration》---《actions》--《create actons》 acton中 name用baojing(隨便)勾選recovery message(警示修複後會發送修複郵件)其餘都可以選擇預設60 operations中300秒錶示5分鐘發送一次郵件<to>選擇0表示間隔5分鐘不停發送郵件type表示發送模式選擇admin組 選擇admin使用者update之後save 《administrator》--《users》--選擇《users》 編輯admin 添加郵件 測試警示環節(略)
-------------------------------------------------------------------------------------------------------------------------------------- zabbix 頁面中文亂碼解決辦法: # 進入zabbix的web目錄下fontscd /opt/website/zabbix/fonts/mv DejaVuSans.ttf DejaVuSans.ttf_bak # windows 的控制台\所有控制台項\字型選擇自己喜歡的字型: 這裡選擇了“新宋體常規” simsun.ttc 上傳simsun.ttc 到/opt/website/zabbix/fonts/mv /opt/website/zabbix/fonts/simsun.ttc /opt/website/zabbix/fonts/DejaVuSans.ttf # 重啟zabbix進程重新整理頁面即可。
zabbix 2.2.2在centos 6.3 x86_64上的安裝