Created
December 7, 2019 12:33
-
-
Save zdev0x/1d43984f61a41816265e10ef16fa1184 to your computer and use it in GitHub Desktop.
图片反代节点环境配置
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # | |
| # 作者: Jsser <jsser AT qq.com> | |
| # | |
| # 日期:2019-12-01 | |
| # | |
| # 说明:基于OneinStack的一键反代环境安装脚本 | |
| # | |
| # 支持系统:CentOS/RedHat 6+ Debian 8+ and Ubuntu 14+ | |
| # | |
| # 本脚本安装第三方模块: | |
| # 1. ngx_brotli (谷歌公司开源的Brotli压缩算法) | |
| # 2. ngx_cache_purge (URL清理缓存扩展) | |
| # 致谢:OneinStack https://oneinstack.com ,以及感谢以上开源模块的作者。 | |
| # | |
| export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin | |
| clear | |
| printf " | |
| ############################################# | |
| # 基于OneinStack的一键图片反代安装脚本 # | |
| # --------------------------------------- # | |
| # 1. ngx_brotli # | |
| # 2. ngx_cache_purge # | |
| # --------------------------------------- # | |
| ############################################# | |
| " | |
| [ $(id -u) != "0" ] && { echo "Error: 请使用root用户执行该脚本"; exit 1; } | |
| WORKER_DIR=$(dirname "`readlink -f $0`") | |
| NGX_MODULE_DIR=${WORKER_DIR}/ngx_module | |
| # ssh端口号 | |
| SSH_PORT=22 | |
| # COLORS | |
| RED='\033[0;31m' | |
| GREEN='\033[0;32m' | |
| YELLOW='\033[0;33m' | |
| SKYBLUE='\033[0;36m' | |
| PLAIN='\033[0m' | |
| # 下载资源 | |
| download_package() { | |
| pushd ${WORKER_DIR} > /dev/null | |
| ## DownLoad Oneinstack | |
| echo "Download lnmp-full.tar.gz..." | |
| src_url=http://mirrors.linuxeye.com/lnmp-full.tar.gz && download_src | |
| ## Download ngx_module | |
| pushd ${NGX_MODULE_DIR} > /dev/null | |
| echo "Git Clone ngx_brotli..." | |
| git clone https://github.com/google/ngx_brotli.git | |
| echo "Download ngx_cache_purge..." | |
| src_url=http://labs.frickle.com/files/ngx_cache_purge-2.3.tar.gz && download_src | |
| } | |
| # 安装 | |
| pre_install() { | |
| pushd ${WORKER_DIR} > /dev/null | |
| echo "解压缩:lnmp-full.tar.gz" | |
| tar zxf lnmp-full.tar.gz | |
| pushd ${NGX_MODULE_DIR} > /dev/null | |
| echo '解压缩:ngx_cache_purge-2.3.tar.gz' | |
| tar zxf ngx_cache_purge-2.3.tar.gz | |
| echo "初始化:ngx_brotli" | |
| pushd ${NGX_MODULE_DIR}/ngx_brotli > /dev/null | |
| git submodule update --init | |
| echo "更新nginx_modules_options配置项"; | |
| sed -i "s@nginx_modules_options=''@nginx_modules_options='--with-http_geoip_module --add-module=${NGX_MODULE_DIR}/ngx_cache_purge-2.3 --add-module=${NGX_MODULE_DIR}/ngx_brotli'@g" ${WORKER_DIR}/lnmp/options.conf | |
| } | |
| # 安装openrestry | |
| install_openresty() { | |
| pushd ${WORKER_DIR}/lnmp > /dev/null | |
| echo "安装openrestry" | |
| ./install.sh --nginx_option 3 --iptables --ssh_port $SSH_PORT --reboot | |
| } | |
| # 下载 | |
| download_src() { | |
| [ -s "${src_url##*/}" ] && echo "[${CMSG}${src_url##*/}${CEND}] found" || { wget -4 --tries=6 -c --no-check-certificate ${src_url}; sleep 1; } | |
| if [ ! -e "${src_url##*/}" ]; then | |
| echo "${CFAILURE}Auto download failed! You can manually download ${src_url} into the oneinstack/src directory.${CEND}" | |
| kill -9 $$ | |
| fi | |
| } | |
| # 检测目录 | |
| check_dir() { | |
| if [ ! -d $NGX_MODULE_DIR ]; then | |
| mkdir -p ${NGX_MODULE_DIR} | |
| fi | |
| } | |
| install_check() { | |
| if check_os packageManager yum || check_os packageManager apt; then | |
| return 0 | |
| else | |
| return 1 | |
| fi | |
| } | |
| # 预处理 | |
| pre_init() { | |
| if [ -e "/usr/bin/yum" ]; then | |
| PM=yum | |
| command -v lsb_release >/dev/null 2>&1 || { [ -e "/etc/euleros-release" ] && yum -y install euleros-lsb || yum -y install redhat-lsb-core; clear; } | |
| fi | |
| if [ -e "/usr/bin/apt-get" ]; then | |
| PM=apt-get | |
| command -v lsb_release >/dev/null 2>&1 || { apt-get -y update; apt-get -y install lsb-release; clear; } | |
| fi | |
| command -v lsb_release >/dev/null 2>&1 || { echo "${PM} source failed! "; kill -9 $$; } | |
| [ "${PM}" == 'apt-get' ] && apt-get -y update | |
| [ "${PM}" == 'yum' ] && yum clean all | |
| ${PM} -y install wget gcc curl python git bison geoip-devel libuuid-devel | |
| } | |
| init() { | |
| pre_init | |
| check_dir | |
| download_package | |
| pre_install | |
| read -p "$(echo -e ${SKYBLUE}扩展包已经下载完成,是否直接安装openresty${PLAIN} [y/n]?)" -n 1 -r | |
| if [[ $REPLY =~ ^[Yy]$ ]];then | |
| install_openresty | |
| else | |
| printf "\n" | |
| exit 1 | |
| fi | |
| } | |
| init |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment