[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# systemctl disable firewalld
[root@localhost ~]# setenforce 0
[root@localhost ~]# getenforce
Permissive
[root@localhost ~]# sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
获取yum网络源:
[root@localhost ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
安装java11
[root@localhost ~]# yum -y install java-11*
[root@localhost ~]# java -version
返回如下图结果,则安装成功:
(这里是之前的图面,但是返回结果都差不多;重点关注我们的版本号是不是我们安装大java版本)
官网地址:https://maven.apache.org/download.cgi
下载:apache-maven-3.8.3-bin.tar.gz
①下载好的maven包上传到root目录下:
解压maven:
[root@localhost ~]# tar -zxf apache-maven-3.8.3-bin.tar.gz
修改解压后的名字:
[root@localhost ~]# mv apache-maven-3.8.3 maven3.8
将maven3.8目录移动到/usr/local目录下:
[root@localhost ~]# mv maven3.8/ /usr/local/
[root@localhost ~]# ls /usr/local/
②配置环境变量:
[root@localhost ~]# vi /etc/profile
(在环境变量最后一行添加以下代码)
export MAVEN_HOME=/usr/local/maven3.8 export PATH=$MAVEN_HOME/bin:$PATH
刷新一下环境变量:
[root@localhost ~]# source /etc/profile
③配置maven镜像仓库
[root@localhost ~]# vi /usr/local/maven3.8/conf/settings.xml
alimaven aliyun maven http://maven.aliyun.com/nexus/content/groups/public/ central
(如下图所示配置完成)
④查看maven是否安装成功:
(输出图片以下结果,则安装成功)
[root@localhost ~]# mvn -version
安装必要的依赖包
[root@localhost ~]# yum -y install wget
获取yum网络源:
[root@localhost ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
[root@localhost ~]# yum repolist
安装依赖包:
[root@localhost ~]# yum install -y yum-utils device-mapper-persistent-data lvm2
添加软件源信息;
[root@localhost ~]# yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
更新并安装docker-ce:
[root@localhost ~]# yum makecache fast
[root@localhost ~]# yum -y install docker-ce
启动docker并设置为开机自启:
[root@localhost ~]# systemctl start docker
[root@localhost ~]# systemctl enable docker
查看是否启动成功:
[root@localhost ~]# systemctl status docker
项目地址:https://gitee.com/random2022/springboot_demo.git
安装git:
[root@localhost ~]# yum -y install git
gitee官网拉取项目:
[root@localhost ~]# git clone https://gitee.com/random2022/springboot_demo.git
拉取mysql镜像:
[root@localhost ~]# docker pull mysql:5.5
(拉去成功可以看到有了MySQL镜像)
创建mysql容器:
[root@localhost ~]# docker run -id -p 3306:3306 --name mysql -e MYSQL_ROOT_PASSWORD=root mysql:5.5
(查看mysql容器是否成功运行)
[root@localhost ~]# docker ps
将springboot项目的new.sql文件拷贝到mysql容器root目录下:
[root@localhost ~]# docker cp /root/springboot_demo/src/main/resources/new.sql mysql:/root/
(拷贝成功,如下图所示)
进入mysql容器内,创建springboot数据库,并上传new.sql的数据:
[root@localhost ~]# docker exec -it mysql bash
登录数据库:
create database springboot; #创建springboot数据库
use springboot ; #切换到springboot数据库
source /root/new.sql; #上传new.sql数据
show tables; #使用show tables查看有没有user
进入springboot_demo项目目录:
[root@localhost ~]# cd springboot_demo/
(因为是容器启动的mysql数据库,所以要加上IP地址)
[root@localhost springboot_demo]# vi /root/springboot_demo/src/main/resources/application.yml
注意:provided表示在编译和测试时使用(不加它,打的包中会指定tomcat,用tomcat部署时会因tomcat版本报错;而加上它,打包时不会把内置的tomcat打进去)
(还是在pom.xml文件中,dependencies下面添加:
[root@localhost ~]# vim /root/springboot_demo/pom.xml
[root@localhost ~]# vim /root/springboot_demo/src/main/java/net/zjitc/SpringbootDemoApplication.java
将项目的启动类SpringbootDemoApplication.java继承SpringBootServletInitializer并重写configure方法。
package net.zjitc; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; @SpringBootApplication public class SpringbootDemoApplication extends SpringBootServletInitializer { @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { return builder.sources(SpringbootDemoApplication.class); } public static void main(String[] args) { SpringApplication.run(SpringbootDemoApplication.class, args); } }
(将springboot项目打包成war包)
[root@localhost springboot_demo]# mvn clean package -DskipTests
(编辑完成后会出现一个target目录)
进入target目录可以发现该目录下有一个springboot项目的war包:
[root@localhost springboot_demo]# cd target/
将springboot项目war拷贝到tomcat的webapps目录下:
[root@localhost ~]# cp /root/springboot_demo/target/Springboot_demo-0.0.1-SNAPSHOT.war /usr/local/tomcat/webapps/
[root@localhost ~]# cd /usr/local/tomcat/webapps/
启动tomcat服务:
[root@localhost webapps]# /usr/local/tomcat/bin/startup.sh
可以看到启动tomcat服务后war包自动解压:
浏览器输入:IP地址+8080/manager/html
(可以看到springboot项目已经部署成功)
访问springboot项目:
浏览器访问:IP地址+8080/Springboot_demo-0.0.1-SNAPSHOT/manager/html