zabbix 3.2.2自动安装脚本 (For Centos6)

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了zabbix 3.2.2自动安装脚本 (For Centos6)相关的知识,希望对你有一定的参考价值。

方法
一、上传源码包到centos上
二、复制需要安装部分的代码(如vi /etc/install-zabbix.sh 复制代码)
chmod +x /etc/install-zabbix.sh
/etc/install-zabbix.sh

shell代码如下: 


 #!/bin/sh

#服务端加客户端安装脚本

groupadd -g 493 zabbix

useradd -u 493 -g zabbix

tar xf zabbix-3.2.2.tar.gz -C /usr/local/

mkdir /usr/local/zabbix

mkdir /var/run/zabbix

mkdir /var/log/zabbix

cd /usr/local/zabbix-3.2.2/

./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2

make install

echo ‘export PATH=$PATH:/usr/local/zabbix/bin:/usr/local/zabbix/sbin‘ > /etc/profile.d/zabbix.sh

echo ‘PidFile=/var/run/zabbix/zabbix_server.pid‘ >> /usr/local/zabbix/etc/zabbix_server.conf

echo ‘PidFile=/var/run/zabbix/zabbix_agentd.pid‘ >> /usr/local/zabbix/etc/zabbix_agentd.conf

sed -i -e "s/tmp\/zabbix_server.log/var\/log\/zabbix\/zabbix_server.log/g" /usr/local/zabbix/etc/zabbix_server.conf

sed -i -e "s/tmp\/zabbix_agentd.log/var\/log\/zabbix\/zabbix_agentd.log/g" /usr/local/zabbix/etc/zabbix_agentd.conf

chown -R zabbix:zabbix /usr/local/zabbix

chown -R zabbix:zabbix /var/run/zabbix

chown -R zabbix:zabbix /var/log/zabbix

rm -rf /usr/local/zabbix-3.2.2/

#自启动脚本 客户端

echo ‘#!/bin/sh

#

# chkconfig: - 86 14

# description: Zabbix agent daemon

# processname: zabbix_agentd

# config: /usr/local/zabbix/etc/zabbix_agentd.conf

#

### BEGIN INIT INFO

# Provides: zabbix-agent

# Required-Start: $local_fs $network

# Required-Stop: $local_fs $network

# Should-Start: zabbix zabbix-proxy

# Should-Stop: zabbix zabbix-proxy

# Default-Start:

# Default-Stop: 0 1 2 3 4 5 6

# Short-Description: Start and stop Zabbix agent

# Description: Zabbix agent

### END INIT INFO

# Source function library.

. /etc/rc.d/init.d/functions

if [ -x /usr/local/zabbix/sbin/zabbix_agentd ]; then

    exec=/usr/local/zabbix/sbin/zabbix_agentd

else

    exit 5

fi

prog=${exec##*/}

conf=/usr/local/zabbix/etc/zabbix_agentd.conf

pidfile=$(grep -e "^PidFile=.*$" $conf | cut -d= -f2)

timeout=10

if [ -f /etc/sysconfig/zabbix-agent ]; then

    . /etc/sysconfig/zabbix-agent

fi

lockfile=/var/lock/subsys/zabbix-agent

start()

{

    echo -n $"Starting Zabbix agent: "

    daemon $exec -c $conf

    rv=$?

    echo

    [ $rv -eq 0 ] && touch $lockfile

    return $rv

}

stop()

{

    echo -n $"Shutting down Zabbix agent: "

    killproc -p $pidfile -d $timeout $prog

    rv=$?

    echo

    [ $rv -eq 0 ] && rm -f $lockfile

    return $rv

}

restart()

{

    stop

    start

}

case "$1" in

    start|stop|restart)

        $1

        ;;

    force-reload)

        restart

        ;;

    status)

        status -p $pidfile $prog 

        ;;

    try-restart|condrestart)

        if status $prog >/dev/null ; then

            restart

        fi

        ;;

    reload)

        action $"Service ${0##*/} does not support the reload action: " /bin/false

        exit 3

        ;;

    *)

        echo $"Usage: $0 {start|stop|status|restart|try-restart|force-reload}"

        exit 2

        ;;

esac‘ > /etc/init.d/zabbix-agent

chmod +x /etc/init.d/zabbix-agent

chkconfig --add zabbix-agent

chkconfig --level 35 zabbix-agent on

/etc/init.d/zabbix-agent start

#自启动脚本 服务端

echo ‘#!/bin/sh

#

# chkconfig: - 85 15

# description: Zabbix server daemon

# config: /usr/local/zabbix/etc/zabbix_server.conf

#

### BEGIN INIT INFO

# Provides: zabbix

# Required-Start: $local_fs $network

# Required-Stop: $local_fs $network

# Default-Start:

# Default-Stop: 0 1 2 3 4 5 6

# Short-Description: Start and stop Zabbix server

# Description: Zabbix server

### END INIT INFO

# Source function library.

. /etc/rc.d/init.d/functions

if [ -x /usr/local/zabbix/sbin/zabbix_server ]; then

    exec=/usr/local/zabbix/sbin/zabbix_server

else

    exit 5

fi

prog=${exec##*/}

conf=/usr/local/zabbix/etc/zabbix_server.conf

pidfile=$(grep -e "^PidFile=.*$" $conf | cut -d= -f2)

timeout=10

if [ -f /etc/sysconfig/zabbix-server ]; then

    . /etc/sysconfig/zabbix-server

fi

lockfile=/var/lock/subsys/zabbix-server

start()

{

    echo -n $"Starting Zabbix server: "

    daemon $exec -c $conf

    rv=$?

    echo

    [ $rv -eq 0 ] && touch $lockfile

    return $rv

}

stop()

{

    echo -n $"Shutting down Zabbix server: "

    killproc -p $pidfile -d $timeout $prog

    rv=$?

    echo

    [ $rv -eq 0 ] && rm -f $lockfile

    return $rv

}

restart()

{

    stop

    start

}

case "$1" in

    start|stop|restart)

        $1

        ;;

    force-reload)

        restart

        ;;

    status)

        status -p $pidfile $prog

        ;;

    try-restart|condrestart)

        if status $prog >/dev/null ; then

            restart

        fi

        ;;

    reload)

        action $"Service ${0##*/} does not support the reload action: " /bin/false

        exit 3

        ;;

    *)

echo $"Usage: $0 {start|stop|status|restart|try-restart|force-reload}"

exit 2

;;

esac‘ > /etc/init.d/zabbix-server

chmod +x /etc/init.d/zabbix-server

chkconfig --add zabbix-server

chkconfig --level 35 zabbix-server on

/etc/init.d/zabbix-server start

#客户端安装脚本

groupadd -g 493 zabbix

useradd -u 493 -g zabbix

tar xf zabbix-3.2.2.tar.gz -C /usr/local/

mkdir /usr/local/zabbix

mkdir /var/run/zabbix

mkdir /var/log/zabbix

cd /usr/local/zabbix-3.2.2/

./configure --prefix=/usr/local/zabbix --enable-agent

make install

echo ‘export PATH=$PATH:/usr/local/zabbix/bin:/usr/local/zabbix/sbin‘ > /etc/profile.d/zabbix.sh

chown -R zabbix:zabbix /usr/local/zabbix

chown -R zabbix:zabbix /var/run/zabbix

chown -R zabbix:zabbix /var/log/zabbix

echo ‘PidFile=/var/run/zabbix/zabbix_agentd.pid‘ >> /usr/local/zabbix/etc/zabbix_agentd.conf

sed -i -e "s/tmp\/zabbix_agentd.log/var\/log\/zabbix\/zabbix_agentd.log/g" /usr/local/zabbix/etc/zabbix_agentd.conf

rm -rf /usr/local/zabbix-3.2.2/

#自启动脚本 客户端

echo ‘#!/bin/sh

#

# chkconfig: - 86 14

# description: Zabbix agent daemon

# processname: zabbix_agentd

# config: /usr/local/zabbix/etc/zabbix_agentd.conf

#

### BEGIN INIT INFO

# Provides: zabbix-agent

# Required-Start: $local_fs $network

# Required-Stop: $local_fs $network

# Should-Start: zabbix zabbix-proxy

# Should-Stop: zabbix zabbix-proxy

# Default-Start:

# Default-Stop: 0 1 2 3 4 5 6

# Short-Description: Start and stop Zabbix agent

# Description: Zabbix agent

### END INIT INFO

# Source function library.

. /etc/rc.d/init.d/functions

if [ -x /usr/local/zabbix/sbin/zabbix_agentd ]; then

    exec=/usr/local/zabbix/sbin/zabbix_agentd

else

    exit 5

fi

prog=${exec##*/}

conf=/usr/local/zabbix/etc/zabbix_agentd.conf

pidfile=$(grep -e "^PidFile=.*$" $conf | cut -d= -f2)

timeout=10

if [ -f /etc/sysconfig/zabbix-agent ]; then

    . /etc/sysconfig/zabbix-agent

fi

lockfile=/var/lock/subsys/zabbix-agent

start()

{

    echo -n $"Starting Zabbix agent: "

    daemon $exec -c $conf

    rv=$?

    echo

    [ $rv -eq 0 ] && touch $lockfile

    return $rv

}

stop()

{

    echo -n $"Shutting down Zabbix agent: "

    killproc -p $pidfile -d $timeout $prog

    rv=$?

    echo

    [ $rv -eq 0 ] && rm -f $lockfile

    return $rv

}

restart()

{

    stop

    start

}

case "$1" in

    start|stop|restart)

        $1

        ;;

    force-reload)

        restart

        ;;

    status)

        status -p $pidfile $prog 

        ;;

    try-restart|condrestart)

        if status $prog >/dev/null ; then

            restart

        fi

        ;;

    reload)

        action $"Service ${0##*/} does not support the reload action: " /bin/false

        exit 3

        ;;

    *)

        echo $"Usage: $0 {start|stop|status|restart|try-restart|force-reload}"

        exit 2

        ;;

esac‘ > /etc/init.d/zabbix-agent

chmod +x /etc/init.d/zabbix-agent

chkconfig --add zabbix-agent

chkconfig --level 35 zabbix-agent on

/etc/init.d/zabbix-agent start

#web前端安装

cd /usr/local/zabbix-3.2.2/frontends/php

mkdir /usr/share/zabbix

cp -a ./ /usr/share/zabbix

chown -R apache:apache /usr/share/zabbix

希望对不能使用yum安装的小伙伴提供便利

脚本的缺点是如果重新安装建议删除/usr/local/zabbix 目录下的文件
再执行一次脚本 



以上是关于zabbix 3.2.2自动安装脚本 (For Centos6)的主要内容,如果未能解决你的问题,请参考以下文章

自动化安装zabbix脚本(3.0/3.2)

zabbix3.0/3.2/3.4自动安装脚本

自动安装zabbix客户端shell脚本

zabbix-agent自动安装脚本

windows上一键自动安装zabbix-agent

自动安装zabbix agent的shell脚本