zabbix_Server一键源码安装脚本

如下是zabbix_server以及zabbix_agent(本地)一键源码安装脚本,若执行中出错,可以根据自己情况适当调整脚本。

#!/bin/bash

cat << EOF
This is how zabbix is installed scprits
EOF
ming (){
read -p "You need to install zabbix(YES|NO):" zab
read -p "Please input zabbix version(2.4.7|3.4.10):" VERSION
read -p "Please input mysql passwd:" passwd
case $zab in 
YES)
#echo "install zabbix_server"
yum install -y net-snmp net-snmp-devel curl curl-devel libxml2 libxml2-devel gcc gcc-c++ mysql-devel libevent-devel 
echo "create user................................start................."
groupadd -g 1001 zabbix
useradd -u 1001 -g 1001 -s /sbin/nologin -M zabbix
[ -d "/root/ruanjian" ]&& echo "cunzai" || mkdir /root/ruanjian
cd /root/ruanjian
wget https://jaist.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/$VERSION/zabbix-"$VERSION".tar.gz
tar zxf /root/ruanjian/zabbix-"$VERSION".tar.gz && cd /root/ruanjian/zabbix-$VERSION
sleep 10
./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --with-mysql --with-net-snmp --with-libcurl --with-libxml2
sleep 10
make && make install
sleep 10

############
if [ `cat /etc/services |grep zabbix |wc -l` -ne 0 ];then
   echo "file ok"
  else
cat >> /etc/services <  zabbix-agent    10050/tcp               # Zabbix Agent
  zabbix-agent    10050/udp               # Zabbix Agent
  zabbix-trapper  10051/tcp               # Zabbix Trapper
  zabbix-trapper  10051/udp               # Zabbix Trapper
eof
fi
#echo "export shuju......................................."
##mysql 5.7 xiugai mima zhixing.......
#!) 从日志过滤passwd 设为变量   mysqladmin -uroot -p$password password 'Redhat@123
sleep 10
###xiugai   kude mima
desc=/root/ruanjian/zabbix-$VERSION
mysql -uroot -p$passwd -e "create database zabbix character set utf8 collate utf8_general_ci;"
mysql -uroot -p$passwd zabbix < $desc/database/mysql/schema.sql 
mysql -uroot -p$passwd zabbix < $desc/database/mysql/images.sql
mysql -uroot -p$passwd zabbix < $desc/database/mysql/data.sql
mysql -uroot -p$passwd -e "grant all privileges on zabbix.* to zabbix@'%' identified by '123456';"
mysql -uroot -p$passwd -e "grant all privileges on zabbix.* to zabbix@'localhost' identified by '123456';"
mysql -uroot -p$passwd -e " flush privileges;"
sleep 10
###修改zabbix_Server配置文件
DIR=/root/ruanjian/zabbix-$VERSION
/bin/cp $DIR/misc/init.d/fedora/core/zabbix_server /etc/init.d/
sed -i 's/BASEDIR=\/usr\/local/BASEDIR=\/usr\/local\/zabbix/g' /etc/init.d/zabbix_server

#[ -d /var/log/zabbix/ ] && echo "cunzai" || echo mkdir -p /var/log/zabbix/ ;chown -R zabbix:zabbix /var/log/zabbix/
if [ -d /var/log/zabbix/ ];then
  echo "cunzai" 
 else 
 mkdir -p /var/log/zabbix/ 
 chown -R zabbix:zabbix /var/log/zabbix/
fi
/bin/cp /usr/local/zabbix/etc/zabbix_server.conf /usr/local/zabbix/etc/zabbix_server.conf.bak
dire=/usr/local/zabbix
sed -i 's#LogFile=\/tmp\/zabbix_server.log#LogFile=\/var\/log\/zabbix\/zabbix_server.log#g' $dire/etc/zabbix_server.conf
sed -i 's#DBUser=zabbix#DBUser=zabbix#g' $dire/etc/zabbix_server.conf
sed -i 's/# DBPassword=/DBPassword=123456/g' $dire/etc/zabbix_server.conf
sed -i 's/# DBPort=3306/DBPort=3306/g' $dire/etc/zabbix_server.conf 
sed -i 's/# DBHost=localhost/DBHost=127.0.0.1/g' $dire/etc/zabbix_server.conf
sed -i 's/# LogFileSize=1/LogFileSize=0/g'

##启动zabbix_server
cat /etc/redhat-release |awk -F " " '{print $0}'
read -p "Please select your Linux system(6|7):" system
case $system in
6)
/etc/init.d/zabbix_server start    #centos6 start
[ `ps -ef|grep zabbix|grep -v "grep"|wc -l` -ne 0 ]&& echo "zabbix_server is runing"||echo "zabbix_server is flase"
;;
7)
/usr/local/zabbix/sbin/zabbix_server -c /usr/local/zabbix/etc/zabbix_server.conf
[ `ps -ef|grep zabbix|grep -v "grep"|wc -l` -ne 0 ]&& echo "zabbix_server is runing"||echo "zabbix_server is flase"
;;
esac
####
##echo "zabbix_server is runing"
sleep 10

###是否配置本地zabbix客户端
read -p "Do you need to configure the client(YES|NO):" zabbix_agent
read -p "Please input localhost zabbix_Server IP(127.0.0.1):" SERVERIP
case $zabbix_agent in
YES)
###修改配置文件
/bin/cp $DIR/misc/init.d/fedora/core/zabbix_agentd /etc/init.d/
sed -i 's/BASEDIR=\/usr\/local/BASEDIR=\/usr\/local\/zabbix/g' /etc/init.d/zabbix_agentd

if [ -d /var/log/zabbix/ ];then
  echo "cunzai" 
 else 
 mkdir -p /var/log/zabbix/ 
 chown -R zabbix:zabbix /var/log/zabbix/
fi

/bin/cp /usr/local/zabbix/etc/zabbix_agentd.conf /usr/local/zabbix/etc/zabbix_agentd.conf.bak
sed -i 's/LogFile=\/tmp\/zabbix_agentd.log/LogFile=\/var\/log\/zabbix\/zabbix_agentd.log/g' /usr/local/zabbix/etc/zabbix_agentd.conf
sed -i 's/# PidFile=\/tmp\/zabbix_agentd.pid/PidFile=\/var\/log\/zabbix\/zabbix_agentd.pid/g' /usr/local/zabbix/etc/zabbix_agentd.conf
sed -i 's/Server=127.0.0.1/#Server=127.0.0.1/g' /usr/local/zabbix/etc/zabbix_agentd.conf
sed -i 's/ServerActive=127.0.0.1/#ServerActive=127.0.0.1/g' /usr/local/zabbix/etc/zabbix_agentd.conf
sed -i 's/Hostname=Zabbix server/#Hostname=Zabbix server/g' /usr/local/zabbix/etc/zabbix_agentd.conf

cat >>/usr/local/zabbix/etc/zabbix_agentd.conf <LogFileSize=0
EnableRemoteCommands=0
Server=$SERVERIP
ListenPort=10050
ListenIP=0.0.0.0
ServerActive=$SERVERIP
Hostname=127.0.0.1
Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/
eof
#配置启动
cat /etc/redhat-release |awk -F " " '{print $0}'
read -p "Please select your Linux system(6|7):" systemid
case $systemid in
6)
/etc/init.d/zabbix_agentd start    #centos6 start
[ `ps -ef|grep zabbix|grep -v "grep"|wc -l` -ne 0 ]&& echo "zabbix_agent is runing"||echo "zabbix_agent is flase"
;;
7)
/usr/local/zabbix/sbin/zabbix_agentd -c /usr/local/zabbix/etc/zabbix_agentd.conf
[ `ps -ef|grep zabbix|grep -v "grep"|wc -l` -ne 0 ]&& echo "zabbix_agent is runing"||echo "zabbix_agent is flase"
;;
esac
;;
NO)
exit
;;
esac

cat << EOF
readme 
在启动完zabbix服务之后,还需要配置zabbix的页面安装,
/root/ruanjian/zabbix-3.4.10/frontends/php/* /www/html
需要配置nginx的配置文件,把访问路径指向zabbix的安装目录。
EOF
;;
NO)
exit
;;
esac
}
read -p "You need to install lnmp(yes|no):" answer 
case $answer in
yes)
#build  lnmp
[ -d /root/old ] && rm -rf /root/old;mkdir /root/old || mkdir /root/old
mv /etc/yum.repos.d/* /root/old
cp -r /root/old/* /etc/yum.repos.d/
rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm
sleep 10
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
yum clean all
yum repolist
sleep 10
#start
yum -y install openssl-devel gcc-c++ gcc make 
echo "waiting install php..........................................................."
yum install -y php56w-fpm php56w-common php56w-mbstring php56w-mcrypt php56w-pdo php56w-pgsql php56w-mysqlnd php56w-gd php56w-bcmath php56w-xml php56w-ldap 
sed -i 's/post_max_size = 8M/post_max_size = 32M/g' /etc/php.ini
sed -i 's/max_execution_time = 30/max_execution_time = 600/g' /etc/php.ini
sed -i 's/max_input_time = 60/max_input_time = 600/g' /etc/php.ini
sed -i 's/upload_max_filesize = 2M/upload_max_filesize = 8M/g' /etc/php.ini
sed -i 's/;always_populate_raw_post_data = -1/always_populate_raw_post_data = -1/g' /etc/php.ini
sed -i 's/listen.allowed_clients = 127.0.0.1/#listen.allowed_clients = 127.0.0.1/g' /etc/php-fpm.d/www.conf

systemctl enable php-fpm
systemctl start php-fpm
sleep 10
echo "waiting for nginx......................................................."
yum install -y nginx
nginx -t
nginx
sleep 10
echo "waiting for mysql5.6................................"
[ -d "/root/ruanjian" ]&& echo "cunzai" || mkdir /root/ruanjian
cd /root/ruanjian
rpm -Uvh http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
yum repolist all | grep "mysql.*-community.*"
yum -y install mysql-community-server
systemctl enable mysqld
/bin/systemctl start mysqld.service
#mysql -uroot -p"" -e "set password=password('123456');"
mysqladmin -uroot -p password '123456'
sleep 10
echo "lnmp is success"
sleep 10
ming
;;
no)
ming
;;
esac

echo "若访问不了,查看端口是否都有放开"

cat <zabbix的web端配置可参考
server {  
listen  80;  
server_name 1123.com;  
           #   client_header_buffer_size 16k;
          #    large_client_header_buffers 4 32k;
           #   client_max_body_size 300m;
           #   client_body_buffer_size 128k;

              location / {
                        root               /www/ss;
                        index              index.php;
                       proxy_connect_timeout 3000;
                        proxy_send_timeout 3000;
                         proxy_read_timeout 3000;
                        proxy_buffer_size 4k;
                        proxy_buffers 4 32k;
                       proxy_busy_buffers_size 64k;

                       # if (!-e $request_filename) {
                       # rewrite ^/index.php(.*)$ /index.php?s=$1 last;
                       # rewrite ^(.*)$ /index.php?s=$1 last;
                       # break;
                       #                            }
                          }

              location ~ \.php$ {
                        root            /www/ss;
                        fastcgi_pass   127.0.0.1:9000;
                        fastcgi_index  index.php;
                        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                        include        fastcgi_params;
                               }
      }
eof

你可能感兴趣的:(脚本)