基础环境搭建

① 购买 ECS

:::warning

centos 部署整套应用 - 图1

② 初始化 CentOS7

  1. curl -O https://pigx.vip/os7init.sh
  2. sh os7init.sh pig4cloud

③ 安装 JDK

  1. yum install -y java
  2. java -version

④ 安装 Mysql 8

:::success 点击下载 Mysql rpm 安装包 mysql80-community-release-el7-7.noarch.rpm.zip :::

  1. rpm -ivh mysql80-community-release-el7-7.noarch.rpm
  2. yum install -y mysql mysql-server
  3. # 修改配置文件
  4. vim /etc/my.cnf
  5. lower_case_table_names=1
  6. # 重启mysql
  7. systemctl restart mysqld
  8. # 查看默认密码
  9. grep password /var/log/mysqld.log
  10. # mysql client 链接 mysql
  11. alter user 'root'@'localhost' identified by 'ZxcRoot123!@#';
  12. set global validate_password.check_user_name=0;
  13. set global validate_password.policy=0;
  14. set global validate_password.length=1;
  15. alter user 'root'@'localhost' identified by 'root';
  16. # 修改为允许远程访问
  17. use mysql;
  18. update user set host = '%' where user = 'root';
  19. FLUSH PRIVILEGES;

⑤ 安装 Redis

  1. yum install redis
  2. systemctl restart redis

⑥ 安装 NGINX

  1. vim /etc/yum.repos.d/nginx.repo
  2. [nginx-stable]
  3. name=nginx stable repo
  4. baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
  5. gpgcheck=1
  6. enabled=1
  7. gpgkey=https://nginx.org/keys/nginx_signing.key
  8. module_hotfixes=true
  9. [nginx-mainline]
  10. name=nginx mainline repo
  11. baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
  12. gpgcheck=1
  13. enabled=0
  14. gpgkey=https://nginx.org/keys/nginx_signing.key
  15. module_hotfixes=true
  1. yum install -y yum-utils
  2. yum-config-manager --enable nginx-mainline
  3. yum install -y nginx

⑦ 配置 hosts

  1. vim /etc/hosts
  2. 127.0.0.1 pig-mysql
  3. 127.0.0.1 pig-redis
  4. 127.0.0.1 pig-gateway
  5. 127.0.0.1 pig-register
  6. 127.0.0.1 pig-sentinel
  7. 127.0.0.1 pig-job
  8. source /etc/hosts

部署应用代码

准备源码包

  • pig 服务端 编译 jar
  1. mvn clean install
  • pig-ui 前端 编译 dist
  1. npm run build

初始化数据库

  1. mysql -uroot -proot
  2. >
  3. source pig.sql
  4. source pig_codegen.sql
  5. source pig_config.sql
  6. source pig_job.sql

启动服务端

  1. nohup java -Dfile.encoding=utf-8 -jar pig-register.jar > /dev/null 2>&1 &
  2. nohup java -Dfile.encoding=utf-8 -jar pig-monitor.jar > /dev/null 2>&1 &
  3. nohup java -Dfile.encoding=utf-8 -jar pig-sentinel-dashboard.jar > /dev/null 2>&1 &
  4. nohup java -Dfile.encoding=utf-8 -jar pig-xxl-job-admin.jar > /dev/null 2>&1 &
  5. nohup java -Dfile.encoding=utf-8 -jar pig-gateway.jar > /dev/null 2>&1 &
  6. nohup java -Dfile.encoding=utf-8 -jar pig-auth.jar > /dev/null 2>&1 &
  7. nohup java -Dfile.encoding=utf-8 -jar pig-upms-biz.jar > /dev/null 2>&1 &

部署前端

  1. mkdir -p /data/pig-ui && cp -r dist/* /data/pig-ui
  2. cd /etc/nginx/conf.d && rm -f default.conf
  3. vim pigx.conf
  4. server {
  5. listen 80;
  6. server_name localhost;
  7. gzip on;
  8. gzip_static on; # 需要http_gzip_static_module 模块
  9. gzip_min_length 1k;
  10. gzip_comp_level 4;
  11. gzip_proxied any;
  12. gzip_types text/plain text/xml text/css;
  13. gzip_vary on;
  14. gzip_http_version 1.0; #兼容多层nginx 反代
  15. gzip_disable "MSIE [1-6]\.(?!.*SV1)";
  16. # 打包好的dist目录文件,放置到这个目录下
  17. root /data/pig-ui;
  18. # 注意维护新增微服务,gateway 路由前缀
  19. location ~* ^/(code|auth|admin|gen) {
  20. proxy_pass http://127.0.0.1:9999;
  21. #proxy_set_header Host $http_host;
  22. proxy_connect_timeout 15s;
  23. proxy_send_timeout 15s;
  24. proxy_read_timeout 15s;
  25. proxy_set_header X-Real-IP $remote_addr;
  26. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  27. proxy_set_header X-Forwarded-Proto http;
  28. }
  29. # 避免端点安全问题
  30. if ($request_uri ~ "/actuator"){
  31. return 403;
  32. }
  33. }
  34. nginx

ECS 安全组

注意配置安全组,服务相关的端口对外暴露

  • 80/443 (生产模式只需要开启此关口)

  • 9999 网关 (如需访问swagger 需要)

  • 5001 监控 (如需访问monitor 需要)
  • 5020 监控 (如需访问monitor 需要)

centos 部署整套应用 - 图2

❤ 问题咨询

手势点击蓝字求关注简约风动态引导关注__2022-09-07+23_18_38.gif