我是靠谱客的博主 优雅小伙,最近开发中收集的这篇文章主要介绍一键安装nginx,keepalived,python脚本,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

#!/bin/bash

########################
#                      #
#  date=2018-12-19     #
#  version=1.0	       #
#  author=changzhenxi  #
#		               #
########################

echo "######################################################
#             VERSION=1.0                            #
#	      AUTHOR=CHANGZHENXI		     #
#	      MAIL=498390272@qq.com                #
######################################################
# welcome to use Install TOOLS,please input number!  #
#          1、nginx install!                         # 
#          2、keepalived install! 	             #
#          3、python install!	 		     #
#          0、exit this tools!                       #
######################################################"
read choice

INSTALL_DIR="/opt/log"


nginx_install () {
if [ ! -d $INSTALL_DIR ]; then
    mkdir -p $INSTALL_DIR
fi
	chmod -R 750 $INSTALL_DIR
if [ ! -f $INSTALL_DIR/install.log ]; then
    touch $INSTALL_DIR/install.log
    chmod 750 $INSTALL_DIR/install.log
fi

echo `date "+%C%y-%m-%d %H:%M:%S"` "start install nginx" |tee -a $INSTALL_DIR/install.log

echo -e "33[31m =====================开始获取nginx安装包!==================== 33[0m"
wget http://nginx.org/download/nginx-1.10.0.tar.gz
echo -e "33[31m =====================nginx安装包获取完成!==================== 33[0m"
echo -e "33[31m =====================请输入nginx解压目录!==================== 33[0m"
read dir
   	if [ ! -d $dir ]; then
		echo "$dir 不存在,脚本将为您新建!"
            mkdir -p $dir
		mv nginx-1.10.0.tar.gz $dir/nginx.tar.gz
            cd $dir
            echo -e "33[31m =====================开始解压!==================== 33[0m"
            tar -zxvf nginx.tar.gz
                echo -e "33[31m =====================解压完成!==================== 33[0m"
                echo -e "33[31m =====================开始安装依赖包!==================== 33[0m"
            yum -y install gcc pcre pcre-devel zlib zlib-devel openssl openssl-devel
                echo -e "33[31m =====================恭喜,依赖包安装完成!==================== 33[0m"
                echo -e "33[31m =====================开始编译安装nginx,此过程预计需要5分钟!==================== 33[0m" 
    else
		mv nginx-1.10.0.tar.gz $dir/nginx.tar.gz
   	        cd $dir
    	 	echo -e "33[31m =====================开始解压!==================== 33[0m"
  		tar -zxvf nginx.tar.gz
  			echo -e "33[31m =====================解压完成!==================== 33[0m"
  			echo -e "33[31m =====================开始安装依赖包!==================== 33[0m"
  		yum -y install gcc pcre pcre-devel zlib zlib-devel openssl openssl-devel
  			echo -e "33[31m =====================恭喜,依赖包安装完成!==================== 33[0m"
  			echo -e "33[31m =====================开始编译安装nginx,此过程预计需要5分钟!==================== 33[0m" 
	fi 
}

keepalived_install () {
echo -e "33[31m =====================开始获取keepalived安装包,请输入下载安装包路径==================== 33[0m"
read keepaliveddir
	if [ ! -d $keepaliveddir ]; then
		echo "$keepaliveddir 不存在,脚本将为您新建!"
			mkdir -p $keepaliveddir
		echo -e "33[31m =====================目录创建完成!==================== 33[0m"
			cd $keepaliveddir
		wget http://www.keepalived.org/software/keepalived-1.2.24.tar.gz
	else 
		cd $keepaliveddir
			wget http://www.keepalived.org/software/keepalived-1.2.24.tar.gz
	fi
		echo -e "33[31m =====================开始解压!==================== 33[0m"
		tar -zxvf keepalived-1.2.24.tar.gz
			echo -e "33[31m =====================解压完成!==================== 33[0m"
			echo -e "33[31m =====================开始编译安装nginx,此过程预计需要5分钟!==================== 33[0m"
		./configure --prefix=/usr/local/keepalived
	make && make install
}

python_install () {
echo -e "33[31m =====================开始获取python安装包,请输入下载安装包路径==================== 33[0m"
read pythondir
	if [ ! -d $pythondir ]; then
		echo "$pythondir 不存在,新建 $pythondir 请输入1,重新输入请输入2!"
			read dirchoice
				case $dirchoice in
					1)
						echo ""
       						mkdir -p $pythondir
						echo -e "33[31m =====================目录创建完成!==================== 33[0m"
 						;;
					2)
						echo -e "33[31m 请输入下载安装包路径 33[0m"
       						read pythondir
						;;
					*)
       						echo "inviald choice!"
						;;	
					esac
                cd $pythondir
		wget https://www.python.org/ftp/python/3.7.1/Python-3.7.1.tgz
	else
	cd $pythondir
		wget https://www.python.org/ftp/python/3.7.1/Python-3.7.1.tgz
	fi
	sleep 2
echo -e "33[31m =====================开始安装依赖包!==================== 33[0m"
yum -y install zlib zlib-devel bzip2 bzip2-devel ncurses ncurses-devel readline readline-devel openssl openssl-devel openssl-static xz lzma xz-devel sqlite sqlite-devel gdbm gdbm-devel tk tk-devel libffi libffi-devel
	echo -e "33[31m =====================开始解压安装包!==================== 33[0m"
        tar -zxvf Python-3.7.1.tgz
		echo -e "33[31m =====================解压完成!==================== 33[0m"
		echo -e "33[31m =====================2秒后开始编译安装!==================== 33[0m"
	sleep 2
	cd $pythondir/Python-3.7.1/
		./configure --prefix=/usr/python --enable-shared CFLAGS=-fPIC
		make && make install
		echo -e "33[31m =====================2秒后开始配置环境变量!==================== 33[0m"
	sleep 2
	ln -s /usr/python/bin/python3.7 /usr/bin/python3
	ln -s /usr/python/bin/pip3.7 /usr/bin/python3
	cd /etc/ld.so.conf.d
		echo "/usr/python/lib/" > python3.conf
	cd /root
	ldconfig
   		echo -e "33[31m ====================python安装完成!==================== 33[0m" 
}	


case $choice in 
1)
  	nginx_install
	;;
2)
	keepalived_install
	;;
3)
	python_install
	;;
0)
	exit
	;;
*) 
	echo "inviald choice!"
sleep 3
exit
;;
esac

最后

以上就是优雅小伙为你收集整理的一键安装nginx,keepalived,python脚本的全部内容,希望文章能够帮你解决一键安装nginx,keepalived,python脚本所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(44)

评论列表共有 0 条评论

立即
投稿
返回
顶部