From 5f1c39bbf1466dd172195406fdeb58a821db90b6 Mon Sep 17 00:00:00 2001 From: Junling Bu Date: Mon, 30 Jul 2018 13:49:47 +0800 Subject: [PATCH] =?UTF-8?q?deploy=E5=86=8D=E6=AC=A1=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- deploy/.gitignore | 9 +- deploy/README.md | 130 +++++++++++++++++--------- deploy/bin/deploy.sh | 31 +----- deploy/bin/reset.sh | 11 +-- deploy/litemall/application-admin.yml | 0 deploy/litemall/application-core.yml | 105 +++++++++++++++++++++ deploy/litemall/application-db.yml | 26 ++++++ deploy/litemall/application-wx.yml | 0 deploy/litemall/application.yml | 19 ++++ deploy/util/lazy.sh | 8 +- deploy/util/package.sh | 27 ++---- 11 files changed, 264 insertions(+), 102 deletions(-) create mode 100644 deploy/litemall/application-admin.yml create mode 100644 deploy/litemall/application-core.yml create mode 100644 deploy/litemall/application-db.yml create mode 100644 deploy/litemall/application-wx.yml create mode 100644 deploy/litemall/application.yml diff --git a/deploy/.gitignore b/deploy/.gitignore index 9b6a6735..ed5468bd 100644 --- a/deploy/.gitignore +++ b/deploy/.gitignore @@ -1,6 +1,3 @@ -/litemall-admin/dist.tar -/litemall-db/litemall_schema.sql -/litemall-db/litemall_table.sql -/litemall-db/litemall_data.sql -/litemall-api/litemall-admin-api.jar -/litemall-api/litemall-wx-api.jar \ No newline at end of file + +/db/litemall.sql +/litemall/litemall.jar diff --git a/deploy/README.md b/deploy/README.md index 77197d25..903619a2 100644 --- a/deploy/README.md +++ b/deploy/README.md @@ -1,58 +1,104 @@ +## deploy -1. 项目进一步打包到deploy文件夹中: - * litemall-wx-api模块编译得到的litemall-wx-api-0.1.0-exec.jar 保存到deploy的litemall-api文件夹中,同时重命名成litemall-wx-api.jar - * litemall-admin-api模块编译得到的litemall-admin-api-0.1.0-exec.jar 保存到deploy的litemall-api文件夹中,同时重命名成litemall-admin-api.jar - * litemall-admin模块编译以后,把dist文件夹压缩,然后放到deploy的litemall-admin文件夹中。 - * litemall-db模块的sql文件拷贝到deploy的litemall-db文件夹中。 +### 项目打包 -2. 使用FileZilla把deploy整个文件夹上传到云主机的/home/ubuntu文件夹中 +1. 在主机或者开发机打包项目到deploy; + ``` + cd litemall + cat ./litemall-db/sql/litemall_schema.sql > ./deploy/db/litemall.sql + cat ./litemall-db/sql/litemall_table.sql >> ./deploy/db/litemall.sql + cat ./litemall-db/sql/litemall_data.sql >> ./deploy/db/litemall.sql + + cd ./litemall-admin + cnpm install + cnpm run build:dep + + cd .. + mvn clean package + cp -f ./litemall-all/target/litemall-all-*-exec.jar ./deploy/litemall/litemall.jar + ``` + 这里的工作是: + 1. 把数据库文件拷贝到deploy/db文件夹 + 2. 编译litemall-admin项目 + 3. 编译litemall-all模块,同时把litemall-admin编译得到的静态文件拷贝到 + litemall-all模块的static目录 + +2. 修改litemall文件夹下面的*.yml外部配置文件,当litemall-all模块启动时会 + 加载外部配置文件,而覆盖默认jar包内部的配置文件。 + 例如,配置文件中一些地方需要设置成远程主机的IP地址 + +此时deploy部署包结构如下: -3. 使用PuTTY登录云主机 +* bin -4. 如果开发者没有部署litemall数据库,可以运行以下命令: +存放远程主机运行的脚本,包括deploy.sh脚本和reset.sh脚本 +* db + +存放litemall数据库文件 + +* litemall + +存放远程主机运行的代码,包括litemall-all二进制可执行包和litemall外部配置文件 + +* util +存放开发主机运行的脚本,包括package.sh脚本和lazy.sh脚本。 +由于是本地开发主机运行,因此开发者可以不用上传到远程主机。 + +### 项目部署 + +1. 远程主机环境(MySQL和JDK1.8)已经安装好,请确保云主机的安全组已经允许相应的端口。 +2. 导入db/litemall.sql ```bash - cd deploy - mysql -h localhost -u root -p123456 - source ./litemall-db/litemall_schema.sql - use litemall; - source ./litemall-db/litemall_table.sql - source ./litemall-db/litemall_data.sql + cd /home/ubuntu/deploy/db + mysql -h localhost -u $ROOT -p$PASSWORD < litemall.sql ``` - 注意,123456是开发者所设置的MySQL管理员密码 - 警告: - > litemall_schema.sql会尝试删除litemall数据库然后重建一个新的数据。 - -5. 运行脚本部署运行 - +3. 启动服务 ```bash - sudo ./deploy/bin/deploy.sh + sudo service litemall stop + sudo ln -f -s /home/ubuntu/deploy/litemall/litemall.jar /etc/init.d/litemall + sudo service litemall start ``` - -6. 测试部署是否成功 - - 请确保云主机的安全组已经允许相应的端口(见1.5.3.1); - 然后测试是否部署成功(xxx.xxx.xxx.xxx是云主机IP): - +4. 测试是否部署成功(xxx.xxx.xxx.xxx是云主机IP): ``` - http://xxx.xxx.xxx.xxx:8082/wx/index/index - http://xxx.xxx.xxx.xxx:8083/admin/index/index + http://xxx.xxx.xxx.xxx:8080/wx/index/index + http://xxx.xxx.xxx.xxx:8080/admin/index/index http://xxx.xxx.xxx.xxx:8080/#/login ``` -7. 部署脚本 +### 项目辅助脚本 - 为了简化步骤1和步骤2,完成了deploy/util/package.sh上传脚本和deploy/util/lazy.sh部署脚本, +在前面的项目打包和项目部署中都是采用手动命令来部署。 +这里可以写一些脚本简化: + +* util/packet.sh + +在开发主机运行可以自动项目打包 + +* util/lazy.sh + +在开发主机运行可以自动项目打包、项目上传远程主机、自动登录系统执行项目部署脚本。 - 注意: - > 1. 开发者需要在deploy/util/package.sh和deploy/util/lazy.sh中设置相应的云主机登录账号和密钥文件路径。 - > 2. 开发者需要在deploy/bin/reset.sh设置云主机的MySQL的root登录账户。 - > 3. 请先执行1.5.1中上述步骤,确保部署环境成功。 +注意: +> 1. 开发者需要在util/lazy.sh中设置相应的远程主机登录账号和密钥文件路径。 +> 2. 开发者需要在bin/reset.sh设置远程主机的MySQL的root登录账户。 - * package.sh - - 该脚本会自动把当前项目Spring Boot项目打包和Vue项目打包工作,然后复制到deploy文件夹中。 - - * lazy.sh - - 该脚本会调用package.sh打包项目,然后上传deploy文件夹到云主机,最后ssh登录远程主机执行bin下面的deploy.sh脚本。 \ No newline at end of file +* bin/deploy.sh + +在远程主机运行可以自动部署服务 + +* bin/reset.sh + +在远程主机运行可以自动项目导入数据、删除本地上传图片、再执行bin/deploy.sh部署服务。 + +注意: +> 开发者需要在bin/reset.sh设置远程主机的MySQL的root登录账户。 + +总结,当开发者设置好配置信息以后,可以在本地运行lazy.sh脚本自动一键部署: +```bash +cd litemall +./deploy/util/lazy.sh +``` + +不过由于需要设置的信息会包含敏感安全信息,强烈建议开发者参考这里的deploy文件夹, +然后实现自己的deploy文件夹,妥善处置外部配置文件和脚本中的敏感安全信息!!! \ No newline at end of file diff --git a/deploy/bin/deploy.sh b/deploy/bin/deploy.sh index 832a255c..cf3623b6 100644 --- a/deploy/bin/deploy.sh +++ b/deploy/bin/deploy.sh @@ -1,29 +1,6 @@ #!/bin/bash -# 请注意 -# 1. 本脚本的作用是停止当前Spring Boot应用,然后再次部署 -# 2. 解压dist.tar到/home/ubuntu/deploy/litemall-admin/dist, -# 而这个目录也正是tomcat或者nginx所配置静态文件目录的路径(见1.5.3.5节) - -#部署litemall-admin静态文件应用 -cd /home/ubuntu/deploy/litemall-admin -rm -rf dist -mkdir dist -tar -zxvf dist.tar -C dist - -#部署三个Spring Boot应用 -#如果服务已经启动,则尝试停止 -sudo service litemall-wx-api stop -sudo service litemall-admin-api stop - -#部署Spring Boot应用成服务 -sudo ln -f -s /home/ubuntu/deploy/litemall-api/litemall-wx-api.jar /etc/init.d/litemall-wx-api -sudo ln -f -s /home/ubuntu/deploy/litemall-api/litemall-admin-api.jar /etc/init.d/litemall-admin-api - -#启动服务 -sudo service litemall-wx-api restart -sudo service litemall-admin-api restart - -# 如果静态文件是通过tomcat来服务,则tomcat8服务最好也再启动 -#sudo service tomcat8 stop -#sudo service tomcat8 start \ No newline at end of file +# 本脚本的作用是停止当前Spring Boot应用,然后再次部署 +sudo service litemall stop +sudo ln -f -s /home/ubuntu/deploy/litemall/litemall.jar /etc/init.d/litemall +sudo service litemall start \ No newline at end of file diff --git a/deploy/bin/reset.sh b/deploy/bin/reset.sh index aa34d9cc..e6bc8e21 100644 --- a/deploy/bin/reset.sh +++ b/deploy/bin/reset.sh @@ -18,15 +18,12 @@ then exit -1 fi -cd /home/ubuntu/deploy/litemall-db -cat litemall_schema.sql > db.sql -cat litemall_table.sql >> db.sql -cat litemall_data.sql >> db.sql -mysql -h localhost -u $ROOT -p$PASSWORD < db.sql -rm db.sql +# 导入数据 +cd /home/ubuntu/deploy/db +mysql -h localhost -u $ROOT -p$PASSWORD < litemall.sql # 删除storage文件夹内文件 -cd /home/ubuntu/deploy/litemall-api/storage +cd /home/ubuntu/deploy/litemall/storage rm -f ./** # 重新部署服务 diff --git a/deploy/litemall/application-admin.yml b/deploy/litemall/application-admin.yml new file mode 100644 index 00000000..e69de29b diff --git a/deploy/litemall/application-core.yml b/deploy/litemall/application-core.yml new file mode 100644 index 00000000..308e6327 --- /dev/null +++ b/deploy/litemall/application-core.yml @@ -0,0 +1,105 @@ +litemall: + # 开发者应该设置成自己的wx相关信息 + wx: + app-id: wxa5b486c6b918ecfb + app-secret: e04004829d4c383b4db7769d88dfbca1 + mch-id: 111111 + mch-key: xxxxxx + notify-url: http://122.152.206.172:8080/wx/order/pay-notify + + #通知相关配置 + notify: + mail: + # 邮件通知配置,邮箱一般用于接收业务通知例如收到新的订单,sendto 定义邮件接收者,通常为商城运营人员 + enable: false + host: smtp.exmail.qq.com + username: ex@ex.com.cn + password: XXXXXXXXXXXXX + sendfrom: ex@ex.com.cn + sendto: ex@qq.com + + # 短消息模版通知配置 + # 短信息用于通知客户,例如发货短信通知,注意配置格式;template-name,template-templateId 请参考 NotifyType 枚举值 + sms: + enable: false + appid: 111111111 + appkey: xxxxxxxxxxxxxx + template: + - name: paySucceed + templateId: 156349 + - name: captcha + templateId: 156433 + - name: ship + templateId: 158002 + - name: refund + templateId: 159447 + + # 微信模版通知配置 + # 微信模版用于通知客户或者运营者,注意配置格式;template-name,template-templateId 请参考 NotifyType 枚举值 + wx: + enable: false + template: + - name: paySucceed + templateId: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx + - name: captcha + templateId: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx + - name: ship + templateId: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx + - name: refund + templateId: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx + + # 快鸟物流查询配置 + express: + enable: false + appId: "XXXXXXXXX" + appKey: "XXXXXXXXXXXXXXXXXXXXXXXXX" + vendors: + - code: "ZTO" + name: "中通快递" + - code: "YTO" + name: "圆通速递" + - code: "YD" + name: "韵达速递" + - code: "YZPY" + name: "邮政快递包裹" + - code: "EMS" + name: "EMS" + - code: "DBL" + name: "德邦快递" + - code: "FAST" + name: "快捷快递" + - code: "ZJS" + name: "宅急送" + - code: "TNT" + name: "TNT快递" + - code: "UPS" + name: "UPS" + - code: "DHL" + name: "DHL" + - code: "FEDEX" + name: "FEDEX联邦(国内件)" + - code: "FEDEX_GJ" + name: "FEDEX联邦(国际件)" + + # 对象存储配置 + storage: + # 当前工作的对象存储模式,分别是local、aliyun、tencent + active: local + # 本地对象存储配置信息 + local: + storagePath: storage + address: http://122.152.206.172:8080/wx/storage/fetch/ + port: 8081 + # 阿里云对象存储配置信息 + aliyun: + endpoint: oss-cn-shenzhen.aliyuncs.com + accessKeyId: 111111 + accessKeySecret: xxxxxx + bucketName: xxxxxx + # 腾讯对象存储配置信息 + # 请参考 https://cloud.tencent.com/document/product/436/6249 + tencent: + secretId: 111111 + secretKey: xxxxxx + region: xxxxxx + bucketName: xxxxxx \ No newline at end of file diff --git a/deploy/litemall/application-db.yml b/deploy/litemall/application-db.yml new file mode 100644 index 00000000..efe31994 --- /dev/null +++ b/deploy/litemall/application-db.yml @@ -0,0 +1,26 @@ +pagehelper: + helperDialect: mysql + reasonable: true + supportMethodsArguments: true + params: count=countSql + +spring: + datasource: + druid: + url: jdbc:mysql://localhost:3306/litemall?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC&verifyServerCertificate=false&useSSL=false + driver-class-name: com.mysql.jdbc.Driver + username: litemall + password: litemall123456 + initial-size: 10 + max-active: 50 + min-idle: 10 + max-wait: 60000 + pool-prepared-statements: true + max-pool-prepared-statement-per-connection-size: 20 + validation-query: SELECT 1 FROM DUAL + test-on-borrow: false + test-on-return: false + test-while-idle: true + time-between-eviction-runs-millis: 60000 + filters: stat,wall,log4j + diff --git a/deploy/litemall/application-wx.yml b/deploy/litemall/application-wx.yml new file mode 100644 index 00000000..e69de29b diff --git a/deploy/litemall/application.yml b/deploy/litemall/application.yml new file mode 100644 index 00000000..3802b74f --- /dev/null +++ b/deploy/litemall/application.yml @@ -0,0 +1,19 @@ +spring: + profiles: + active: db, core, admin, wx + message: + encoding: UTF-8 + +server: + port: 8080 + +logging: + level: + root: ERROR + org.springframework: ERROR + org.mybatis: ERROR + org.linlinjava.litemall.core: ERROR + org.linlinjava.litemall.db: ERROR + org.linlinjava.litemall.admin: ERROR + org.linlinjava.litemall.wx: ERROR + org.linlinjava.litemall: ERROR \ No newline at end of file diff --git a/deploy/util/lazy.sh b/deploy/util/lazy.sh index 4ca240fe..33dbc35c 100644 --- a/deploy/util/lazy.sh +++ b/deploy/util/lazy.sh @@ -3,7 +3,7 @@ # 本脚本的作用是 # 1. 项目打包 # 2. 上传云主机 -# 3. 远程登录云主机并执行deploy脚本 +# 3. 远程登录云主机并执行reset脚本 # 请设置云主机的IP地址和账户 # 例如 ubuntu@122.152.206.172 @@ -34,10 +34,12 @@ cd $LITEMALL_HOME ./deploy/util/package.sh # 上传云主机 +cd $LITEMALL_HOME scp -i $ID_RSA -r ./deploy $REMOTE:/home/ubuntu/ -# 远程登录云主机并执行deploy脚本 +# 远程登录云主机并执行reset脚本 ssh $REMOTE -i $ID_RSA << eeooff -sudo ./deploy/bin/deploy.sh +cd /home/ubuntu +sudo ./deploy/bin/reset.sh exit eeooff \ No newline at end of file diff --git a/deploy/util/package.sh b/deploy/util/package.sh index 45aac623..9df8a1fc 100644 --- a/deploy/util/package.sh +++ b/deploy/util/package.sh @@ -2,9 +2,9 @@ # 请注意 # 本脚本的作用是把本项目编译的结果保存到deploy文件夹中 -# 1. 把项目数据库文件拷贝到litemall-db -# 2. 编译litemall-admin,然后打包到litemall-admin -# 3. 编译后台服务模块,然后拷贝到litemall-api +# 1. 把项目数据库文件拷贝到deploy/db +# 2. 编译litemall-admin +# 3. 编译litemall-all模块,然后拷贝到deploy/litemall DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )" cd $DIR/../.. @@ -12,24 +12,17 @@ LITEMALL_HOME=$PWD echo "LITEMALL_HOME $LITEMALL_HOME" # 复制数据库 -cp -f ./litemall-db/sql/litemall_schema.sql ./deploy/litemall-db/litemall_schema.sql -cp -f ./litemall-db/sql/litemall_table.sql ./deploy/litemall-db/litemall_table.sql -cp -f ./litemall-db/sql/litemall_data.sql ./deploy/litemall-db/litemall_data.sql +cat $LITEMALL_HOME/litemall-db/sql/litemall_schema.sql > $LITEMALL_HOME/deploy/db/litemall.sql +cat $LITEMALL_HOME/litemall-db/sql/litemall_table.sql >> $LITEMALL_HOME/deploy/db/litemall.sql +cat $LITEMALL_HOME/litemall-db/sql/litemall_data.sql >> $LITEMALL_HOME/deploy/db/litemall.sql -cd ./litemall-admin +cd $LITEMALL_HOME/litemall-admin # 安装阿里node镜像工具 npm install -g cnpm --registry=https://registry.npm.taobao.org # 安装node项目依赖环境 cnpm install cnpm run build:dep -cd .. -# 压缩litemall-admin应用 -tar -zcvf ./deploy/litemall-admin/dist.tar -C ./litemall-admin/dist . -# 复制三个Spring Boot应用 -# 需要注意的是target目录里面存在两种jar,一种是当前模块纯编译代码的jar,另外一种是包含依赖库的可执行jar, -# 这里我们需要的是可执行jar -mvn clean -mvn package -cp -f ./litemall-wx-api/target/litemall-wx-api-*-exec.jar ./deploy/litemall-api/litemall-wx-api.jar -cp -f ./litemall-admin-api/target/litemall-admin-api-*-exec.jar ./deploy/litemall-api/litemall-admin-api.jar \ No newline at end of file +cd $LITEMALL_HOME +mvn clean package +cp -f $LITEMALL_HOME/litemall-all/target/litemall-all-*-exec.jar $LITEMALL_HOME/deploy/litemall/litemall.jar \ No newline at end of file