很久之前写的一个脚本,在收拾硬盘的时候发现的,这里发下,仅供大家参考.
资源地址:https://download.csdn.net/download/xzm5708796/11111918
说明:脚本是由zabbix2.X 版本升级到3.X版本的一键升级脚本,由于3版本升级了很多的功能,所有弃用了2X版本的,进行升级需求的实现!!!
#!/bin/bash
#writting by skyfans
#date 20170608
#使用注意事项
#(1)注意修改你的数据库的密码位置,skyfans8888,可以直接替换
#(2)本文件是进行zabbix及其中间件升级操作,
#(3)各个升级版本说明:apache,升级版本至2.4.25
# php升级至5.6.31
# zabbix升级至3.0版本
#version 1.1
BASE_DIR=/opt/update_apache
#--------------------------------1-------------------------------------------------------
function update_httpd(){
cd $BASE_DIR
yum remove -y httpd
yum install gcc* -y
tar -zxf apr-1.5.2.tar.gz
cd apr-1.5.2
./configure --prefix=/usr/local/apr
make
make install
cd $BASE_DIR
tar -zxf apr-util-1.5.4.tar.gz
cd apr-util-1.5.4
./configure --prefix=/usr/local/apr-util -with-apr=/usr/local/apr/bin/apr-1-config
make
make install
cd $BASE_DIR
tar -zxf pcre-8.40.tar.gz
cd pcre-8.40
./configure --prefix=/usr/local/pcre
make
make install
cd $BASE_DIR
tar -zxf httpd-2.4.25.tar.gz
cp -rf apr-1.5.2 httpd-2.4.25/srclib/apr
cp -rf apr-util-1.5.4 httpd-2.4.25/srclib/apr-util
cd httpd-2.4.25
./configure --prefix=/usr/local/apache2 --with-included-apr --with-pcre=/usr/local/pcre
make
make install
cp /usr/local/apache2/bin/apachectl /etc/rc.d/init.d/httpd
sed -i '/#!\/bin\/sh/a\#chkconfig: 2345 10 90\n#description:Activates/DeactivatesApacheWebServer' /etc/rc.d/init.d/httpd
sed -i 's/#ServerName www.example.com:80/ServerName localhost:80/' /usr/local/apache2/conf/httpd.conf
chkconfig --add httpd
chkconfig httpd on
}
#------------------------------------2------------------------------------------------------------------------------------------
function update_php(){
cd /
yum remove -y php*
cd $BASE_DIR
yum install bzip2-devel freetype freetype-devel libjpeg-6b libjpeg-devel libpng libpng-devel libxml2-devel -y
tar -zxvf php-5.6.31.tar.gz
cd php-5.6.31
./configure --prefix=/usr/local/php --with-config-file-path=/etc/ --with-apxs2=/usr/local/apache2/bin/apxs --with-bz2 --with-curl --with-libdir=lib64 --with-jpeg-dir=/usr/local --with-png-dir=/usr/local --with-freetype-dir=/usr/local --with-libxml-dir=/usr/local --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-mysql=mysqlnd --with-gettext --with-zlib --with-gd --enable-sockets --disable-ipv6 --enable-gd-native-ttf --enable-mbstring --enable-bcmath --enable-calendar --enable-dom --enable-xml --enable-fpm
make
make install
if [ $? -eq 0 ]
then
ln -s /usr/local/php/bin/php /usr/bin/php
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
sed -i 's/*.conf/*.conf.default/' /usr/local/php/etc/php-fpm.conf
cp /opt/update_apache/php-5.6.31/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
chkconfig --add php-fpm
chkconfig php-fpm on
cp /opt/update_apache/php-5.6.31/php.ini-production /etc/php.ini
sed -i 's#;date.timezone =#date.timezone = "Asia/Chongqing"#' /etc/php.ini
sed -i 's/max_execution_time = 30/max_execution_time = 300/' /etc/php.ini
sed -i 's/max_input_time = 60/max_input_time = 300/' /etc/php.ini
sed -i 's/post_max_size = 8M/post_max_size = 16M/' /etc/php.ini
sed -i '/always_populate_raw_post_data/s/;//g' /etc/php.ini
else
echo "php make failed"
exit 2
fi
}
#-------------------------------------------3-----------------------------------------------------------------------------------
function update_zabbix(){
#备份原zabbix相关内容
mv /etc/zabbix/ /tmp
mv /usr/local/zabbix /tmp
mv /var/www/html/zabbix /tmp
mv /etc/init.d/zabbix_server /tmp
mv /etc/init.d/zabbix_agentd /tmp
#安装高版本zabbix内容
cd $BASE_DIR
tar -xzvf zabbix-3.0.4.tar.gz
cd zabbix-3.0.4
./configure --with-mysql --with-mysqli --with-net-snmp --with-libcurl --enable-server --enable-agent --enable-proxy --prefix=/usr/local/zabbix3
make && make install
mkdir /etc/zabbix
mkdir -p /var/www/html/zabbix3
cp -r $BASE_DIR/zabbix-3.0.4/conf/* /etc/zabbix/
chown -R zabbix:zabbix /etc/zabbix
sed -i 's/\# DBPassword=.*$/DBPassword=skyfans8888/' /usr/local/zabbix3/etc/zabbix_server.conf
sed -i 's/\# DBPassword=.*$/DBPassword=skyfans8888/' /etc/zabbix/zabbix_server.conf
cp /usr/local/zabbix3/sbin/zabbix_server /etc/init.d/zabbix_server3
cp /usr/local/zabbix3/sbin/zabbix_agentd /etc/init.d/zabbix_agentd3
chmod +x /etc/init.d/zabbix_*
cp -rf $BASE_DIR/zabbix-3.0.4/frontends/php/* /var/www/html/zabbix3
chown -R zabbix:zabbix /var/www/html/zabbix3
cp $BASE_DIR/zabbix.conf.php /var/www/html/zabbix3/conf/zabbix.conf.php
chmod 777 /var/www/html/zabbix3/conf/zabbix.conf.php
cp $BASE_DIR/simkai.ttf /var/www/html/zabbix3/fonts/
sed -i 's/DejaVuSans/simkai/g' /var/www/html/zabbix3/include/defines.inc.php
sed -i '/$last = strtolower(substr($val, -1));/a$val = substr($val,0,-1);' /var/www/html/zabbix3/include/func.inc.php
}
#---------------------------------------------4---------------------------------------------------------------------------------
function update_zabbixconfig(){
sed -i 's#Listen 80#Listen 10080#g' /usr/local/apache2/conf/httpd.conf
sed -i '/AddType application\/x-gzip .gz .tgz/a\ AddType application/x-httpd-php .php\n AddType application/x-httpd-php-source .phps' /usr/local/apache2/conf/httpd.conf
sed -i 's#/usr/local/apache2/htdocs#/var/www/html#g' /usr/local/apache2/conf/httpd.conf
sed -i 's/index.html/& index.php/' /usr/local/apache2/conf/httpd.conf
sed -i '/old_passwords=1/d' /etc/my.cnf
sed -i 's#localhost#127.0.0.1#g' /var/www/html/zabbix/conf/zabbix.conf.php
}
#---------------------------------------------5---------------------------------------------------------------------------------
function update_mysqluser(){
mysql -uroot -pskyfans8888 <<EOF
use mysql;
CREATE TABLE servers ( Server_name char(64) NOT NULL, Host char(64) NOT NULL, Db char(64) NOT NULL, Username char(64) NOT NULL, Password char(64) NOT NULL, Port int(4) DEFAULT NULL, Socket char(64) DEFAULT NULL, Wrapper char(64) NOT NULL, Owner char(64) NOT NULL,PRIMARY KEY ( Server_name )) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='MySQL Foreign Servers table';
SET SESSION old_passwords=FALSE;
UPDATE mysql.user SET Password = PASSWORD('skyfans8888') WHERE user = 'zabbix';
flush privileges;
EOF
}
#------------------------------------------------6------------------------------------------------------------------------------
#------------------------------------------------------------------------------------------------------------------------------
function start_zabbix(){
chown -R mysql.mysql /data/
killall zabbix_server
killall zabbix_agentd
/etc/init.d/zabbix_server
/etc/init.d/zabbix_agentd
chkconfig httpd --add
chkconfig httpd on
service php-fpm start
echo "/etc/init.d/httpd start">>/etc/rc.local
echo "0 8 * * * root python /usr/local/zabbix/share/zabbix/alertscripts/zabbix_send_report.py">>/etc/crontab
echo "open $IPLOCAL:10080/zabbix"
}
#function agent(){
# cd $BASE_DIR/zabbix_piagent/zabbix_agent/conf
# sed -i 's#ServerActive=127.0.0.1#ServerActive='${IPLOCAL}'#g' zabbix_agentd.conf
# sed -i 's#Server=127.0.0.1#Server='${IPLOCAL}'#g' zabbix_agentd.conf
# cd $BASE_DIR/zabbix_piagent
# chmod +x pscp
# chmod +x pssh
# sh pi_agent.sh
#}
#-----------------------------------------------7-------------------------------------------------------------------------------
restartall_server(){
/etc/init.d/mysqld restart
/etc/init.d/httpd restart
/etc/init.d/php-fpm restart
# killall zabbix_server
# killall zabbix_agentd
# /etc/init.d/zabbix_server
# /etc/init.d/zabbix_agentd
}
#执行所有方法
update_httpd
update_php
update_zabbix
update_mysqluser
update_zabbixconfig
start_zabbix
restartall_server
#zabbix_java
#agent
if [ $? -eq 0 ]
then
echo "install success"
fi