部署前后端分离项目,要求前端项目、后端项目、数据库分别部署在3台服务器
服务器准备
服务器名 | IP | 软件包 |
---|---|---|
前端 | 192.168.99.137 | nginx |
后端 | 192.168.99.139 | jar |
数据库 | 192.168.99.100 | mariadb |
1、前端服务器
bash
yum install -y epel-release && yum install -y nginx
bash
vim /etc/nginx/nginx.conf
perl
server {
listen 80;
server_name 192.168.99.137;
location / {
root /usr/share/nginx/html/bm;
index index.html index.htm;
}
location /bm {
proxy_pass http://192.168.99.139:8090;
}
2、后端服务器
安装jdk
rpm ......
查看后端端口号和项目路径
bash
vim carbon.jar
bash
#回车
99 BOOT-INF/classes/application-dev.properties
远程连接数据库
进入BOOT-INF/classes/application.properties
java
#修改配置
spring.datasource.url=jdbc:mysql://192.168.99.130:3306/carbon?useSSL=false&useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=Asia/Shanghai&characterEncoding=utf8
3、mysql服务器
- 安装mariadb
bash
yum install -y mariadb-server
systemctl start mariadb
- 更改密码
sql
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('root');
create user 'root'@'192.168.99.139' identified by 'root';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.99.139' IDENTIFIED BY 'root';
FLUSH PRIVILEGES;
exit
- 导入数据库
bash
mysql -uroot -p < carbon.sql
4、测试
启动后端项目
bash
java -jar carbon.jar
浏览器访问网站