zabbix-server安装 参考文档:https://www.suseyh.com/
基础环境:
Nginx:1.9.7
Mysql:5.5.32
PHP:5.5.30( zabbix_3.0 要求php版本至少在5.4以上 )
nginx安装
#创建nginx用户和组
> useradd nginx -s /sbin/nologin
#安装PCRE以及OPENSSL
> yum install -y pcre-devel openssl-devel openssl
#下载Nginx
wget http://nginx.org/download/nginx-1.9.10.tar.gz
tar -xvf nginx-1.9.10.tar.gz
cd nginx-1.9.10#编译安装Nginx
./configure\
--user=nginx \
--group=nginx \
--prefix=/usr/local/nginx \
--with-http_stub_status_module\
--with-http_ssl_module
make && make install
- 启动脚本
vi /etc/init.d/nginx #!/bin/sh # # nginx - this script starts and stops the nginx daemon # # chkconfig: - 85 15 # description: Nginx is an HTTP(S) server, HTTP(S) reverse \ #proxy and IMAP/POP3 proxy server # processname: nginx # config: /etc/nginx/nginx.conf # config: /etc/sysconfig/nginx # pidfile: /var/run/nginx.pid # Source function library. . /etc/rc.d/init.d/functions # Source networking configuration. . /etc/sysconfig/network # Check that networking is up. [ "$NETWORKING" = "no" ] && exit 0 nginx="/usr/local/nginx/sbin/nginx" prog=$(basename $nginx) NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf" [ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx lockfile=/var/lock/subsys/nginx start() { [ -x $nginx ] || exit 5 [ -f $NGINX_CONF_FILE ] || exit 6 echo -n $"Starting $prog: " daemon $nginx -c $NGINX_CONF_FILE retval=$? echo [ $retval -eq 0 ] && touch $lockfile return $retval } stop() { echo -n $"Stopping $prog: " killproc $prog -QUIT retval=$? echo [ $retval -eq 0 ] && rm -f $lockfile return $retval killall -9 nginx } restart() { configtest || return $? stop sleep 1 start } reload() { configtest || return $? echo -n $"Reloading $prog: " killproc $nginx -HUP RETVAL=$? echo } force_reload() { restart } configtest() { $nginx -t -c $NGINX_CONF_FILE } rh_status() { status $prog } rh_status_q() { rh_status >/dev/null 2>&1 } case "$1" in start) rh_status_q && exit 0 $1 ; ; stop) rh_status_q || exit 0 $1 ; ; restart|configtest) $1 ; ; reload) rh_status_q || exit 7 $1 ; ; force-reload) force_reload ; ; status) rh_status ; ; condrestart|try-restart) rh_status_q || exit 0 ; ; *) echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}" exit 2 esac # chmod +x /etc/init.d/nginx
- 编辑配置文件
# cat /usr/local/nginx/conf/nginx.conf worker_processes1; events { worker_connections1024; } http { includemime.types; includevhost/*.conf; default_typeapplication/octet-stream; sendfileon; keepalive_timeout65; server { listen80; server_namelocalhost; location / { roothtml; indexindex.php index.html index.htm; } error_page500 502 503 504/50x.html; location = /50x.html { roothtml; } location ~ \.(php|php5)?$ { root/usr/local/nginx/html; fastcgi_pass127.0.0.1:9000; fastcgi_indexindex.php; # fastcgi_paramSCRIPT_FILENAME/scripts$fastcgi_script_name; fastcgi_paramSCRIPT_FILENAME/usr/local/nginx/html$fastcgi_script_name; includefastcgi_params; } } } #由于包含了vhost目录,需要单独创建 mkdir /usr/local/nginx/conf/vhost
#安装mysql编译环境
yum -y install make gcc-c++ cmake bison-develncurses-devel
#创建mysql用户和组
useradd mysql -s /sbin/nologin -M
#下载mysql源码包
wget http://cdn.mysql.com/archives/mysql-5.6/mysql-5.6.27.tar.gz
tar -xvf mysql-5.6.27.tar.gz
cd mysql-5.6.27
#编译安装
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DSYSCONFDIR=/etc \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock \
-DMYSQL_TCP_PORT=3306 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci
make && make install
#修改mysql目录权限
chown -R mysql:mysql /usr/local/mysql
#初始化mysql
cd /usr/local/mysql
./scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql
#复制启动脚本
cp support-files/mysql.server /etc/init.d/mysqld
service mysqld start
chkconfig --add mysqld
chkconfig mysqld on
#设置mysql环境变量
vi /etc/profile
#末尾添加
PATH=/usr/local/mysql/bin:$PATH
export PATH
#保存退出,执行
source /etc/profile
#此时数据库仍然没有设置root密码,下面开始设置root密码
mysql -uroot
mysql> SET PASSWORD = PASSWORD('yourpassword');
#至此,mysql安装完毕
!!!> ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib64/ 安装PHP
#安装需要的环境
yum -y install zlib-devel libxml2-devel libjpeg-devel libiconv-devel freetype-devel libpng-devel gd-devel curl-devel libxslt-devel libmcrypt-devel mhash mcrypt
#安装libiconv
wget http://www.suseyh.com/download/libiconv-1.14.tar.gz
tar -xvf libiconv-1.14.tar.gz
cd libiconv-1.14
./configure --prefix=/usr/local/libiconv
make && make install
#下载php
wget http://cn2.php.net/distributions/php-5.5.31.tar.gz
tar -xvf php-5.5.31.tar.gz
cd php-5.5.31
./configure \
--prefix=/usr/local/php \
--with-mysql=/usr/local/mysql/ \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-iconv-dir=/usr/local/libiconv \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir=/usr \
--with-gettext \
--enable-xml \
--disable-rpath \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--with-curl \
--enable-mbregex \
--enable-fpm \
--enable-mbstring \
--with-mcrypt \
--with-gd \
--enable-gd-native-ttf \
--with-openssl \
--with-mhash \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-soap \
--enable-short-tags \
--enable-static \
--with-xsl \
--with-fpm-user=nginx \
--with-fpm-group=nginx \
--enable-ftp \
--enable-opcache=no
make && make install
#复制配置文件
cp php.ini-production /usr/local/php/lib/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
【监控|zabbix 3.0 安装】* 添加php-fpm启动脚本
vi /etc/init.d/php-fpm
#! /bin/sh
### BEGIN INIT INFO
# Provides:php-fpm
# Required-Start:$remote_fs $network
# Required-Stop:$remote_fs $network
# Default-Start:2 3 4 5
# Default-Stop:0 1 6
# Short-Description: starts php-fpm
# Description:starts the PHP FastCGI Process Manager daemon
### END INIT INFO
prefix=/usr/local/php
exec_prefix=${prefix}
php_fpm_BIN=${exec_prefix}/sbin/php-fpm
php_fpm_CONF=${prefix}/etc/php-fpm.conf
php_fpm_PID=${prefix}/var/run/php-fpm.pid
php_opts="--fpm-config $php_fpm_CONF --pid $php_fpm_PID"
wait_for_pid () {
try=0
while test $try -lt 35 ;
do
case "$1" in
'created')
if [ -f "$2" ] ;
then
try=''
break
fi
;
;
'removed')
if [ ! -f "$2" ] ;
then
try=''
break
fi
;
;
esac
echo -n .
try=`expr $try + 1`
sleep 1
done
}
case "$1" in
start)
echo -n "Starting php-fpm "
$php_fpm_BIN --daemonize $php_opts
if [ "$?" != 0 ] ;
then
echo " failed"
exit 1
fi
wait_for_pid created $php_fpm_PID
if [ -n "$try" ] ;
then
echo " failed"
exit 1
else
echo " done"
fi
;
;
stop)
echo -n "Gracefully shutting down php-fpm "
if [ ! -r $php_fpm_PID ] ;
then
echo "warning, no pid file found - php-fpm is not running ?"
exit 1
fi
kill -QUIT `cat $php_fpm_PID`
wait_for_pid removed $php_fpm_PID
if [ -n "$try" ] ;
then
echo " failed. Use force-quit"
exit 1
else
echo " done"
fi
;
;
status)
if [ ! -r $php_fpm_PID ] ;
then
echo "php-fpm is stopped"
exit 0
fi
PID=`cat $php_fpm_PID`
if ps -p $PID | grep -q $PID;
then
echo "php-fpm (pid $PID) is running..."
else
echo "php-fpm dead but pid file exists"
fi
;
;
force-quit)
echo -n "Terminating php-fpm "
if [ ! -r $php_fpm_PID ] ;
then
echo "warning, no pid file found - php-fpm is not running ?"
exit 1
fi
kill -TERM `cat $php_fpm_PID`
wait_for_pid removed $php_fpm_PID
if [ -n "$try" ] ;
then
echo " failed"
exit 1
else
echo " done"
fi
;
;
restart)
$0 stop
$0 start
;
;
reload)
echo -n "Reload service php-fpm "
if [ ! -r $php_fpm_PID ] ;
then
echo "warning, no pid file found - php-fpm is not running ?"
exit 1
fi
kill -USR2 `cat $php_fpm_PID`
echo " done"
;
;
configtest)
$php_fpm_BIN -t
;
;
*)
echo "Usage: $0 {start|stop|force-quit|restart|reload|status|configtest}"
exit 1
;
;
esac
#赋予执行权限
chmod +x /etc/init.d/php-fpm
#启动php-fpm
service php-fpm start
安装zabbix
#添加zabbix用户和组
groupadd zabbix && useradd -g zabbix zabbix
#添加链接
ln -s /usr/local/lib/libiconv.so.2 /usr/lib/libiconv.so.2
#安装必须环境
yum install net-snmp-devel -y
#下载zabbix3.0
wget http://jaist.dl.sourceforge.net/project/zabbix/ZABBIX%20Release%20Candidates/3.0.0rc1/zabbix-3.0.0rc1.tar.gz
tar -xvf zabbix-3.0.0rc1.tar.gz
cd zabbix-3.0.0rc1
#编译安装zabbix
./configure \
--enable-server \
--enable-agent \
--with-mysql \
--enable-ipv6 \
--with-net-snmp \
--with-libcurl \
--with-libxml2
make && make install
#创建zabbix数据库
mysql -uroot -p
mysql> create database zabbix character set utf8 collate utf8_bin;
mysql> grant all privileges on zabbix.* to zabbix@localhost identified by 'your password';
mysql> flush privileges;
mysql> quit;
#导入数据库
mysql> use zabbix
mysql> source /root/zabbix-3.0.0rc1/database/mysql/schema.sql
mysql> source /root/zabbix-3.0.0rc1/database/mysql/images.sql
mysql> source /root/zabbix-3.0.0rc1/database/mysql/data.sql
mysql> quit;
#修改数据库连接文件
vi /usr/local/etc/zabbix_server.conf
#数据库名称
DBName=zabbix
#数据库用户名
DBUser=zabbix
#数据库密码
DBPassword=yourpassword
#数据库ip地址
ListenIP=localhost
#zabbix运行脚本存放目录
AlertScriptsPath=/usr/local/zabbix/alertscripts
:wq
chown -R zabbix.zabbix /usr/local/zabbix/
#复制启动脚本
cp /root/zabbix-3.0.0rc1/misc/init.d/fedora/core/zabbix_server /etc/rc.d/init.d/zabbix_server
cp /root/zabbix-3.0.0rc1/misc/init.d/fedora/core/zabbix_agentd /etc/rc.d/init.d/zabbix_agentd
#启动zabbix
service zabbix_server start
#查看10051端口是否监听
netstat -ntl
安装zabbix web
#修改php.ini配置
vi /usr/local/php/lib/php.ini
post_max_size 16M
max_execution_time 300
max_input_time 300
date.timezone=Asia/Shanghai
#重启php-fpm
service php-fpm restart
#复制zabbix web程序
cd /root/zabbix-3.0.0rc1/frontends/php
cp -rf ./* /home/wwwroot/zabbix/
chown -R nginx.nginx /home/wwwroot/zabbix/
#创建zabbix站点
vi /usr/local/nginx/conf/vhost/zabbix.conf
server{
listen 80;
server_name zabbix.suseyh.cn;
access_log /home/wwwlogs/zabbix.suseyh.cn_nginx.log combined;
index index.html index.htm index.php;
root /home/wwwroot/zabbix;
location ~ [^/]\.php(/|$) {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
}
:wq# service nginx restart
zabbix_agent 安装
#安装环境
SystemZabbix
Centos6.5 X86_64zabbix3.0.0RC1
wget http://jaist.dl.sourceforge.net/project/zabbix/ZABBIX%20Release%20Candidates/3.0.0rc1/zabbix-3.0.0rc1.tar.gz
tar -xvf zabbix-3.0.0rc1.tar.gz
cd zabbix-3.0.0rc1
ln -s /usr/local/lib/libiconv.so.2/usr/lib/libiconv.so.2
ldconfig
#添加zabbix用户
useradd zabbix
./configure --prefix=/usr/local/zabbix --enable-agent
make && make install
#添加系统软连接
ln -s /usr/local/zabbix/sbin/* /usr/local/sbin/
ln -s /usr/local/zabbix/bin/* /usr/local/bin/
#添加zabbix服务对应端口
echo 'zabbix-agent 10050/tcp #Zabbix Agent' >> /etc/services
echo 'zabbix-agent 10050/udp #Zabbix Agent' >> /etc/services
echo 'zabbix-trapper 10051/tcp #Zabbix trapper' >> /etc/services
echo 'zabbix-trapper 10051/udp #Zabbix trapper' >> /etc/services
#修改配置文件
vi /usr/local/zabbix/etc/zabbix_agentd.conf
Server = Your zabbix server IP
Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/
UnsafeUserParameters=1
:wq
#添加开机启动脚本
cp ./misc/init.d/fedora/core/zabbix_agentd /etc/rc.d/init.d/zabbix_agentd
#修改配置
vi /etc/rc.d/init.d/zabbix_agentd
#修改为zabbix安装目录
BASEDIR=/usr/local/zabbix/
#设置开机启动
chkconfig zabbix_agentd on
#启动zabbix_agentd服务
service zabbix_agentd start
#查看10050端口是否监听
netstat -ntl
zabbix_proxy安装
#编译安装
yum install net-snmp-devel curl-devel
./configure --prefix=/usr/local/zabbix-proxy --enable-proxy --with-mysql --with-net-snmp --with-libcurl
make && make install
#mysql设定
mysql -u -p
mysql> create database zabbix_proxy character set utf8;
mysql> GRANT ALL ON zabbix_proxy.* TO zabbixproxy@'localhost' IDENTIFIED BY 'zabbixproxy';
mysql> flush privileges;
mysql> quit;
cd create/schema
cat mysql.sql | mysql -u -p zabbix
#zabbix_proxy.conf配置文件设定:
Server=zabbix_server #zabbix server的ip地址或者域名
Hostname=zabbix-proxy-qyhk01 #proxy主机名,在zabbix web会以这个名字为准
#DB 设定档
DBName=zabbixproxy
DBUser=zabbixproxy
DBPassword=123456
ProxyLocalBuffer=0 #设定为0小时,除非有其他第三方应用和插件需要调用
ProxyOfflineBuffer=1 #proxy或者server无法连接时,保留离线的监控数据的时间,单位小时
ConfigFrequency=600 #server和proxy配置修改同步时间间隔,设定5-10分钟即可。
DataSenderFrequency=10 #数据发送时间间隔,10-30s;
#网络传输质量越好,可以设定间隔时间越短,监控效果也越迅速;
StartPollers=10 #开启多线程数,一般不要超过30个;
StartPollersUnreachable=1 #该线程用来单独监控无法连接的主机,1个即可;
StartTrappers=10 #trapper线程数
StartPingers=1 #fping线程数
CacheSize=64M #用来保存监控数据的缓存数,根据监控主机数量适当调整;
Timeout=10 #超时时间,设定不要超过30s,不然会拖慢其他监控数据抓取时间;
TrapperTimeout=30 #同上
FpingLocation=/usr/sbin/fping #配合simple check icmp检测使用,如不需要可关闭;
* 启动时需要导入zabbix数据
mysql -uzabbixproxy -p zabbix_proxy < schema.sql
推荐阅读
- career|万能辞职报告
- 小软件推荐|PicPick - 经典的截图软件
- Java|开源框架中文介绍地址
- oracle|Oracle PLSQL文档资料
- 网络管理|域名邮箱用GMAIL,live
- 汇编|MOV MVN 范围问题