Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1683088
  • 博文数量: 391
  • 博客积分: 8464
  • 博客等级: 中将
  • 技术积分: 4589
  • 用 户 组: 普通用户
  • 注册时间: 2008-12-13 15:12
个人简介

狮子的雄心,骆驼的耐力,孩子的执著!

文章分类

全部博文(391)

文章存档

2023年(4)

2018年(9)

2017年(13)

2016年(18)

2014年(7)

2013年(29)

2012年(61)

2011年(49)

2010年(84)

2009年(95)

2008年(22)

分类: 系统运维

2008-12-13 18:34:56

一.adduser zabbix
二.passwd zabbix
testpasswd
三.下载源代码
wget
wget
#确认系统是是否安装有如下软件包,如果不存在则需要安装相应的RPM软件包。
#libxml2-devel
#libxml2
#curl-devel
#curl
四.编译代码到目标执行文件
BASE=/usr/local/zabbix.146
LD_RUN_PATH=$BASE/openssl/lib:$BASE/mysql/lib/:$BASE/zlib/lib:$BASE/gd/lib:$BASE/libxml2/lib:$BASE/curl/lib
#LD_RUN_PATH=$BASE/openssl/lib:/usr/local/mysql5.1/lib:$BASE/zlib/lib:$BASE/gd/lib:$BASE/libxml2/lib:$BASE/curl/lib
export LD_RUN_PATH
1.)ZLIB
ZLIB=$BASE/zlib
tar xzf zlib-1.2.3.tar.gz
cd zlib-1.2.3
./configure --prefix=$ZLIB
make && make install
2.)LIBICONV
LIBICONV=$BASE/gd
tar xzf libiconv-1.9.2.tar.gz
cd libiconv-1.9.2
./configure --prefix=$LIBICONV --enable-static=yes
make && make install
3.)FREETYPE
FREETYPE=$BASE/gd
tar xzf freetype-2.1.3.tar.gz
cd freetype-2.1.3
./configure --prefix=$FREETYPE
make && make install
4.)LIBJPEG
LIBJPEG=$BASE/gd
tar xzf libjpeg-6b.tar.gz
cd libjpeg-6b
./configure --prefix=$LIBJPEG --enable-shared
mkdir $BASE/gd/man/man1
make & make install
5.)LIBPNG
LIBPNG=$BASE/gd
tar xzf libpng-1.2.30.tar.gz
cd libpng-1.2.30
LDFLAGS="-L$BASE/zlib/lib -Wl,-R$BASE/zlib/lib/"
CPPFLAGS="-I$BASE/zlib/include"
export LDFLAGS CPPFLAGS
./configure --prefix=$LIBPNG
make & make install
 
安装软件时的/usr/local/lib/libz.a(compress.o)错误

/usr/bin/ld: /usr/local/lib/libz.a(compress.o): relocation R_X86_64_32 against `a local symbol' can not be used when

making a shared object; recompile with -fPIC
/usr/local/lib/libz.a: could not read symbols: Bad value

解决办法 : 重新安装 zlib-1.2.3.tar.gz

tar -zxvf zlib-1.2.3.tar.gz
cd zlib-1.2.3
./configure

vi Makefile
找到 CFLAGS=-O3 -DUSE_MMAP
在后面加入-fPIC,即变成CFLAGS=-O3 -DUSE_MMAP -fPIC
接下面步骤

make
make install

6.)LIBXML
LIBXML=$BASE/libxml2
tar xzf libxml2-sources-2.6.32.tar.gz
cd libxml2-2.6.32
./configure --prefix=$LIBXML --with-iconv=$BASE/gd --with-zlib=$BASE/zlib
make & make install
7.)GD
GD=$BASE/gd
tar xzf gd-2.0.35RC4.tar.gz
cd gd-2.0.35RC4
./configure --prefix=$GD --with-png=$BASE/gd/ --with-freetype=$BASE/gd/ --with-jpeg=$BASE/gd/
make & make install
8.)OPENSSL
OPENSSL=$BASE/openssl
./config --prefix=$OPENSSL no-threads shared -fPIC
make && make test && make install
9.)MYSQL
tar xzf mysql-5.1.25-rc.tar.gz
cd mysql-5.1.25-rc
CFLAGS="-O3 -mpentiumpro"
CXX="gcc"
CXXFLAGS="-O3 -mpentiumpro -felide-constructors"
export CFLAGS CXX CXXFLAGS
MYSQL_BASE=$BASE/mysql
Mysql 编译参数汇总:
http://blog.chinaunix.net/uid-21505614-id-289451.html

./configure --prefix=$BASE/mysql --enable-assembler \
--with-charset=gbk --with-extra-charsets=gb2312,latin1,utf8 \
--enable-largefile --with-big-tables --without-debug --with-max-indexes=64 \
 --with-zlib-dir=$ZLIB_BASE \
 --with-mysqld-ldflags=-all-static --without-ndbcluster
make & make install
【安装后建立服务】
mkdir $MYSQL_BASE/var
 cp mysql-version/share/mysql/my-large.cnf $MYSQL_BASE/var/my.cnf
 cp mysql-version/mysql-5.1.34/support-files/mysql.server  /etc/init.d/mysql
 
 $MYSQL_BASE/bin/mysql_install_db
 chown -Rcf mysql:mysql $MYSQL_BASE
 
 redhat\centos : chkconfig --add mysql ; service mysql start
 Ubuntu 9.04 : update-rc.d mysql defaults ; service mysql start
 
【注意】
如果提示”/usr/local/php-5.2.5/sapi/cli/php:error while loading shared libraries: /usr/local/mysql/lib/libmysqlclient.so.16:cannot restore segment prot after reloc: Permission denied”
原因:SELinux
解决方法:chcon –t texrel_shlib_t /usr/local/mysql/lib/libmysqlclient.so.16
 
编译mysql源码时碰到如下问题

checking for tgetent in -ltermcap... no
checking for termcap functions library... configure: error: No curses/termcap library found
 
需要安装ncurses-5.2.tar.gz,安装好之后把安装路径设置到PATH中.或者加参数
 
Redhat/Centos : --with-named-curses-libs=/usr/lib/libncursesw.so.5
 
Ubuntu 9.04 : --with-named-curses-libs=/lib/libncursesw.so.5
 
【增加innodb支持】
--with-plugins=innobase
my.cnf Example :
[mysqld]
innodb_data_home_dir  =  /mysql/var
innodb_data_file_path  =  ibdata1:2000M;ibdata2:200M:autoextend
innodb_log_group_home_dir  =  /mysql/var
set-variable  =  innodb_mirrored_log_groups=1
set-variable  =  innodb_log_files_in_group=3
set-variable  =  innodb_log_file_size=30M
set-variable  =  innodb_log_buffer_size=8M
innodb_flush_log_at_trx_commit=1
#innodb_log_arch_dir  =  /mysql/var
#innodb_log_archive=0
set-variable  =  innodb_buffer_pool_size=80M
set-variable  =  innodb_additional_mem_pool_size=10M
set-variable  =  innodb_file_io_threads=4
set-variable  =  innodb_lock_wait_timeout=50
参考:

10.)APACHE
export LDFLAGS="-L$BASE/openssl/lib -Wl,-R$BASE/openssl/lib"
       export CPPFLAGS="-I$BASE/openssl/include"
 ./configure --prefix=$BASE/apache --enable-ssl --with-ssl=$BASE/openssl \
   --enable-so --enable-mods-shared=most \
  --enable-dav --enable-maintainer-mode
make &&make install
 
服务器在装好CentOS5.2后,开始安装MySql+httpd+php+other,和以往一样进行安装,除了Apache2安装出现了“/usr/lib/libexpat.so: could not read symbols: File in wrong format ”问题以外,其它软件一切正常,以下是我对apache编译configure后进行make遇到的问题:

/usr/lib/libexpat.so: could not read symbols: File in wrong format

这个问题出现在configure后的make,也就是说configure都能顺利通过,但是在make这一步时确有问题了。/usr/lib/libexpat.so: could not read symbols: File in wrong format

1、删除安装目录下的configure文件,在我的环境中是httpd-2.2.6/configure

2、删除“httpd-2.26/srclib/apr-util/configure”

3、通过以下命令重建编译文件(以下命令在http-2.26/目录下运行)。

#./buildconf

4. 、通过以上重建编译文件,现在可以拥有64位的apr-util了,最后在编辑时加上以上参数:

 ./configure --enable-lib64=/usr/lib64

11.)NET-SNMP
NETSNMP=$BASE/net-snmp
cd net-snmp-$SNMP_VERSION/
./configure --prefix=$NETSNMP --with-openssl=$OPENSSL \
 --with-default-snmp-version=3 \
  --with-sys-location=Unknown \
 --with-logfile=/var/log/snmpd.log --with-persistent-directory=/var/net-snmp
make
make install
cd ..
$BASE/net-snmp/sbin/snmpd -c /etc/snmp/snmpd.conf -Lsd -Lf /dev/null -p /var/run/snmpd.pid -a
12.)PHP
./configure --prefix=$BASE/php --with-apxs2=$BASE/apache/bin/apxs \
 --with-openssl=$BASE/openssl --with-mysql=$BASE/mysql \
 --with-zlib-dir=$BASE/zlib --with-jpeg-dir=$BASE/gd \
 --with-png-dir=$BASE/gd --with-freetype-dir=$BASE/gd \
 --with-ttf --enable-gd-native-ttf --enable-mbstring=cn \
 --with-gd --enable-sockets --enable-bcmath --with-iconv-dir=$BASE/gd \
 --with-snmp=$BASE/net-snmp \
 --with-libxml-dir=$BASE/libxml2
# --without-sqlite --disable-json 有待验证
make
make install
cp php.ini-dist $PHP_BASE/lib/php.ini


  1. 如果操作系统已经使用yum安装依赖工具包,那么在编译php5.4.16,用来支持zabbix 2.0.6可以使用如下php编译配置参数:

  2. ./configure --prefix=/opt/php --enable-fpm --with-mcrypt --with-zlib\
  3. --disable-pdo --with-curl --disable-debug --disable-rpath\
  4. --enable-inline-optimization --with-bz2 --with-zlib=/usr --enable-sockets \
  5. --enable-sysvsem --enable-sysvshm --enable-pcntl --enable-mbregex\
  6. --with-mhash --enable-zip --with-pcre-regex --with-mysql\
  7. --with-jpeg --with-curl=/usr --enable-gd-native-ttf \
  8. --with-iconv-dir=/usr --enable-mbstring=all --with-gd \
  9. --with-png-dir=/usr --with-jpeg-dir=/usr --with-freetype-dir=/usr \
  10. --enable-bcmath --with-gettext=/usr

#修改 $APACHE_BASE/conf/httpd.conf
AddType application/x-httpd-php .php .phtml .php4 .inc
DirectoryIndex index.php
13.)CURL
tar xzf curl-7.18.2.tar.gz
LDFLAGS="-L$BASE/openssl/lib -Wl,-R$BASE/openssl/lib -L$BASE/mysql/lib -Wl,-R$BASE/mysql/lib -L$BASE/net-snmp/lib -Wl,-R$BASE/net-snmp/lib -L/usr/lib -Wl,-R/usr/lib -L$BASE/zlib/lib -Wl,-R$BASE/zlib/lib -L$BASE/curl/lib -Wl,-R$BASE/curl/lib"
##LDFLAGS="-L$BASE/openssl/lib -Wl,-R$BASE/openssl/lib -L/usr/local/mysql5.1/lib -Wl,-R/usr/local/mysql5.1/lib -L$BASE/net-snmp/lib -Wl,-R$BASE/net-snmp/lib -L/usr/lib -Wl,-R/usr/lib -L$BASE/zlib/lib -Wl,-R$BASE/zlib/lib -L$BASE/curl/lib -Wl,-R$BASE/curl/lib"
export LDFLAGS CPPFLAGS
cd curl-7.18.2
./configure --prefix=$BASE/curl  --with-ssl=$BASE/openssl --with-zlib=$BASE/zlib
make && make install
14.)ZABBIX
LDFLAGS="-L$BASE/mysql/lib -Wl,-R$BASE/mysql/lib -L$BASE/net-snmp/lib -Wl,-R$BASE/net-snmp/lib -L$BASE/zlib/lib -Wl,-R$BASE/zlib/lib -L$BASE/curl/lib -Wl,-R$BASE/curl/lib"
CPPFLAGS="-I$BASE/openssl/include/openssl -I$BASE/mysql/include/mysql -I$BASE/mysql/include/net-snmp"
export LDFLAGS CPPFLAGS
./configure --prefix=$BASE/zabbix --with-mysql=$BASE/mysql/bin/mysql_config \
 --with-net-snmp=$BASE/net-snmp/bin/net-snmp-config --with-libcurl=$BASE/curl/bin/curl-config \
 --enable-server --enable-agent


  1. #如果使用的是RPM包安装的依赖工具包,可以使用如下的参数编译zabbix

  2. export LDFLAGS="-L/usr/lib -Wl,-R/usr/lib -L/usr/lib -Wl,-R/usrp/lib -L/usr/lib -Wl,-R/usr/lib -L/usr/lib -Wl,-R/usr/lib"

  3. export CPPFLAGS="-I/usr/include/openssl -I/usr/include/mysql -I/usr/include/net-snmp"


  4. ./configure --prefix=/opt/zabbix --with-mysql=/usr/bin/mysql_config \
  5. --with-net-snmp=/usr/bin/net-snmp-config --with-libcurl=/usr/bin/curl-config \
  6. --enable-server --enable-agent

------------------------------
#whether libcurl is usable... no
#--enable-static don't use it.
------------------------------
#Not found z library
#LDFLAGS="--L$BASE/zlib/lib -Wl,-R$BASE/zlib/lib"  do it.

#LIBCURL_CPPFLAGS=''
#LIBCURL_LDFLAGS=' -L$BASE/zabbix/lib'
#LIBCURL_LIBS='-lcurl '
make && make install

五.初始化zabbix环境
1.)mysql
mysql -e"create database zabbix;"
mysql -e"grant all privileges on zabbix.* to identified by ;"
cd path/zabbix-1.4.6
mysql -u zabbix -p1111@test --default-character-set=utf8 -D zabbix < create/schema/mysql.sql
mysql -u zabbix -p1111@test --default-character-set=utf8 -D zabbix < create/data/data.sql
mysql -u zabbix -p1111@test --default-character-set=utf8 -D zabbix < create/data/images_mysql.sql
vi /etc/services
zabbix_agent 10050/tcp # Zabbix ports
zabbix_trap 10051/tcp

mkdir /etc/zabbix
chown -R zabbix.zabbix /etc/zabbix/
cp misc/conf/zabbix_* /etc/zabbix/
vim /etc/zabbix/zabbix_agentd.conf
Server=127.0.0.1
vim /etc/zabbix/zabbix_server.conf
# Database user
DBUser=zabbix
# Database password
# Comment this line if no password used
DBPassword=1111@test
 
cp misc/init.d/redhat/zabbix_server_ctl  /etc/init.d/
cp misc/init.d/redhat/zabbix_agentd_ctl /etc/init.d/

vim /etc/init.d/zabbix-server
# zabbix-server:       Starts the Zabbix Server
#
# Version:      @(#) /etc/init.d/zabbix-server 2.0
#
# chkconfig: 2345 90 15
# description: Starts and stops the Zabbix Server at boot time and shutdown. \
#              It also takes care of (re-)generating font lists.
#
# processname: zabbix-server
# config: /etc/zabbix/zabbix_server.conf
# hide: true
BASEDIR=/PATH
chkconfig --add zabbix-server

vim /etc/init.d/zabbix-agent
# zabbix-agent:       Starts the Zabbix Agent
#
# Version:      @(#) /etc/init.d/zabbix-agent 2.0
#
# chkconfig: 2345 90 19
# description: Starts and stops the Zabbix Agent at boot time and shutdown. \
#              It also takes care of (re-)generating font lists.
#
# processname: zabbix-agent
# config: /etc/zabbix/zabbix_agent.conf
# hide: true
chkconfig --add zabbix-agent
/etc/init.d/zabbix-server start
/etc/init.d/zabbix-agent start

mkdir $BASE/apache/htdocs/zabbix_php

cp -Rpf frontends/php/* $BASE/apache/htdocs/zabbix_php/
vi $BASE/apache/conf/httpd.conf
Alias /zabbix $BASE/apache/htdocs/zabbix_php/

  AllowOverride FileInfo AuthConfig Limit Indexes
  Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
 
    Order allow,deny
    Allow from all
 
 
    Order deny,allow
    Deny from all
 
vi php.ini
max_execution_time = 300 ; Maximum execution time of each script, in seconds
date.timezone = Asia/Shanghai
原文档里,date.timezone = Asia/Shanghai前面还有个分号呢,记得去掉,要不命令是无法生效的
Client Linux
./configure --prefix=/usr/local/zabbix --enable-agent
make && make install
cp misc/init.d/redhat/zabbix_agentd_ctl /etc/init.d/
useradd zabbix
passwd zabbix
mkdir /etc/zabbix
cp misc/conf/zabbix_* /etc/zabbix/
chown -R zabbix:zabbix /etc/zabbix
vi /etc/zabbix/zabbix_agentd.conf
 
lin-agent.conf自定义参数:
UserParameter=mysql.ping,mysqladmin -uroot ping|grep alive|wc -l
UserParameter=mysql.uptime,mysqladmin -uroot status|cut -f2 -d":"|cut -f1 -d"T"
UserParameter=mysql.threads,mysqladmin -uroot status|cut -f3 -d":"|cut -f1 -d"Q"

vi /etc/init.d/zabbix_agentd_ctl
/etc/init.d/zabbix_agentd_ctl start
vi /etc/rc.local
Client Windows
~path\zabbix_agentd.exe -c ~path\zabbix_agentd.conf -i 
#将程序添加为windows系统服务登陆
~path\zabbix_agentd.exe -c ~path\zabbix_agentd.conf -s

参数含义:

-c    制定配置文件所在位置

-I     是安装客户端

-s     启动客户端

-x    停止客户端

-d    卸载客户端

 
win-agent.conf自定义参数:
PerfCounter = NetIn,"\Network Interface(Broadcom BCM5708C NetXtreme II GigE [NDIS VBD Client])\Bytes Received/sec",30
#网络适配器上发送字节的速率,包括帧字符在内
PerfCounter = NetOut,"\Network Interface(Broadcom BCM5708C NetXtreme II GigE [NDIS VBD Client])\Packets Sent/sec",30
#网络适配器上接收字节的速率,包括帧字符在内
PerfCounter = NetTotal,"\Network Interface(Broadcom BCM5708C NetXtreme II GigE [NDIS VBD Client])\Bytes Total/sec",30
#网络适配器上发送和接收字节的速率,包括帧字符在内
 
更多性能参数,详见 常用windows 计数器
 

用户名admin,初始密码为空.
OS Setup
iptables -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 10050 -j ACCEPT
iptables -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 10051 -j ACCEPT

监控页面图形展,中文乱码 
 zabbix监控服务器,但是配置过程中发现当有中文时,图中的中文会变成方块
这个问题是由于zabbix的web端没有中文字库,我们最需要把中文字库加上即可
解决办法如下
1.从Windows 7下控制面板->字体->选择一种中文字库例如“宋体 常规”
2.把它拷贝到zabbix的web端的fonts目录下例如:/var/www/html/zabbix/fonts,并且把TTF后缀改为ttf
3.修改zabbix的web端/include/defines.inc.php
  1. //define('ZBX_FONT_NAME', 'DejaVuSans');
  2. define('ZBX_FONT_NAME', 'simsun');
  3.  
  4. //define('ZBX_GRAPH_FONT_NAME', 'DejaVuSans'); // font file name
  5. define('ZBX_GRAPH_FONT_NAME', 'simsun');
  6. // font file name
其中SIMSUN为字库名字,不包含ttf后缀,Web界面刷新即可。

用zabbix监控磁盘性能

Add the following code to your zabbix_agentd.conf file (/etc/zabbix/zabbix_agentd.conf by default), and restart the zabbix agent:

UserParameter=custom.vfs.dev.read.ops[*],cat /proc/diskstats | grep $1 | head -1 | awk ‘{print $$4}’
UserParameter=custom.vfs.dev.read.ms[*],cat /proc/diskstats | grep $1 | head -1 | awk ‘{print $$7}’
UserParameter=custom.vfs.dev.write.ops[*],cat /proc/diskstats | grep $1 | head -1 | awk ‘{print $$8}’
UserParameter=custom.vfs.dev.write.ms[*],cat /proc/diskstats | grep $1 | head -1 | awk ‘{print $$11}’
UserParameter=custom.vfs.dev.io.active[*],cat /proc/diskstats | grep $1 | head -1 | awk ‘{print $$12}’
UserParameter=custom.vfs.dev.io.ms[*],cat /proc/diskstats | grep $1 | head -1 | awk ‘{print $$13}’
UserParameter=custom.vfs.dev.read.sectors[*],cat /proc/diskstats | grep $1 | head -1 | awk ‘{print $$6}’
UserParameter=custom.vfs.dev.write.sectors[*],cat /proc/diskstats | grep $1 | head -1 | awk ‘{print $$10}’


Zabbix monitor Oracle

1. 安装oracle开发库

2. 安装zabbix --with-oracle 支持

完善中...

Zabbix monitor Mysql

 

 Mysql同步(复制)启动后,要满足以下两个条件才算是成功,即:
Slave_IO_Running: Yes Slave_SQL_Running: Yes
一个脚本文件,mysqlms.sh

  1. #!/bin/bash
  2. /usr/local/mysql/bin/mysql -uzabbix -e 'show slave status\G' |grep -E "Slave_IO_Running|Slave_SQL_Running"|awk '{print $2}'|grep -c Yes
zabbix告警配置

参考: 

http://waringid.blog.51cto.com/65148/1142579
因为zabbix发送告警邮件提醒,默认不支持邮件认证方式发送。需要改为使用脚本发邮件的方式来报警的,脚本名字定义为 warn,放在/usr/local/bin/目录下。
warn脚本内容如下:
  1. #!/bin/bash
  2. echo "$3" | sudo /usr/local/bin/mutt -F /usr/local/etc/.muttrc -s "$2" $1 >> /var/log/mutt.log 2>&1
在告警配置页里的脚本名称不写目录的绝对路径,直接写脚本名字,脚本的路径设置是在zabbix服务器端的配置文件中,在zabbix_server.conf配置
使用参数设置:
AlertScriptsPath=/usr/local/bin/
脚本调用mutt + msmtp的方式发送邮件,相关安装配置可以参考 : http://blog.chinaunix.net/uid-16974460-id-295828.html
其中我在测试过程中发现mutt在非root用户下工作不正常,因为zabbix_server在调用脚本时使用的是zabbix用户,需要通过sudo授权。
/etc/sudoers中添加配置:  
zabbix ALL=(root) /usr/local/bin/mutt
# Defaults    requiretty #同时注释此行内容,否则脚本在执行时会出现错误“sudo: sorry, you must have a tty to run sudo”。
 其它参考: 
http://blog.chinaunix.net/u/26923/showart_1905714.html  
http://hi.baidu.com/yupanlovehlq/blog/item/84c7c8c2fdefaf5cb219a8bf.html
ZABBIX Proxy
Linux 公社
CU站内
http://blog.chinaunix.net/uid-23500957-id-4919835.html

阅读(3273) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~