diff --git a/doc/docker.md b/doc/docker.md index d6d4b24..146add3 100644 --- a/doc/docker.md +++ b/doc/docker.md @@ -1,5 +1,5 @@ -### Docker最小化部署前准备 -系统|Centos 8 Stream 纯净系统 [1cpu 4G内存] +### Docker最小化部署前准备,如果使用超级签和云存储,需要使用阿里云的服务器 +系统|Centos 8 Stream 纯净系统 [2cpu 4G内存] ----|---- 域名|```app.hehelucky.cn``` 域名SSL证书| nginx 格式证书 [阿里云和腾讯云都可以申请免费ssl证书] @@ -11,19 +11,19 @@ ``` cd /data/ dnf install git -y -git clone https://github.com/nineaiyu/FlyApps +git clone https://github.com/nineaiyu/flyapps ``` -## 注意,下面展示的相对路径,都是以```/data/FlyApps```为相对目录 +## 注意,下面展示的相对路径,都是以```/data/flyapps```为相对目录 #### 2.docker环境安装 ``` -cd /data/FlyApps/docker/init +cd /data/flyapps/docker/init sh init.sh ``` #### 3.配置域名和证书,如果有cdn或者oss,也要进行配置 -a.将域名证书通过```sftp软件```或者```rz命令```复制到```/data/FlyApps/nginx.conf.d```目录中 +a.将域名证书通过```sftp软件```或者```rz命令```复制到```/data/flyapps/nginx.conf.d```目录中 b.将域名证书分别重命名为 ```域名.pem``` 和 ```域名.key``` .本次使用的域名是 ```app.hehelucky.cn``` ,因此,证书名称类似如下 ```shell script @@ -59,19 +59,19 @@ const pro_base_env = { ##### 构建静态资源 ``` -cd /data/FlyApps/docker/scripts +cd /data/flyapps/docker/scripts sh build.sh ``` ##### 启动所有服务 ``` -cd /data/FlyApps/docker/scripts +cd /data/flyapps/docker/scripts sh start_all.sh ``` ##### 关闭所有服务 ``` -cd /data/FlyApps/docker/scripts +cd /data/flyapps/docker/scripts sh stop_all.sh ``` @@ -82,4 +82,21 @@ docker exec -it flyapps python manage.py createsuperuser ##### 测试访问 - 在浏览器输入自己配置的域名 https://app.hehelucky.cn/ 进行访问 -- 管理后台访问 https://app.hehelucky.cn:3448/ 进行访问 \ No newline at end of file +- 管理后台访问 https://app.hehelucky.cn:3448/ 进行访问 + + +##### 如果要使用本地的数据库和redis,api服务使用容器,需要修改文件```/data/flyapps/docker/flyapps/docker-compose.yml``` +```shell + external_links: + - mariadb:mariadb + - redis:redis +``` +修改为 +```shell + extra_hosts: + - "mariadb:172.31.31.1" + - "redis:172.31.31.1" +``` +并将```nginx:```下面的配置注释掉 + +同时还需要修改mariadb和redis授权 \ No newline at end of file diff --git a/doc/local.md b/doc/local.md index c9487f0..b3d91e3 100644 --- a/doc/local.md +++ b/doc/local.md @@ -1,5 +1,5 @@ ### 本地部署前准备 -系统|Centos 8 Stream [1cpu 4G内存] +系统 | Centos 8 Stream [2cpu 4G内存] ----|---- 域名|```app.hehelucky.cn``` 域名SSL证书| nginx 格式证书 [阿里云和腾讯云都可以申请免费ssl证书] @@ -9,78 +9,158 @@ ##### 从git上面下载源码 ```shell cd /data/ -git clone https://github.com/nineaiyu/FlyApps +dnf install git gcc zip unzip -y +git clone https://github.com/nineaiyu/flyapps ``` -### FlyApp 本地部署 [python3 环境] +### flyapps 本地部署 [python3 环境] ##### 搭建python env 环境 ```shell -yum install python39 python39-devel redis mariadb-server mariadb-devel -y +dnf install python39 python39-devel redis mariadb-server mariadb-devel -y python3.9 -m venv py39 source py39/bin/activate ``` ###### 安装pip包 ```shell -cd fir_ser/ -pip install -U setuptools pip -pip install -r requirements.txt +cd /data/flyapps/fir_ser/ +pip install -U setuptools pip -i https://pypi.tuna.tsinghua.edu.cn/simple/ +pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple/ ``` -###### 配置数据库 +#### 配置数据库 +##### 启动mariadb数据库 +```shell +systemctl restart mariadb +systemctl enable mariadb ``` -在 config.py 配置redis 和 mysql 数据库 +##### 创建mysql数据库 +```shell +mysql ``` - -###### 迁移数据库 +执行下面mysql命令 +```mariadb +create database flyapps default character set utf8 COLLATE utf8_general_ci; +grant all on flyapps.* to flyuser@'127.0.0.1' identified by 'KGzKjZpWBp4R4RSa'; +``` +##### 启动redis数据库 ```shell -#如果是mysql,需要做一下配置,如果是sqlite,需要升级sqlite -#记得根据配置创建数据库 -#create database flyapp default character set utf8 COLLATE utf8_general_ci; -#grant all on flyapp.* to flyuser@'127.0.0.1' identified by 'flypwd00oo.1'; - -python manage.py makemigrations -python manage.py migrate +echo 'requirepass nineven' >> /etc/redis.conf # 配置授权密码 +systemctl restart redis +systemctl enable redis ``` -### FlyApp zsign ipa重签名工具安装 +### flyapps zsign ipa重签名工具安装 ```shell -yum install openssl-devel -y -yum install gcc-c++ gcc -y - -tar xvf v1.1.2.tar.gz +dnf install openssl-devel -y +dnf install gcc-c++ gcc -y +cd /data/flyapps/fir_ser/ +tar xvf zsign-1.1.2.tar.gz cd zsign-1.1.2/ -g++ *.cpp common/*.cpp -lcrypto -O3 -std=c++11 -o zsign -cp zsign /usr/bin/ +g++ *.cpp common/*.cpp -lcrypto -O3 -std=c++11 -o /usr/bin/zsign ``` -### FlyApp web端搭建 + +#### 配置api服务需要修改api和web域名,如果有需求,还可以配置 短信,邮箱,geetest,存储等信息 +##### fir_ser配置文件 ```fir_ser/config.py``` +```python +class DOMAINCONF(object): + API_DOMAIN = "https://app.hehelucky.cn" # 用与开启本地存储,上传应用配置 + WEB_DOMAIN = "https://app.hehelucky.cn" # 用于超级签跳转配置,该域名一般为前端页面域名 +``` + +##### fir_client配置文件 ```fir_client/vue.confjg.js``` +```javascript +const pro_base_env = { + baseUrl: '/', //该选项可以填写web-api的域名,类似 https://api.xxx.com/ + index_static: '/', //若配置cdn等加速,可以填写cdn加速域名 + baseShortUrl: '/', //该选项可以填写short-api的域名,也可以和web-api域名一样,类似 https://api.xxx.com/ + short_static: '/short/', //若配置cdn等加速,可以填写cdn加速域名 + version: version, +}; +``` + +### flyapps web端搭建 ###### npm编译环境 ```shell -yum install npm +dnf install npm -y npm install -g n n 12.13 # 安装12版本的node或者14版本 ,最新版本会有问题 npm install -g yarn ``` + + ###### 编译web端和下载页 ```shell -cd FlyApps/fir_client/ +cd /data/flyapps/fir_client/ vim vue.config.js #修改api接口地址 # pro_base_env 正式环境信息 # dev_base_env 开发环境信息 yarn install -yarn build index # web打包 -yarn build short # 下载也打包 +yarn build index # 前端打包,输出目录 dist_index +yarn build short # 下载页打包,输出目录 dist_short ``` ###### 编译web管理后台 ```shell -cd FlyApps/fir_admin/ - +cd /data/flyapps/fir_admin/ yarn install -yarn build +yarn build:prod # 下载页打包,输出目录 dist +``` + +### nginx配置 +##### 安装nginx +```shell +dnf install nginx -y +``` +##### 将域名ssl证书解压到```/etc/nginx/conf.d/``` 目录中,并重命名为```域名.pem```,```域名.key```格式 +##### 拷贝虚拟主机配置文件 +```shell +cp /data/flyapps/nginx.conf.d/flyapps-vhost.conf /etc/nginx/conf.d/ +``` +1.创建web目录,并将打包好的web复制该目录 +```shell +mkdir -pv /data/{fir_client/short,fir_admin} +cp -a /data/flyapps/fir_client/dist_index/* /data/fir_client/ +cp -a /data/flyapps/fir_client/dist_short/* /data/fir_client/short/ +cp -a /data/flyapps/fir_admin/dist/* /data/fir_admin/ +chown nginx.nginx -R /data/{fir_client,fir_admin} +``` +2.启动nginx服务 +```shell +nginx -t +systemctl restart nginx +systemctl enable nginx +``` + +##### 添加redis和mariadb uwsgi本地解析 +```shell +echo '127.0.0.1 mariadb redis flyapps' >> /etc/hosts +``` + +###### 迁移数据库 +```shell +cd /data/flyapps/fir_ser/ +python manage.py makemigrations +python manage.py migrate +``` + +#### 启动api服务 +```shell +echo 'net.core.somaxconn=1024' >> /etc/sysctl.conf +sysctl -p +cd /data/flyapps/fir_ser/ +python manage.py start all -u nginx -usm 1 -d +``` + +##### 根据提示创建默认管理用户,用与访问管理后台 +```shell +python manage.py createsuperuser ``` +- 需要输入用户名,邮箱和密码 +- 用户名和密码用与登录管理后台 +- 邮箱和密码用与登录前端web \ No newline at end of file diff --git a/docker/flyapps/docker-compose.only.yml b/docker/flyapps/docker-compose.only.yml new file mode 100644 index 0000000..d48e881 --- /dev/null +++ b/docker/flyapps/docker-compose.only.yml @@ -0,0 +1,31 @@ +version: '3' + +networks: + flyapps: + external: true + name: flyapps + +services: + flyapps: + container_name: flyapps + restart: always + image: 'nineven/flyapps' + working_dir: /data/fir_ser + volumes: + - /etc/localtime:/etc/localtime:ro + - ../../fir_ser:/data/fir_ser + - ../../data/flyapps/files:/data/fir_ser/files + - ../../data/logs/flyapps/:/data/fir_ser/logs + - ../../data/flyapps/supersign/:/data/fir_ser/supersign + - ../../nginx.conf.d:/data/cert + networks: + flyapps: + ipv4_address: 172.31.31.100 + external_links: + - mariadb:mariadb + - redis:redis + sysctls: + - net.core.somaxconn=4096 + extra_hosts: + - "mariadb:172.31.31.1" + - "redis:172.31.31.1" diff --git a/docker/init/clean.sh b/docker/init/clean.sh index c38b099..d186183 100644 --- a/docker/init/clean.sh +++ b/docker/init/clean.sh @@ -2,8 +2,6 @@ # # -for i in nginx flyapps mariadb redis buildclient buildshort buildadmin build-buildflyapps-1;do echo $i;docker rm -f $i;done - +for i in nginx flyapps mariadb redis buildclient buildshort buildadmin ;do echo $i;docker rm -f $i;done docker network rm flyapps - diff --git a/docker/init/download.images b/docker/init/download.images new file mode 100644 index 0000000..4df1571 --- /dev/null +++ b/docker/init/download.images @@ -0,0 +1,10 @@ +#!/bin/bash +# +# + + +docker pull 'bitnami/mariadb:10.7.3' +docker pull 'bitnami/redis:6.2.7' +docker pull 'nginx:1.21.3' +docker pull 'nineven/flyapps:latest' +docker pull 'node:14.17.3' diff --git a/docker/init/init.sh b/docker/init/init.sh index e716c6c..335881e 100644 --- a/docker/init/init.sh +++ b/docker/init/init.sh @@ -7,22 +7,18 @@ if [ $? -ne 0 ];then dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo dnf install docker-ce -y fi -which docker-compose -if [ $? -ne 0 ];then - curl -L https://get.daocloud.io/docker/compose/releases/download/v2.5.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose - chmod +x /usr/local/bin/docker-compose -fi +#which docker-compose +#if [ $? -ne 0 ];then +# curl -L https://get.daocloud.io/docker/compose/releases/download/v2.5.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose +# chmod +x /usr/local/bin/docker-compose +#fi data_path="$(dirname $(dirname `pwd`))/data" mkdir -pv ${data_path}/{flyapps/files,web,mariadb,redis,logs/{mariadb,nginx,flyapps}} \cp $(dirname $(dirname `pwd`))/fir_ser/files/head_img.jpeg ${data_path}/flyapps/files/ chown 1001.1001 -R ${data_path}/{flyapps,web,mariadb,redis,logs/{mariadb,nginx,flyapps}} -systemctl start docker && docker network create flyapps --driver bridge --subnet=172.31.31.0/24 +chown 101.101 -R ${data_path}/{flyapps,logs/flyapps} +systemctl start docker && docker network create flyapps --driver bridge --subnet=172.31.31.0/24 --gateway=172.31.31.1 systemctl enable docker systemctl status docker - -#docker pull 'bitnami/mariadb:10.7.3' -#docker pull 'bitnami/redis:6.2.7' -#docker pull 'nginx:1.21.3' -#docker pull 'node:14.17.3' diff --git a/docker/scripts/build.sh b/docker/scripts/build.sh index 6c6bc1f..193a3eb 100644 --- a/docker/scripts/build.sh +++ b/docker/scripts/build.sh @@ -3,4 +3,4 @@ # cd ../build/ -docker-compose up buildclient buildadmin +docker compose up buildclient buildadmin diff --git a/docker/scripts/start_all.sh b/docker/scripts/start_all.sh index d0b73b7..e43545e 100644 --- a/docker/scripts/start_all.sh +++ b/docker/scripts/start_all.sh @@ -2,8 +2,8 @@ # # -cd ../mariadb/ && docker-compose up -d -cd ../redis/ && docker-compose up -d +cd ../mariadb/ && docker compose up -d +cd ../redis/ && docker compose up -d -cd ../flyapps/ && docker-compose up -d +cd ../flyapps/ && docker compose up -d docker logs -f flyapps diff --git a/docker/scripts/stop_all.sh b/docker/scripts/stop_all.sh index da1a10f..f4d0f02 100644 --- a/docker/scripts/stop_all.sh +++ b/docker/scripts/stop_all.sh @@ -3,8 +3,8 @@ # -cd ../flyapps/ && docker-compose down +cd ../flyapps/ && docker compose down -cd ../redis/ && docker-compose down +cd ../redis/ && docker compose down -cd ../mariadb/ && docker-compose down +cd ../mariadb/ && docker compose down