-
zabbix服务端安装
1.使用脚本安装、脚本内容如下。安装完用http://192.168.159.20/zabbix
#!/bin/bash #使用说明,此版本是针对程序安装路径不在/opt/下的 #installZabbixServer里已经开启了--enable-agent #1.上传所需的文件到pageDir #libiconv-1.14.tar.gz #mysql-5.6.33-linux-glibc2.5-x86_64.tar.gz #php-5.6.21.tar.gz #zabbix-3.2.5.tar.gz #nginx-1.10.0.tar.gz #nginx.conf #msyh.ttf #服务端安装 # 1.修改变量serverIp 为服务端ip # 2.sh installZabbix_lnV3.sh #安装端安装 # 1.修改变量serverIp 为服务端ip # 2.check_server install_zabbixAgent 脚本最末端只留这个,其它注释掉。 # 3.执行 sh installZabbix_lnV3.sh pageDir="/opt/tools/" bdFile="/tmp/bdFile.txt" webUser="www" zabbixUser="zabbix" mysqlData="/home/mysql" serverIp="192.168.159.20" #安装zabbix-agent时指定zabbix-server ip dbhost="127.0.0.1" dbuser='zabbix' dbname='zabbix' dbpassword='123456' installDir="/opt" installDir2="/opt" [ -f /etc/yum.repos.d/epel-6.repo ] || wget -P /etc/yum.repos.d/ http://mirrors.aliyun.com/repo/epel-6.repo [ -d ${installDir} ] || mkdir -p ${installDir} check_ok() { if [ $? != 0 ] then echo "Error, Check the error log." exit 1 fi } myum() { if ! rpm -qa|grep -q "^$1" then yum install -y $1 check_ok else echo $1 already installed. fi } myum curl install_libiconv(){ cd $pageDir [ -f libiconv-1.14.tar.gz ] || wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz [ -d libiconv-1.14 ] || tar zxf libiconv-1.14.tar.gz cd libiconv-1.14 ./configure --prefix=${installDir}/libiconv check_ok make check_ok make install check_ok rm -rf libiconv-1.14 check_ok echo "install_libiconv" >> "$bdFile" echo "libiconv install ok" } install_phpfpm() { cd $pageDir [ -f php-5.6.21.tar.gz ] || wget http://cn2.php.net/get/php-5.6.21.tar.gz/from/this/mirror [ -d php-5.6.21.tar.gz ] || tar zxf php-5.6.21.tar.gz for p in libmcrypt libmcrypt-devel libxslt-devel libxslt zlib-devel libxml2-devel libjpeg-turbo-devel freetype-devel libpng-devel gd-devel libcurl-devel mhash mhash-devel do myum $p done if ! grep -q "$webUser" /etc/passwd then useradd -M -s /sbin/nologin "$webUser" check_ok fi cd php-5.6.21 ./configure --prefix=${installDir}/php-5.6.21 --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir=${installDir}/libiconv/ --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --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 --with-gettext --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --enable-short-tags --enable-static --with-xsl --with-fpm-user="$webUser" --with-fpm-group="$webUser" --enable-fpm --enable-ftp --enable-opcache=yes check_ok make && make install check_ok ln -sv ${installDir}/php-5.6.21 ${installDir}/php check_ok [ -f ${installDir}/php/etc/php.ini ] || /bin/cp php.ini-production ${installDir}/php/etc/php.ini if ${installDir}/php/bin/php -i |grep -iq 'date.timezone => no value' then sed -i '/;date.timezone =$/adate.timezone = "Asia/Chongqing"' ${installDir}/php/etc/php.ini check_ok fi [ -f ${installDir}/php/etc/php-fpm.conf ] || cp ${installDir}/php/etc/php-fpm.conf.default ${installDir}/php/etc/php-fpm.conf check_ok [ -f /etc/init.d/phpfpm ] || /bin/cp sapi/fpm/init.d.php-fpm /etc/init.d/phpfpm chmod 755 /etc/init.d/phpfpm chkconfig phpfpm on service phpfpm start check_ok cd $pageDir rm -rf php-5.6.21 echo "phpfpm install ok" echo "install_phpfpm" >> "$bdFile" } install_nginx(){ for i in pcre pcre-devel zlib gcc openssl openssl-devel zlib-devel do myum $i done cd $pageDir [ -f nginx-1.10.0.tar.gz ] || wget http://nginx.org/download/nginx-1.10.0.tar.gz [ -d nginx-1.10.0 ] || tar -zxf nginx-1.10.0.tar.gz if ! grep -q "^$webUser" /etc/passwd then useradd -M -s /sbin/nologin "$webUser" check_ok fi cd nginx-1.10.0 ./configure --user="$webUser" --group="$webUser" --prefix=${installDir}/nginx-1.10.0 --with-pcre --with-http_stub_status_module --with-http_ssl_module check_ok make check_ok make install check_ok ln -sv ${installDir}/nginx-1.10.0 ${installDir}/nginx curl http://www.apelearn.com/study_v2/.nginx_init -o /etc/init.d/nginx sed -i "s@/usr/local@${installDir}@g" /etc/init.d/nginx chmod 755 /etc/init.d/nginx chkconfig nginx on #[ -f nginx.conf ] || curl http://www.apelearn.com/study_v2/.nginx_conf -o ${installDir}/nginx/conf/nginx.conf mv ${installDir}/nginx/conf/nginx.conf{,.bak} && cp -a $pageDir/nginx.conf ${installDir}/nginx/conf/ sed -i "s@/usr/local@${installDir}@g" ${installDir}/nginx/conf/nginx.conf check_ok sed -i 's#fastcgi_pass unix:/tmp/php-fcgi.sock;#fastcgi_pass 127.0.0.1:9000;#' ${installDir}/nginx/conf/nginx.conf service nginx start check_ok echo -e "<?php phpinfo(); ?>" > ${installDir}/nginx/html/index.php check_ok cd $pageDir rm -rf nginx-1.10.0 check_ok echo "nginx install ok" echo "install_nginx" >> "$bdFile" } install_mysql(){ cd $pageDir [ -f mysql-5.6.33-linux-glibc2.5-x86_64.tar.gz ] || wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.33-linux-glibc2.5-x86_64.tar.gz tar zxf mysql-5.6.33-linux-glibc2.5-x86_64.tar.gz check_ok [ -d ${installDir}/mysql ] && /bin/mv ${installDir}/mysql ${installDir}/mysql_bak mv mysql-5.6.33-linux-glibc2.5-x86_64 ${installDir}/mysql-5.6.33 if ! grep '^mysql:' /etc/passwd then useradd -M mysql -s /sbin/nologin fi for i in compat-libstdc++-33 libaio libaio-devel do myum $i done [ -d $mysqlData ] && /bin/mv $mysqlData $mysqlData_bak mkdir -p $mysqlData chown -R mysql:mysql $mysqlData ln -sv ${installDir}/mysql-5.6.33 ${installDir}/mysql cd ${installDir}/mysql ./scripts/mysql_install_db --user=mysql --datadir="$mysqlData" check_ok /bin/cp support-files/my-default.cnf /etc/my.cnf check_ok sed -i "/^[mysqld]$/adatadir = ${mysqlData}" /etc/my.cnf /bin/cp support-files/mysql.server /etc/init.d/mysqld sed -i "s#^datadir=#datadir=${mysqlData}#" /etc/init.d/mysqld sed -i "s@usr/local@${installDir}@g" /etc/init.d/mysqld chmod 755 /etc/init.d/mysqld chkconfig --add mysqld chkconfig mysqld on echo "mysql install ok" echo "install_mysql" >> "$bdFile" service mysqld start check_ok } install_zabbixServer(){ myum net-snmp-devel myum mysql-devel echo "${installDir}/mysql/lib/" >> /etc/ld.so.conf ldconfig check_ok cd $pageDir [ -f zabbix-3.2.5.tar.gz ] || wget http://repo.zabbix.com/zabbix/3.0/ubuntu/pool/main/z/zabbix/zabbix-3.2.5.tar.gz [ -d zabbix-3.2.5 ] || tar zxf zabbix-3.2.5.tar.gz if ! grep -q "^$zabbixUser" /etc/passwd then useradd -M -s /sbin/nologin $zabbixUser check_ok fi cd zabbix-3.2.5 ./configure --prefix=${installDir}/zabbix-3.2.5 --enable-server --enable-agent --with-mysql=mysqld --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2 check_ok make check_ok make install check_ok rm -rf ${installDir}/zabbix && ln -sv ${installDir}/zabbix-3.2.5 ${installDir}/zabbix check_ok [ -d ${installDir}/nginx/html/zabbix ] || mkdir -p ${installDir}/nginx/html/zabbix cp -R frontends/php/* ${installDir}/nginx/html/zabbix/ chown -R $webUser.$webUser ${installDir}/nginx/html/zabbix check_ok rm -f /etc/init.d/zabbix* cp misc/init.d/fedora/core/zabbix_server /etc/rc.d/init.d/zabbix_server cp misc/init.d/fedora/core/zabbix_agentd /etc/rc.d/init.d/zabbix_agentd sed -i "s#BASEDIR=/usr/local#BASEDIR=${installDir}/zabbix#" /etc/init.d/zabbix_server sed -i "/BASEDIR=${installDir2}/zabbix$/aBASECONF=${installDir2}/zabbix/etc/zabbix_server.conf" /etc/init.d/zabbix_server sed -i 's/action $"Starting $BINARY_NAME: " $FULLPATH/action $"Starting $BINARY_NAME: " $FULLPATH -c $BASECONF/' /etc/init.d/zabbix_server sed -i "s/# DBHost=localhost/DBHost=${dbhost}/" ${installDir}/zabbix/etc/zabbix_server.conf sed -i "s/# DBPassword=/DBPassword=${dbpassword}/" ${installDir}/zabbix/etc/zabbix_server.conf if ${installDir}/mysql/bin/mysql -uroot -e "show databases" | grep -q ${dbname} ;then ${installDir}/mysql/bin/mysql -uroot -e "drop database ${dbname};" fi ${installDir}/mysql/bin/mysql -uroot -e "create database ${dbname} default character set utf8;" check_ok if ! ${installDir}/mysql/bin/mysql -uroot -e "select user from mysql.user where user='${dbuser}';" | grep -q ${dbuser};then ${installDir}/mysql/bin/mysql -uroot -e "grant all privileges on ${dbname}.* to '${dbuser}'@'${dbhost}' identified by '${dbpassword}';flush privileges;" check_ok fi cd $pageDir cd zabbix-3.2.5 ${installDir}/mysql/bin/mysql -u${dbuser} -p${dbpassword} -h ${dbhost} ${dbname} < database/mysql/schema.sql check_ok ${installDir}/mysql/bin/mysql -u${dbuser} -p${dbpassword} -h ${dbhost} ${dbname} < database/mysql/images.sql check_ok ${installDir}/mysql/bin/mysql -u${dbuser} -p${dbpassword} -h ${dbhost} ${dbname} < database/mysql/data.sql check_ok sed -i 's/post_max_size = 8M/post_max_size = 16M/' ${installDir}/php/etc/php.ini sed -i 's/max_execution_time = 30/max_execution_time = 300/' ${installDir}/php/etc/php.ini sed -i 's/max_input_time = 60/max_input_time = 300/' ${installDir}/php/etc/php.ini sed -i 's/;always_populate_raw_post_data = -1/always_populate_raw_post_data = -1/' ${installDir}/php/etc/php.ini if ${installDir}/php/bin/php -i |grep -iq 'date.timezone => no value' then sed -i '/;date.timezone =$/adate.timezone = "Asia/Chongqing"' ${installDir}/php/etc/php.ini check_ok fi sed -i 's@php_fpm_CONF=${prefix}/etc/php-fpm.conf@php_fpm_CONF=${prefix}/etc/php.ini@' /etc/init.d/phpfpm sed -i 's/php_opts="--fpm-config $php_fpm_CONF --pid $php_fpm_PID"/php_opts="-c $php_fpm_CONF --pid $php_fpm_PID"/' /etc/init.d/phpfpm /etc/init.d/phpfpm restart check_ok /etc/init.d/zabbix_server start check_ok chkconfig --add zabbix_server check_ok chkconfig zabbix_server on check_ok echo "install zabbix_server ok" echo "install_zabbixServer" >> "$bdFile" #客户端 sed -i "s@BASEDIR=/usr/local@BASEDIR=${installDir}/zabbix@g" /etc/init.d/zabbix_agentd sed -i "/BASEDIR=${installDir2}/zabbix$/aBASECONF=${installDir2}/zabbix/etc/zabbix_agentd.conf" /etc/init.d/zabbix_agentd sed -i 's/action $"Starting $BINARY_NAME: " $FULLPATH/action $"Starting $BINARY_NAME: " $FULLPATH -c $BASECONF/' /etc/init.d/zabbix_agentd # Include=/usr/local/etc/zabbix_agentd.conf.d/*.conf sed -i "s/Server=127.0.0.1/Server=$serverIp/" ${installDir}/zabbix/etc/zabbix_agentd.conf sed -i "s@# Include=/usr/local/etc/zabbix_agentd.conf.d/*.conf@Include=${installDir}/zabbix/etc/zabbix_agentd.conf.d/*.conf@g" ${installDir}/zabbix/etc/zabbix_agentd.conf sed -i 's/ServerActive=127.0.0.1/ServerActive=0.0.0.0:10050/' ${installDir}/zabbix/etc/zabbix_agentd.conf sed -i 's/# UnsafeUserParameters=0/UnsafeUserParameters=1/g' ${installDir}/zabbix/etc/zabbix_agentd.conf /etc/init.d/zabbix_agentd start check_ok chkconfig --add zabbix_agentd check_ok chkconfig zabbix_agentd on check_ok echo "install_zabbixAgent install ok" echo "install_zabbixAgent" >> "$bdFile" } install_zabbixAgent(){ if ! grep -q "^$zabbixUser" /etc/passwd then useradd -M -s /sbin/nologin $zabbixUser check_ok fi cd $pageDir [ -f zabbix-3.2.5.tar.gz ] || wget http://repo.zabbix.com/zabbix/3.0/ubuntu/pool/main/z/zabbix/zabbix-3.2.5.tar.gz [ -d zabbix-3.2.5 ] || tar zxf zabbix-3.2.5.tar.gz cd zabbix-3.2.5 ./configure --prefix=${installDir}/zabbix-3.2.5 --enable-agent check_ok make check_ok make install check_ok [ -l ${installDir}/zabbix ] || ln -sv ${installDir}/zabbix-3.2.5 ${installDir}/zabbix cp misc/init.d/fedora/core/zabbix_agentd /etc/rc.d/init.d/zabbix_agentd sed -i "s@BASEDIR=/usr/local@BASEDIR=${installDir}/zabbix@g" /etc/init.d/zabbix_agentd sed -i "/BASEDIR=${installDir2}/zabbix$/aBASECONF=${installDir2}/zabbix/etc/zabbix_agentd.conf" /etc/init.d/zabbix_agentd sed -i 's/action $"Starting $BINARY_NAME: " $FULLPATH/action $"Starting $BINARY_NAME: " $FULLPATH -c $BASECONF/' /etc/init.d/zabbix_agentd # Include=/usr/local/etc/zabbix_agentd.conf.d/*.conf sed -i "s/Server=127.0.0.1/Server=$serverIp/" ${installDir}/zabbix/etc/zabbix_agentd.conf sed -i "s@# Include=/usr/local/etc/zabbix_agentd.conf.d/*.conf@Include=${installDir}/zabbix/etc/zabbix_agentd.conf.d/*.conf@g" ${installDir}/zabbix/etc/zabbix_agentd.conf sed -i 's/ServerActive=127.0.0.1/ServerActive=0.0.0.0:10050/' ${installDir}/zabbix/etc/zabbix_agentd.conf sed -i 's/# UnsafeUserParameters=0/UnsafeUserParameters=1/g' ${installDir}/zabbix/etc/zabbix_agentd.conf #sed -i "s@BASEDIR=/usr/local@BASEDIR=${installDir}/zabbix@g" /etc/init.d/zabbix_agentd #sed -i '/BASEDIR='${installDir}'/zabbix$/aBASECONF='${installDir}'/zabbix/etc/zabbix_agentd.conf' /etc/init.d/zabbix_agentd #sed -i 's/action $"Starting $BINARY_NAME: " $FULLPATH/action $"Starting $BINARY_NAME: " $FULLPATH -c $BASECONF/' /etc/init.d/zabbix_agentd #sed -i "s/Server=127.0.0.1/Server=$serverIp/" ${installDir}/zabbix/etc/zabbix_agentd.conf #sed -i "s/# Include=/usr/local/etc/zabbix_agentd.conf.d/*.conf/Include=${installDir}/zabbix/etc/zabbix_agentd.conf.d/*.conf/" ${installDir}/zabbix/etc/zabbix_agentd.conf #sed -i 's/ServerActive=127.0.0.1/ServerActive=0.0.0.0:10050/' ${installDir}/zabbix/etc/zabbix_agentd.conf #sed -i 's/# UnsafeUserParameters=0/UnsafeUserParameters=1/g' ${installDir}/zabbix/etc/zabbix_agentd.conf /etc/init.d/zabbix_agentd start check_ok chkconfig --add zabbix_agentd check_ok chkconfig zabbix_agentd on check_ok echo "install_zabbixAgent install ok" echo "install_zabbixAgent" >> "$bdFile" } check_server(){ if ! grep -q "$1" "$bdFile" then "$1" fi } check_server install_nginx check_server install_libiconv check_server install_phpfpm check_server install_mysql check_server install_zabbixServer #check_server install_zabbixAgent
2.页面配置
访问http://192.168.159.20/zabbix
点击
next
next
Configure DB connection(host:127.0.0.1 port:3306 daname: zabbix user: zabbix password:xxxx) next
配置 zabbix server next
next
finsh
登入默认用户(admin/zabbix)
中文支持
修改locales.inc.php
vim /opt/nginx/html/zabbix/include/locales.inc.php
找到
'zh_CN' => ['name' => _('Chinese (zh_CN)'), 'display' => fales]
把fales改成true
图片支持中文
在更换完中文后我们的监控图片会出现乱码因为图片这里不支持中文我们这么做
修改defines.inc.php
#修改第45行改为
define('ZBX_GRAPH_FONT_NAME', 'simkai')
#修改第93行
define('ZBX_FONT_NAME', 'simkai');
1、从windows下控制面板->字体->选择一种中文字库例如“楷体”
2、将字体复制到/apps/nginx-1.10.0/html/zabbix/fonts/目录下
3、最后在用户中设置即可
zabbix_proxy安装和配置
useradd -M -s /sbin/nologin zabbix yum install mysql-devel net-snmp-devel curl-devel -y ./configure --prefix=/opt/zabbix-proxy --enable-proxy --enable-agent --with-mysql --with-net-snmp --with-libcurl make && make install [root@devops etc]# cat zabbix_agentd.conf LogFile=/tmp/zabbix_agentd.log Server=10.200.0.26 ServerActive=127.0.0.1 Hostname=10.200.0.26 Include=/opt/zabbix_proxy/etc/zabbix_agentd.conf.d/*.conf [root@devops etc]# cat zabbix_proxy.conf Server=218.70.106.250 Hostname=47.100.217.13 LogFile=/tmp/zabbix_proxy.log DBHost=218.70.106.250 DBName=zabbix_proxy DBUser=zabbix_proxy DBPassword=zabbix@puyi DBPort=13306 ConfigFrequency=60 DataSenderFrequency=60 Timeout=4 FpingLocation=/usr/local/sbin/fping LogSlowQueries=3000 #启动脚本 #!/bin/sh # chkconfig: 345 95 95 # desctription: Zabbix Proxy # Zabbix # Copyright (C) 2001-2013 Zabbix SIA # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Start/Stop the Zabbix agent daemon. # Place a startup script in /sbin/init.d, and link to it from /sbin/rc[023].d SERVICE="Zabbix proxy" DAEMON=/opt/apps/zabbix/zabbix_proxy/sbin/zabbix_proxy PIDFILE=/tmp/zabbix_proxy.pid BASEDIR=/opt/apps/zabbix/ ZABBIX_AGENTD=$BASEDIR/zabbix_proxy/sbin/zabbix_proxy case $1 in 'start') if [ -x ${DAEMON} ] then $DAEMON # Error checking here would be good... echo "${SERVICE} started." else echo "Can't find file ${DAEMON}." echo "${SERVICE} NOT started." fi ;; 'stop') if [ -s ${PIDFILE} ] then if kill `cat ${PIDFILE}` >/dev/null 2>&1 then echo "${SERVICE} terminated." rm -f ${PIDFILE} fi fi ;; 'restart') $0 stop sleep 10 $0 start ;; *) echo "Usage: $0 start|stop|restart" ;; esac
控制台添加proxy代理
centos7 zabbix_agentd启动脚本
[root@devops init.d]# cat /etc/init.d/zabbix_agentd #!/bin/bash # # chkconfig: - 90 10 # description: Starts and stops Zabbix Agent using chkconfig # Tested on Fedora Core 2 - 5 # Should work on all Fedora Core versions # # @name: zabbix_agentd # @author: Alexander Hagenah <hagenah@topconcepts.com> # @created: 18.04.2006 # # Modified for Zabbix 2.0.0 # May 2012, Zabbix SIA # # Source function library. #. /etc/init.d/functions # Variables # Edit these to match your system settings # Zabbix-Directory BASEDIR=/opt/zabbix-proxy BASECONF=/opt/zabbix-proxy/etc/zabbix_agentd.conf # Binary File BINARY_NAME=zabbix_agentd # Full Binary File Call FULLPATH=$BASEDIR/sbin/$BINARY_NAME # PID file PIDFILE=/tmp/$BINARY_NAME.pid # Establish args ERROR=0 STOPPING=0 # # No need to edit the things below # # application checking status if [ -f $PIDFILE ] && [ -s $PIDFILE ] then PID=`cat $PIDFILE` if [ "x$PID" != "x" ] && kill -0 $PID 2>/dev/null && [ $BINARY_NAME == `ps -e | grep $PID | awk '{print $4}'` ] then STATUS="$BINARY_NAME (pid `pidof $APP`) running.." RUNNING=1 else rm -f $PIDFILE STATUS="$BINARY_NAME (pid file existed ($PID) and now removed) not running.." RUNNING=0 fi else if [ `ps -e | grep $BINARY_NAME | head -1 | awk '{ print $1 }'` ] then STATUS="$BINARY_NAME (pid `pidof $APP`, but no pid file) running.." else STATUS="$BINARY_NAME (no pid file) not running" fi RUNNING=0 fi # functions start() { if [ $RUNNING -eq 1 ] then echo "$0 $ARG: $BINARY_NAME (pid $PID) already running" else $FULLPATH touch /var/lock/subsys/$BINARY_NAME fi } stop() { echo -n $"Shutting down $BINARY_NAME: " killproc $BINARY_NAME RETVAL=$? echo [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$BINARY_NAME RUNNING=0 } # logic case "$1" in start) start ;; stop) stop ;; status) status $BINARY_NAME ;; restart) stop sleep 10 start ;; help|*) echo $"Usage: $0 {start|stop|status|restart|help}" cat <<EOF start - start $BINARY_NAME stop - stop $BINARY_NAME status - show current status of $BINARY_NAME restart - restart $BINARY_NAME if running by sending a SIGHUP or start if not running help - this screen EOF exit 1 ;; esac exit 0