Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/hectorqin/reader
Browse files Browse the repository at this point in the history
  • Loading branch information
hectorqin committed Jul 6, 2023
2 parents bc8315a + 66d17fb commit 38ff966
Show file tree
Hide file tree
Showing 4 changed files with 297 additions and 13 deletions.
51 changes: 42 additions & 9 deletions doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
- [服务器版](#服务器版)
- [Docker版](#docker版)
- [Docker-Compose版(推荐)](#docker-compose版推荐)
- [脚本部署(甲骨文非Ubuntu可能不支持)](#通过脚本一键部署)
- [Nginx反向代理](#nginx反向代理)
- [开发编译](#开发编译)
- [编译脚本](#编译脚本)
Expand Down Expand Up @@ -278,18 +279,22 @@ reader添加环境变量:-e "READER_APP_REMOTEWEBVIEWAPI=http://localhost:8050
### Docker-Compose版(推荐)
```bash
#安装docker-compose
```shell
#腾讯云,阿里云,华为云,甲骨文等服务器提供商需在控制台面板手动关闭防火墙并放行端口
#安装docker 及 docker-compose
#Debian/Ubuntu
apt install docker-compose -y
#CentOS
curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
docker-compose --version
curl -fsSL https://get.docker.com | bash -s docker #国外服务器
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun #国内服务器
# 下载项目里的 docker-compose.yaml
wget https://raw.githubusercontent.com/hectorqin/reader/master/docker-compose.yaml
wget https://ghproxy.com/https://raw.githubusercontent.com/hectorqin/reader/master/docker-compose.yaml
# 根据 docker-compose.yaml 里面的注释编辑所需配置
vim docker-compose.yaml
# 保存
esc
:wq
# 启动 docker-compose
docker-compose up -d
Expand All @@ -299,19 +304,47 @@ docker-compose stop
# 查看实时日志
docker logs -f reader
# 自行导入远程书源(打开链接后复制网址导入即可)
https://legado.pages.dev
# 手动更新
docker-compose pull && docker-compose up -d
```
## Nginx反向代理
### 通过脚本一键部署
```shell
# 此脚本对甲骨文非Ubuntu系统,CentOS9可能不兼容。建议网上手动搜索
#curl
bash <(curl -L -s https://ghproxy.com/https://raw.githubusercontent.com/hectorqin/reader/master/reader.sh)
#wget
bash <(wget -qO- --no-check-certificate https://ghproxy.com/https://raw.githubusercontent.com/hectorqin/reader/master/reader.sh)
```
## Nginx反向代理(如果有域名可以考虑80端口复用)
```shell
# 宝塔等各种面板不适用下列教程
# Debian/Ubuntu
apt install nginx -y
# CentOS
yum install nginx -y
vim /etc/nginx/conf.d/reader.conf
将下面代码复制进reader.conf后,修改域名输入
esc
:wq
保持即可
```
```nginx
# 此文件放入 conf.d目录下,一般可用 touch /etc/nginx/conf.d/reader.conf 创建
server {
listen 80;
server_name 域名;
#开启ssl解除注释
#不使用宝塔获取证书脚本 https://github.com/Misaka-blog/acme-1key
# SSL证书获取
# https://github.com/acmesh-official/acme.sh/wiki/%E8%AF%B4%E6%98%8E
#listen 443 ssl;
#ssl_certificate 证书.cer;
#ssl_certificate_key 证书.key;
Expand Down
7 changes: 3 additions & 4 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
version: '3.1'
services:
# reader 在线阅读
# 第三方在线演示(服务器位于日本):[https://reader.nxnow.top](https://reader.nxnow.top) 测试账号/密码分别为guest/guest123,也可自行创建账号添加书源,不定期删除长期未登录账号
# 源仓库书源 : yckceo.com/yuedu/shuyuan/index.html
# 阅读官方书源 : https://www.legado.top/blog/book-source
# 喵公子书源 : http://shuyuan.miaogongzi.net/shuyuan/1623355431.json
# 公开服务器(服务器位于日本):[https://reader.nxnow.top](https://reader.nxnow.top) 测试账号/密码分别为guest/guest123,也可自行创建账号添加书源,不定期删除长期未登录账号(2周)
# 阅读官方书源 : [https://legado.pages.dev](https://legado.pages.dev) 或者 [http://legado.git.llc](https://legado.pages.dev) 点击打开连接,添加远程书源即可
# 公众号汇总 : [https://mp.weixin.qq.com/s/5t8nfSnRfHjJNAvT76fA_A](https://mp.weixin.qq.com/s/5t8nfSnRfHjJNAvT76fA_A)
# 手动更新方式 : docker-compose pull && docker-compose up -d
reader:
image: hectorqin/reader
Expand Down
50 changes: 50 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
version: '3.1'
services:
# reader 在线阅读
# 公开服务器(服务器位于日本):[https://reader.nxnow.top](https://reader.nxnow.top) 测试账号/密码分别为guest/guest123,也可自行创建账号添加书源,不定期删除长期未登录账号(2周)
# 阅读官方书源 : [https://legado.pages.dev](https://legado.pages.dev) 或者 [http://legado.git.llc](https://legado.pages.dev) 点击打开连接,添加远程书源即可
# 公众号汇总 : [https://mp.weixin.qq.com/s/5t8nfSnRfHjJNAvT76fA_A](https://mp.weixin.qq.com/s/5t8nfSnRfHjJNAvT76fA_A)
# 手动更新方式 : 在此文件所在的目录下执行 docker-compose pull && docker-compose up -d
reader:
#image: hectorqin/reader # 普通镜像
image: hectorqin/reader:openj9-latest # Openj9镜像,arm64架构或小内存机器优先使用
container_name: reader #容器名 可自行修改
restart: always
ports:
- 4396:8080 #4396端口映射可自行修改,8080请勿修改
volumes:
- /home/reader/logs:/logs #log映射目录 /home/reader/logs 映射目录可自行修改
- /home/reader/storage:/storage #数据映射目录 /home/reader/storage 映射目录可自行修改
environment:
- SPRING_PROFILES_ACTIVE=prod
#- READER_APP_USERLIMIT=50 #用户上限,默认且最大值为50
- READER_APP_USERBOOKLIMIT=200 #用户书籍上限,默认200
- READER_APP_CACHECHAPTERCONTENT=true #开启缓存章节内容
- READER_APP_REMOTEWEBVIEWAPI=http://readerwebview:8050 #启用webview(若下方readerwebview容器不开启需注释此行
# ↓多用户模式配置↓
- READER_APP_SECURE=true #开启登录鉴权,开启后将支持多用户模式
- READER_APP_SECUREKEY=adminpwd #管理员密码 建议修改
- READER_APP_INVITECODE=registercode #注册邀请码 建议修改,如不需要可注释或删除
# 如需支持webview书源,打开(占用较大,不需要可加 # 注释)
readerwebview:
image: hectorqin/remote-webview
container_name: readerwebview
restart: always
environment:
- TZ=Asia/Shanghai
# 自动更新docker镜像
watchtower:
image: containrrr/watchtower
container_name: watchtower
restart: always
environment:
- TZ=Asia/Shanghai
volumes:
- /var/run/docker.sock:/var/run/docker.sock
command: reader readerwebview watchtower --cleanup --schedule "0 0 4 * * *"
# 仅更新reader与watchtower容器,如需其他自行添加 '容器名' ,如:reader watchtower nginx
# --cleanup 更新后清理旧版本镜像
# --schedule 自动检测更新 crontab定时(限定6位crontab) 此处代表凌晨4点整
volumes:
reader:
readerwebview:
202 changes: 202 additions & 0 deletions reader.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
#!/bin/bash

red='\033[0;31m'
green="\033[32m"
yellow='\033[0;33m'
plain='\033[0m'

file_dir=""
remotePort=""
isMultiUser=""
adminPassword=""
registerCode=""
strTrue="true"
dockerImages=""

# CheckRoot
if [[ $EUID -ne 0 ]]; then
echo "请使用root用户登录!" 1>&2
exit 1
fi

# CheckSystem
if [[ -f /etc/redhat-release ]]; then
release="centos"
elif cat /etc/issue | grep -q -E -i "debian"; then
release="debian"
elif cat /etc/issue | grep -q -E -i "ubuntu"; then
release="ubuntu"
elif cat /etc/issue | grep -q -E -i "centos|red hat|redhat"; then
release="centos"
elif cat /proc/version | grep -q -E -i "debian"; then
release="debian"
elif cat /proc/version | grep -q -E -i "ubuntu"; then
release="ubuntu"
elif cat /proc/version | grep -q -E -i "centos|red hat|redhat"; then
release="centos"
fi
bit=$(uname -m)
if test "$bit" != "x86_64"; then
bit="arm64"
else bit="amd64"
fi

os_version=""

# os version
if [[ -f /etc/os-release ]]; then
os_version=$(awk -F'[= ."]' '/VERSION_ID/{print $3}' /etc/os-release)
fi
if [[ -z "$os_version" && -f /etc/lsb-release ]]; then
os_version=$(awk -F'[= ."]+' '/DISTRIB_RELEASE/{print $2}' /etc/lsb-release)
fi

if [[ x"${release}" == x"centos" ]]; then
if [[ ${os_version} -le 6 ]]; then
echo -e "${red}请使用 CentOS 7 或更高版本的系统!${plain}\n" && exit 1
fi
elif [[ x"${release}" == x"ubuntu" ]]; then
if [[ ${os_version} -lt 16 ]]; then
echo -e "${red}请使用 Ubuntu 16 或更高版本的系统!${plain}\n" && exit 1
fi
elif [[ x"${release}" == x"debian" ]]; then
if [[ ${os_version} -lt 9 ]]; then
echo -e "${red}请使用 Debian 9 或更高版本的系统!${plain}\n" && exit 1
fi
fi

install_dockercompose() {
if [[ x"${release}" == x"centos" ]]; then
yum install wget curl -y
echo -e "${green} 正在移除CentOS遗留无效Docker文件 ${plain}"
yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-engine -y
echo -e "${green} 正在安装Docker ${plain}"
yum install yum-utils device-mapper-persistent-data lvm2 -y
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum install docker-ce docker-ce-cli containerd.io docker-compose-plugin -y
echo -e "${green} 正在启动Docker ${plain}"
systemctl start docker
systemctl restart docker
systemctl enable docker
echo -e "${green} 正在安装docker-compose ${plain}"
curl -L "https://ghproxy.com/https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose && chmod +x /usr/local/bin/docker-compose
else
echo -e "${green} 正在安装docker-compose ${plain}"
apt update && apt install wget curl docker-compose -y
fi
}

install_reader() {
mkdir -p ${orgin_file_dir}/storage/data/default
cd ${orgin_file_dir}
rm docker-compose*
wget https://ghproxy.com/https://raw.githubusercontent.com/hectorqin/reader/master/docker-compose.yml
echo -e "${green} 正在配置默认书源 ${plain}"
wget https://legado.pages.dev/sy-yc.json -O storage/data/default/bookSource.json
echo -e "${green} 正在配置docker变量 ${plain}"
sed -i "s/\/home\/reader/${file_dir}/" docker-compose.yml
sed -i "s/4396/${remotePort}/" docker-compose.yml
sed -i "s/openj9-latest/${dockerImages}/" docker-compose.yml
# 多用户
sed -i "s/READER_APP_SECURE\=true/READER_APP_SECURE\=${isMultiUser}/" docker-compose.yml
sed -i "s/adminpwd/${adminPassword}/" docker-compose.yml
sed -i "s/registercode/${registerCode}/" docker-compose.yml
echo -e "${green} 准备启动 ${plain}"
# 远程webview
docker-compose up -d
}

getRemotePort () {
echo "请输入部署端口,例如 4396"
read -p "不填默认为4396: " remotePort
if [[ -z "$remotePort" ]];then
remotePort="4396"
fi
if [ "$remotePort" -gt 0 ] 2>/dev/null;then
if [[ $remotePort -lt 0 || $remotePort -gt 65535 ]];then
echo -e "${red} 端口号不正确,请输入0-65535${plain}"
getRemotePort
exit 0
fi
else
echo -e "${red} 端口号不正确,请输入0-65535${plain}"
getRemotePort
exit 0
fi
}


getfileDir () {
echo -e "${green} 请输入数据存放目录,例如 /home/reader : ${plain}"
read -p "不填默认为/home/reader : " file_dir
if [[ -z "$file_dir" ]];then
file_dir="/home/reader"
fi
orgin_file_dir=$file_dir
file_dir=${file_dir//\//\\\/}
}

getMultiUser () {
echo -e "${green} 是否需要开启多用户 : ${plain}"
read -p "填0不开启,不填开启 : " isMultiUser
if [[ -z "$isMultiUser" ]];then
isMultiUser="true"
else
isMultiUser="false"
fi
}

getPwdOrCode () {
echo -e "${green} 请输入管理密码,用于加载用户空间 : ${plain}"
read -p "建议修改此参数,默认为adminpwd : " adminPassword
if [[ -z "$adminPassword" ]];then
adminPassword="adminpwd"
fi
echo -e "${green} 请输入邀请码,用于注册使用 : ${plain}"
read -p "不填默认为空 : " registerCode
if [[ -z "$registerCode" ]];then
registerCode=""
fi
}

getDockerImages () {
echo -e "${green} 请输入需要的镜像 arm或者小内存(1G)机器建议openj9,其余建议基础镜像 : ${plain}"
read -p "不输入为基础镜像,输入其他值为openj9 : " dockerImages
if [[ -z "$dockerImages" ]];then
dockerImages="latest"
else
dockerImages="openj9-latest"
fi
}

Server_IP=''
Public_IP=''
getIpaddr () {
Server_IP=$(hostname -I | awk -F " " '{printf $1}')
Public_IP=$(curl http://pv.sohu.com/cityjson 2>> /dev/null | awk -F '"' '{print $4}')
}

echo -e "${green}准备部署reader${plain}"
echo -e "${green}甲骨文官方系统可能并不适用此脚本,本脚本仅测试CentOS7,8,Ubuntu20+,Debian10+${plain}"
install_dockercompose
getfileDir
getRemotePort
getMultiUser
if [ $isMultiUser == "true" ]; then
getPwdOrCode
fi
getDockerImages
install_reader
getIpaddr

echo -e "${green}初步部署完成,已配置默认书源,国内服务器等有控制台面板的服务器厂商请手动在控制台打开reader所需的端口${remotePort}${plain}"
if [ $Server_IP == $Public_IP ];then
echo -e "${green}网址:${plain} http://${Server_IP}:${remotePort}"
else
echo -e "${green}内网网址:${plain} http://${Server_IP}:${remotePort}"
echo -e "${green}公网网址:${plain} http://${Public_IP}:${remotePort}"
fi

echo -e "${green}如需修改其他配置请前往 cd${orgin_file_dir} 根据注释修改 vim docker-compose.yml文件后${plain}"
echo -e "${green}先自行学习vim用法,否则建议使用sftp或WindTerm等ssh自带sftp的软件直接打开编辑${plain}"
echo -e "${green}修改后前往 cd${orgin_file_dir} 后通过命令docker-compose up -d 重启即可${plain}"

0 comments on commit 38ff966

Please sign in to comment.