Last active
October 8, 2019 17:26
-
-
Save zdev0x/576ea31ceb1dc15ea4b957630015a319 to your computer and use it in GitHub Desktop.
基于OneinStack的一键反代环境安装脚本
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-09-09 | |
| # | |
| # 说明:基于OneinStack的一键反代环境安装脚本 | |
| # | |
| # 支持系统:CentOS/RedHat 6+ Debian 8+ and Ubuntu 14+ | |
| # | |
| # 本脚本安装第三方模块: | |
| # 1. replace-filter-nginx-module (字符串替换,支持正则) | |
| # 2. ngx_brotli (谷歌公司开源的Brotli压缩算法) | |
| # 3. ngx_pagespeed (加速前端页面模块) | |
| # 4. ngx_cache_purge (URL清理缓存扩展) | |
| # 5. nginx-image-filter-watermark (图片压缩、图片裁剪、添加水印) | |
| # | |
| # 致谢:OneinStack https://oneinstack.com ,以及感谢以上开源模块的作者。 | |
| # | |
| export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin | |
| clear | |
| printf " | |
| ############################################# | |
| # 基于OneinStack的一键反代安装脚本 # | |
| # --------------------------------------- # | |
| # 1. replace-filter-nginx-module # | |
| # 2. ngx_brotli # | |
| # 3. ngx_pagespeed # | |
| # 4. ngx_cache_purge # | |
| # 5. nginx-image-filter-watermark # | |
| # --------------------------------------- # | |
| ############################################# | |
| " | |
| [ $(id -u) != "0" ] && { echo "Error: 请使用root用户执行该脚本"; exit 1; } | |
| WORKER_DIR=$(dirname "`readlink -f $0`") | |
| NGX_MODULE_DIR=${WORKER_DIR}/ngx_module | |
| # 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 sregex..." | |
| git clone https://github.com/openresty/sregex.git | |
| echo "Git Clone replace-filter-nginx-module..." | |
| git clone https://github.com/openresty/replace-filter-nginx-module.git | |
| echo "Git Clone ngx_brotli..." | |
| git clone https://github.com/google/ngx_brotli.git | |
| echo "Download Pagespeed..." | |
| src_url=https://github.com/pagespeed/ngx_pagespeed/archive/latest-beta.tar.gz && download_src | |
| echo "Download Pagespeed-psol..." | |
| src_url=https://dl.google.com/dl/page-speed/psol/1.13.35.2-x64.tar.gz && download_src | |
| echo "Download ngx_cache_purge..." | |
| src_url=http://labs.frickle.com/files/ngx_cache_purge-2.3.tar.gz && download_src | |
| echo "Git Clone nginx-image-filter-watermark" | |
| git clone https://github.com/intaro/nginx-image-filter-watermark | |
| } | |
| # 安装 | |
| pre_install() { | |
| pushd ${WORKER_DIR} > /dev/null | |
| echo "解压缩:lnmp-full.tar.gz" | |
| tar zxf lnmp-full.tar.gz | |
| echo "安装:sregex正则库" | |
| pushd ${NGX_MODULE_DIR}/sregex > /dev/null | |
| make && make install | |
| pushd ${NGX_MODULE_DIR} > /dev/null | |
| echo "解压缩:Pagespeed - latest-beta.tar.gz" | |
| tar zxf latest-beta.tar.gz | |
| tar zxf 1.13.35.2-x64.tar.gz -C ./incubator-pagespeed-ngx-latest-beta | |
| 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 --with-http_image_filter_module --add-module=${NGX_MODULE_DIR}/ngx_cache_purge-2.3 --add-module=${NGX_MODULE_DIR}/incubator-pagespeed-ngx-latest-beta --add-module=${NGX_MODULE_DIR}/replace-filter-nginx-module --add-module=${NGX_MODULE_DIR}/ngx_brotli'@g" ${WORKER_DIR}/lnmp/options.conf | |
| echo "安装nginx图片处理模块" | |
| \cp -rf ${WORKER_DIR}/lnmp/include/openresty.sh ${WORKER_DIR}/lnmp/include/openresty.sh.bak | |
| patchCommand="\ \ cp -rf ${NGX_MODULE_DIR}/nginx-image-filter-watermark/ngx_http_image_filter_module.c ${WORKER_DIR}/lnmp/src/openresty-\${openresty_ver}/bundle/nginx-1.15.8/src/http/ngx_http_image_filter_module.c" | |
| sed -i "20 a${patchCommand}" ${WORKER_DIR}/lnmp/include/openresty.sh | |
| } | |
| # 安装openrestry | |
| install_openresty() { | |
| pushd ${WORKER_DIR}/lnmp > /dev/null | |
| echo "安装openrestry" | |
| ./install.sh --nginx_option 3 | |
| } | |
| # 下载 | |
| 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