Browse Source

编译脚本不放在安装脚本里,放在 docs/compile.md 文档

zjcqoo 6 years ago
parent
commit
999edf253e
3 changed files with 93 additions and 101 deletions
  1. 1 1
      README.md
  2. 81 13
      docs/compile.md
  3. 11 87
      i.sh

+ 1 - 1
README.md

@@ -22,7 +22,7 @@ https://zjcqoo.github.io/-----https://www.google.com
 curl -O https://raw.githubusercontent.com/EtherDream/jsproxy/master/i.sh && bash i.sh
 ```
 
-如果安装失败,尝试[源码编译安装](docs/compile.md)。
+如果安装失败,尝试[手动安装](docs/compile.md)。
 
 
 # 测试

+ 81 - 13
docs/compile.md

@@ -1,29 +1,97 @@
-# 简介
+# 手动安装
 
-默认的安装方式,是直接下载编译后的 nginx 程序。目前只提供 Linux x64 系统的文件,其他系统暂不支持,需要从源码编译。
+## 创建用户
 
-此外,对于没有 root 权限的系统,也需通过源码编译,从而改变 nginx 的安装位置。(nginx 程序路径是在编译时通过 `--prefix` 参数指定的,安装后移动程序位置会导致某些链接库无法加载。如果有好的解决方案多指教~)
+新建一个名为 `jsproxy` 用户(`nobody` 组),并切换:
 
+```bash
+groupadd nobody
+useradd jsproxy -g nobody --create-home
+
+su - jsproxy
+```
+
+非 Linux 系统,或者无 root 权限的设备,可忽略。
+
+
+## 安装 nginx
+
+下载、编译、安装 nginx。本项目使用 [OpenResty](https://openresty.org/en/)。
+
+```bash
+cd $(mktemp -d)
+
+curl -O https://www.openssl.org/source/openssl-1.1.1b.tar.gz
+tar zxf openssl-*
+
+curl -O https://ftp.pcre.org/pub/pcre/pcre-8.43.tar.gz
+tar zxf pcre-*
+
+curl -O https://zlib.net/zlib-1.2.11.tar.gz
+tar zxf zlib-*
+
+curl -O https://openresty.org/download/openresty-1.15.8.1.tar.gz
+tar zxf openresty-*
+cd openresty-*
+
+export PATH=$PATH:/sbin
+
+./configure \
+  --with-openssl=../openssl-1.1.1b \
+  --with-pcre=../pcre-8.43 \
+  --with-zlib=../zlib-1.2.11 \
+  --with-http_v2_module \
+  --with-http_ssl_module \
+  --with-pcre-jit \
+  --prefix=$HOME/openresty
+
+make
+make install
+```
+
+其中 `configure` 的参数 `--prefix` 指定 nginx 安装路径,这里为方便设为用户主目录。
+
+> 注意编译后的 nginx 程序不能改变位置,否则会启动失败
+
+测试能否执行:
 
-# 依赖
+```bash
+$HOME/openresty/nginx/sbin/nginx -h
+```
 
-需要安装 make、gcc 等,参考 nginx 的编译。
 
-无需安装 pcre、zlib、openssl 开发库,安装脚本会自动下载源码。
+## 安装代理程序
 
+下载本项目。其本质就是一堆 nginx 配置:
+
+```bash
+git clone --depth=1 https://github.com/EtherDream/jsproxy.git server
+```
 
-# 脚本
+开启代理服务:
 
 ```bash
-curl -O https://raw.githubusercontent.com/EtherDream/jsproxy/master/i.sh
-bash i.sh compile
+cd server
+./run.sh
 ```
 
-nginx 最终安装在 `$HOME/openresty` 目录下。代理服务安装在当前 `server` 目录下。
+更新使用 git 即可。
+
+
+## 编译问题
+
+编译前需要安装 make、gcc 等工具,具体可参考 nginx 编译。
+
+无需安装 pcre-devel、openssl-devel、zlib-devel 依赖,已使用源码编译。
+
+
+## 用户问题
+
+为什么要创建一个 `jsproxy` 用户运行该服务?
 
+因为该服务无需 root,所以更低的权限可以减少风险。另外在防 SSRF 脚本 `setup-ipset.sh` 中,是通过 iptalbes 的 `uid-owner` 策略阻止 `jsprxoy` 这个特定用户访问内网的。
 
-# 支持
 
-目前测试过的系统:
+## 支持系统
 
-* OSX
+目前测试了 OSX 系统,其他还在测试中。。。

+ 11 - 87
i.sh

@@ -3,9 +3,6 @@
 CDN=https://cdn.jsdelivr.net/gh/etherdream/jsproxy-bin@master
 
 JSPROXY_VER=0.0.9
-PCRE_VER=8.43
-ZLIB_VER=1.2.11
-OPENSSL_VER=1.1.1b
 OPENRESTY_VER=1.15.8.1
 
 SUPPORTED_OS="Linux-x86_64"
@@ -35,7 +32,12 @@ err() {
   output $COLOR_RED $1
 }
 
-check_nginx() {
+install() {
+  log "下载 nginx 程序 ..."
+  curl -O $CDN/$OS/openresty-$OPENRESTY_VER.tar.gz
+  tar zxf openresty-$OPENRESTY_VER.tar.gz
+  rm -f openresty-$OPENRESTY_VER.tar.gz
+
   local ngx_exe="$NGX_DIR/nginx/sbin/nginx"
   local ngx_ver=$($ngx_exe -v 2>&1)
 
@@ -45,9 +47,7 @@ check_nginx() {
   fi
   log "$ngx_ver"
   log "nginx path: $NGX_DIR"
-}
 
-install_jsproxy() {
   log "下载代理服务 ..."
   curl -s -O $CDN/server-$JSPROXY_VER.tar.gz
 
@@ -72,75 +72,6 @@ install_jsproxy() {
   log "服务已开启。后续维护参考 https://github.com/EtherDream/jsproxy"
 }
 
-compile() {
-  local tmp_dir="$PWD/__tmp__"
-
-  mkdir -p $tmp_dir
-  cd $tmp_dir
-
-  log "下载 pcre 源码 ..."
-  curl -O https://ftp.pcre.org/pub/pcre/pcre-$PCRE_VER.tar.gz
-  tar zxf pcre-$PCRE_VER.tar.gz
-
-  log "下载 zlib 源码 ..."
-  curl -O https://zlib.net/zlib-$ZLIB_VER.tar.gz
-  tar zxf zlib-$ZLIB_VER.tar.gz
-
-  log "下载 openssl 源码 ..."
-  curl -O https://www.openssl.org/source/openssl-$OPENSSL_VER.tar.gz
-  tar zxf openssl-$OPENSSL_VER.tar.gz
-
-  log "下载 nginx 源码 ..."
-  curl -O https://openresty.org/download/openresty-$OPENRESTY_VER.tar.gz
-  tar zxf openresty-$OPENRESTY_VER.tar.gz
-
-  cd openresty-$OPENRESTY_VER
-
-  export PATH=$PATH:/sbin
-
-  log "配置中 ..."
-  ./configure \
-    --with-openssl=../openssl-$OPENSSL_VER \
-    --with-pcre=../pcre-$PCRE_VER \
-    --with-zlib=../zlib-$ZLIB_VER \
-    --with-http_v2_module \
-    --with-http_ssl_module \
-    --with-pcre-jit \
-    --prefix=$NGX_DIR
-
-  log "编译中 ..."
-  make
-  make install
-
-  log "编译完成"
-  rm -rf $tmp_dir
-
-  check_nginx
-  install_jsproxy
-}
-
-install() {
-  log "下载 nginx 程序 ..."
-  curl -O $CDN/$OS/openresty-$OPENRESTY_VER.tar.gz
-  tar zxf openresty-$OPENRESTY_VER.tar.gz
-  rm -f openresty-$OPENRESTY_VER.tar.gz
-
-  check_nginx
-  install_jsproxy
-}
-
-update() {
-  install_jsproxy
-}
-
-pack() {
-  log "压缩 openresty ..."
-  GZIP=-9
-  tar cvzf openresty.tar.gz openresty
-  log "done"
-  ls -la
-}
-
 main() {
   if [[ "$SUPPORTED_OS" != *"$OS"* ]]; then
     err "当前系统 $OS 不支持自动安装。尝试编译安装"
@@ -170,15 +101,8 @@ main() {
 }
 
 
-case "$1" in
-"install") install
-  exit;;
-"compile") compile
-  exit;;
-"update") update
-  exit;;
-"pack") pack
-  exit;;
-*) main
-  exit;;
-esac
+if [[ "$1" == "install" ]]; then
+  install
+else
+  main
+fi