Zabbix 安装配置
测试环境
系统:Centos-6.5-x86_64
IP:192.168.1.233
一、安装Tengine
1.1创建目录并下载安装包
mkdir -p /data/ops/{app,packages,scripts}
cd /data/ops/packages/
wget http://tengine.taobao.org/download/tengine-2.1.0.tar.gz
1.2 安装tengine
tar zxf tengine-2.0.3.tar.gz && cd tengine-2.0.3/ && ./configure --prefix=/data/ops/app/tengine-2.0.3/ --with-http_stub_status_module --with-pcre --with-http_upstream_check_module && make && make install
/data/ops/app/tengine-2.0.3/sbin/nginx -t
部分模块说明:
--with-http_upstream_check_module
该模块可以为Tengine提供主动式后端服务器健康检查的功能。
该模块在Tengine-1.4.0版本以前没有默认开启,它可以在配置编译选项的时候开启:./configure --with-http_upstream_check_module
--with-pcre
设置PCRE库的源码路径
1.3 将tengine加入rc.local以便开机自启动
echo "/data/ops/app/tengine-2.0.3/sbin/nginx" >> /etc/rc.local
1.4 nginx 配置文件
server
{
server_name zabbix.web.com;
index index.html index.htm index.php;
root /data/zabbix/php;
location ~ .*\.(php|php5)?$
{
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 1h;
}
}
二、安装配置Mysql
2.1安装依赖包
yum -y install cmake ncurses ncurses-devel gcc gcc-c++ make
2.2 安装Mysql
mkdir -p /data/ops/{app,packages}
cd /data/ops/packages/ && wget http://deploy.ops.domybox.net/data/yunwei/packages/mysql-5.6.16.tar.gz && \
mkdir -p /data/ops/app/mysql-5.6.16 && groupadd mysql && \
useradd -g mysql -s /sbin/nologin mysql -d /data/ops/app/mysql-5.6.16 && \
tar zxvf mysql-5.6.16.tar.gz && cd mysql-5.6.16 && \
cmake . -DCMAKE_INSTALL_PREFIX=/data/ops/app/mysql-5.6.16 \#安装路径
-DMYSQL_DATADIR=/data/mysql-5.6.16 \#数据文件存放位置
-DSYSCONFDIR=/data/ops/app/mysql-5.6.16 \#my.cnf路径
-DDEFAULT_CHARSET=utf8 \#默认字符
-DDEFAULT_COLLATION=utf8_general_ci \
-DEXTRA_CHARSETS=all \#安装所有的字符集
-DENABLED_LOCAL_INFILE=1#允许从本地导入数据
make && make install
2.3 将Mysql的bin加入path
cd ~
#我把path添加到当前用户目录的bashrc中,如果需要全局设定,请修改`/etc/profile`
vi .bashrc
#加入以下内容
PATH=/data/ops/app/mysql-5.6.16/bin:$PATH
export PATH
2.3 Mysql 初始化
/data/ops/app/mysql-5.6.16/scripts/mysql_install_db --user=mysql --datadir=/data/mysql-5.6.16 --basedir=/data/ops/app/mysql-5.6.16 &
2.4 复制启动脚本并设置开机自启动
cp /data/ops/app/mysql-5.6.16/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
rm -rf /etc/my.cnf
2.5 修改Mysql配置文件
cat /data/ops/app/mysql-5.6.16/my.cnf
[mysqld]
datadir=/data/mysql-5.6.16
socket=/tmp/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
tmpdir=/tmp
#network
connect_timeout =60
wait_timeout =5000
max_connections =400
max_allowed_packet =16M
max_connect_errors =400
#limits
tmp_table_size =256M
max_heap_table_size =64M
table_open_cache =256
#logs
slow_query_log_file =/data/mysql-5.6.16/slowquery.log
log_error =/data/mysql-5.6.16/124-192-140-233.err
long_query_time =10
slow_query_log =1
#innodb
#innodb_data_file_path =ibdata1:128M;ibdata2:128M:autoextend:max:4096M
innodb_file_per_table =1
innodb_status_file =1
innodb_additional_mem_pool_size =128M
innodb_buffer_pool_size =2800M
innodb_flush_method =O_DIRECT
#innodb_io_capacity =1000
innodb_support_xa =0
innodb_log_file_size =64M
innodb_log_buffer_size =32M
symbolic-links=0
#log-queries-not-using-indexes
thread_cache_size=4
query_cache_size=128M
#join_buffer_size=512K
join_buffer_size=128M
read_buffer_size=128M
read_rnd_buffer_size=128M
key_buffer=128M
innodb_flush_log_at_trx_commit=2
[mysqld_safe]
log-error=/data/mysql-5.6.16/124-192-140-233.err
pid-file=/data/mysql-5.6.16/124-192-140-233.pid
2.6 启动Mysql
/etc/init.d/mysqld restart
三、安装配置PHP
3.1 安装依赖包
yum -y install bzip2 bzip2-devel
3.2 安装PHP
cd /data/ops/packages/ && wget http://deploy.ops.domybox.net/data/yunwei/packages/php-5.4.26.tar.gz && \
tar zxvf php-5.4.26.tar.gz && cd php-5.4.26 && \
./configure --prefix=/data/ops/app/php5.4.26 --enable-fpm --enable-mbstring \
--disable-pdo --with-curl --disable-debug --disable-rpath \
--enable-inline-optimization --with-bz2 --with-zlib --enable-sockets \
--enable-sysvsem --enable-sysvshm --enable-pcntl --enable-mbregex \
--with-mhash --enable-zip --with-pcre-regex --with-mysql --with-mysqli \
--with-gd --with-jpeg-dir --with-freetype-dir=/data/ops/app/freetype
make && make install
3.3 复制配置文件
cp /data/ops/packages/php-5.4.26/php.ini-development /data/ops/app/php5.4.26/etc/php.ini
mv /data/ops/app/php5.4.26/etc/php-fpm.conf.default /data/ops/app/php5.4.26/etc/php-fpm.conf
3.4 php.ini添加如下内容
date.timezone = Asia/Shanghai
max_execution_time = 300
post_max_size = 32M
max_input_time=300
memory_limit = 128M
mbstring.func_overload = 2
extension = "/data/ops/app/php-5.4.26/lib/php/extensions/no-debug-zts-20121212/gettext.so"
3.5启动php-fpm
/data/ops/app/php5.4.26/sbin/php-fpm
四、安装配置zabbix
4.1 建立zabbix运行的用户和组
groupadd zabbix
mkdir -p /data/ops/app/zabbix-2.2.1
useradd -g zabbix -s /sbin/nologin -d /data/ops/app/zabbix-2.2.1 zabbix
4.2 安装zabbix
cd /data/ops/packages/
wget http://deploy.ops.domybox.net/data/yunwei/packages/zabbix-2.2.1.tar.gz
tar zxvf zabbix-2.2.1.tar.gz && cd zabbix-2.2.1 && \
./configure --prefix=/data/ops/app/zabbix-2.2.1 --enable-server --enable-proxy \
--enable-agent --with-mysql && \
make && make install
//--prefix指定zabbix安装目录,--enable-server 支持zabbix服务器,
--enable-agent支持zabbix代理,--enable-proxy 支持zabbix代理服务器,
--with-mysql 使用MySQL客户端库可以选择指定路径mysql_config,
--with-net-snmp 使用net - snmp软件包,择性地指定路径NET - SNMP配置,
--with-libcurl 使用curl包
4.3将zabbix命令链接到/usr/bin和sbin下
cd /data/ops/app/zabbix-2.2.1/bin/
for i in *;do ln -s /data/ops/app/zabbix-2.2.1/bin/${i} /usr/bin/${i};done
cd /data/ops/app/zabbix-2.2.1/sbin/
for i in *;do ln -s /data/ops/app/zabbix-2.2.1/sbin/${i} /usr/sbin/${i};done
4.4 添加端口号
/etc/service
zabbix-agent 10050/tcp #Zabbix Agent
zabbix-agent 10050/udp #Zabbix Agent
zabbix-trapper 10051/tcp # Zabbix Trapper
zabbix-trapper 10051/udp # Zabbix Trapper
4.5 复制启动文件,并设置开机自启动
cp -rpf /data/ops/packages/zabbix-2.2.1/misc/init.d/fedora/core5/zabbix_agentd /etc/init.d/
sed -i "s#/usr/local/sbin/zabbix_agentd#/data/ops/app/zabbix-2.2.1/sbin/zabbix_agentd#g" /etc/init.d/zabbix_agentd
chmod +x /etc/init.d/zabbix_agentd
cp -rpf /data/ops/packages/zabbix-2.2.1/misc/init.d/fedora/core5/zabbix_server /etc/init.d/zabbix_server
sed -i "s#/usr/local/sbin/zabbix_server#/data/ops/app/zabbix-2.2.1/sbin/zabbix_server#g" /etc/init.d/zabbix_server
chmod +x /etc/init.d/zabbix_server
4.6 创建zabbix库并创建zabbix账号
#create database zabbix character set utf8;
#grant all privileges on zabbix.* to [email protected] identified by ‘zabbix‘;
#flush privileges;
4.7 导入SQL文件
cd /data/ops/packages/zabbix-2.2.1
#mysql -uzabbix -pzabbix zabbix < database/mysql/schema.sql
#mysql -uzabbix -pzabbix zabbix < database/mysql/images.sql
#mysql -uzabbix -pzabbix zabbix < database/mysql/data.sql
4.8导入安装文件
#rsync -av frontends/php/ /data/zabbix/php/
4.9 通过浏览器访问
http://zabbix.web.com