centos 部署整套应用
分享:服务器部署java的环境和应用
初始化 ECS
购买 ECS
阿里云 ECS 官网 https://www.aliyun.com/minisite/goods?userCode=ueyxv2qf
数据库/redis 等也安装在云上 镜像选择centos7

初始化 CentOS7
curl -O http://pigx.vip/os7init.sh
sh os7init.sh pig4cloud
安装 JDK
yum install -y java
java -version
安装 Mysql 8
https://dev.mysql.com/downloads/
rpm -ivh xx.rpm
yum install -y mysql mysql-server
vi /etc/my.cnf
lower_case_table_names=1
systemctl restart mysqld
grep password /var/log/mysqld.log
set global validate_password.check_user_name=0;
set global validate_password.policy=0;
set global validate_password.length=1;
alter user 'root'@'localhost' identified by 'root';
use mysql;
update user set host = '%' where user = 'root';
FLUSH PRIVILEGES;
安装 Redis
yum install redis
systemctl restart redis
安装 NGINX
https://nginx.org/en/linux_packages.html
vim /etc/yum.repos.d/nginx.repo
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
yum install -y yum-utils
yum-config-manager --enable nginx-mainline
yum install -y nginx
配置 hosts
vim /etc/hosts
127.0.0.1 pig-mysql
127.0.0.1 pig-redis
127.0.0.1 pig-gateway
127.0.0.1 pig-register
127.0.0.1 pig-sentinel
127.0.0.1 pig-job
source /etc/hosts
部署 pig
准备源码包
pig 服务端 编译 jar
mvn clean install
pig-ui 前端 编译 dist
npm run build
初始化数据库
pig db目录
source pig.sql
source pig_codegen.sql
source pig_config.sql
source pig_job.sql
启动服务端
nohup java -Dfile.encoding=utf-8 -jar pig-register.jar > /dev/null 2>&1 &
nohup java -Dfile.encoding=utf-8 -jar pig-monitor.jar > /dev/null 2>&1 &
nohup java -Dfile.encoding=utf-8 -jar pig-sentinel-dashboard.jar > /dev/null 2>&1 &
nohup java -Dfile.encoding=utf-8 -jar pig-xxl-job-admin.jar > /dev/null 2>&1 &
nohup java -Dfile.encoding=utf-8 -jar pig-gateway.jar > /dev/null 2>&1 &
nohup java -Dfile.encoding=utf-8 -jar pig-auth.jar > /dev/null 2>&1 &
nohup java -Dfile.encoding=utf-8 -jar pig-upms-biz.jar > /dev/null 2>&1 &
部署前端
mkdir -p /data/pig-ui && cp -r dist/* /data/pig-ui
cd /etc/nginx/conf.d && rm -f default.conf
vim pigx.conf
server {
listen 80;
server_name localhost;
# 打包好的dist目录文件,放置到这个目录下
root /data/pig-ui;
# 注意维护新增微服务,gateway 路由前缀
location ~* ^/(code|auth|admin|gen) {
proxy_pass http://127.0.0.1:9999;
#proxy_set_header Host $http_host;
proxy_connect_timeout 15s;
proxy_send_timeout 15s;
proxy_read_timeout 15s;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto http;
}
}
nginx
ECS 安全组
注意配置安全组,服务相关的端口对外暴露

80/443
9999 网关 (如需访问swagger 需要)
5001 监控 (如需访问monitor 需要)
5020 监控 (如需访问monitor 需要)