前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >CentOS7.9搭建SpringBoot应用环境总结

CentOS7.9搭建SpringBoot应用环境总结

原创
作者头像
BrianLee
发布2023-03-12 16:17:26
8720
发布2023-03-12 16:17:26
举报
文章被收录于专栏:用户1031264的专栏

记录一下周末搭建SpringBoot单体应用的主要步骤:

1、运行环境

1.1、服务器环境

代码语言:javascript
复制
ssh root@192.168.0.1 
CentOS7.9
CentOS7.9

1.2、本机环境

1.3、Springboot版本及主要组件版本

代码语言:javascript
复制
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.7.4</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    
   <properties>
        <java.version>1.8</java.version>
        <ijapy.version>2.9.3</ijapy.version>
        <enjoy.version>4.3</enjoy.version>
<!--        <fastjson.version>1.2.75</fastjson.version>-->
        <zxing.version>3.5.0</zxing.version>
        <slf4j.api.version>2.0.3</slf4j.api.version>
        <xk.time.version>3.2.4</xk.time.version>
        <alipay.version>4.34.0.ALL</alipay.version>
        <fastjson.version>2.0.14.graal</fastjson.version>
    </properties>
    
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-freemarker</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>2.2.2</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-boot-starter</artifactId>
            <version>3.0.0</version>
        </dependency>
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
            <version>3.5.2</version>
        </dependency>
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-generator</artifactId>
            <version>3.5.3</version>
        </dependency>
        <dependency>
            <groupId>io.jsonwebtoken</groupId>
            <artifactId>jjwt</artifactId>
            <version>0.9.1</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-amqp</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.amqp</groupId>
            <artifactId>spring-rabbit-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.generator</groupId>
            <artifactId>uid-generator</artifactId>
            <version>1.0.0-SNAPSHOT</version>
            <exclusions>
                <exclusion>
                    <groupId>org.mybatis</groupId>
                    <artifactId>mybatis</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.mybatis</groupId>
                    <artifactId>mybatis-spring</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-boot-starter</artifactId>
            <version>3.0.0</version>
        </dependency>
        <!-- IJPay 让支付触手可及 -->
        <dependency>
            <groupId>com.github.javen205</groupId>
            <artifactId>IJPay-All</artifactId>
            <version>2.9.3</version>
        </dependency>
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
            <version>2.0.14</version>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.9</version>
        </dependency>

        <dependency>
            <groupId>com.jfinal</groupId>
            <artifactId>enjoy</artifactId>
            <version>${enjoy.version}</version>
        </dependency>
        <!-- 开源多维码生成工具 -->
        <dependency>
            <groupId>com.google.zxing</groupId>
            <artifactId>core</artifactId>
            <version>${zxing.version}</version>
        </dependency>
        <dependency>
            <groupId>com.google.zxing</groupId>
            <artifactId>javase</artifactId>
            <version>${zxing.version}</version>
        </dependency>

        <!-- 开源多维码生成工具 -->
        <dependency>
            <groupId>com.github.xkzhangsan</groupId>
            <artifactId>xk-time</artifactId>
            <version>${xk.time.version}</version>
        </dependency>
        <dependency>
            <groupId>com.alipay.sdk</groupId>
            <artifactId>alipay-sdk-java</artifactId>
            <version>${alipay.version}</version>
            <exclusions>
                <exclusion>
                    <artifactId>fastjson</artifactId>
                    <groupId>com.alibaba</groupId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.8.0-beta4</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.8.0-beta4</version>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>
        <dependency>
            <groupId>com.github.tobato</groupId>
            <artifactId>fastdfs-client</artifactId>
            <version>1.27.2</version>
        </dependency>

    </dependencies>

1.4、准备工作

提前下载好需要的软件
提前下载好需要的软件
  1. JDK下载地址
  2. Tomcat 用wget
  3. mysql-8.0.30-1.el7.x86_64.rpm-bundle.tar
  4. rabbitmq采用yum install
  5. fastdfs
代码语言:shell
复制
wget https://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-10/v10.1.7/bin/apache-tomcat-10.1.7.tar.gz --no-check-certificate

2、主要步骤

2.1、Centos7.9上JDK安装配置

  • 上传安装包到服务器
代码语言:shell
复制
scp -P 22 jdk-8u361-linux-x64.tar root@124.x.x.x:/root
  • 在服务器创建jdk目录,设置弹性云服务器安全组规则
代码语言:shell
复制
cd /root
mkdir jdk
mv jdk-8u361-linux-x64.tar ./jdk
cd jdk
tar -xvf jdk-8u361-linux-x64.tar
vi /etc/profile

//在底部添加以下内容
#set java environment
JAVA_HOME=/root/jdk/jdk1.8.0_361
JRE_HOME=$JAVA_HOME
PATH=$JAVA_HOME/bin:$PATH
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JRE_HOME/lib/tools.jar
export JAVA_HOME JRE_HOME PATH CLASSPATH

export JAVA_HOME=/root/jdk/jdk1.8.0_361
export JRE_HOME=$JAVA_HOME

//执行以下命令保存并退出。
:wq

//验证安装。
java -version

2.2、Centos7.9上Tomcat安装配置

代码语言:shell
复制
  398  2023-03-10 22:06:51 root cd tomcat
  399  2023-03-10 22:06:52 root ll
  400  2023-03-10 22:07:07 root tar -xvf apache-tomcat-10.1.7.tar.gz
  401  2023-03-10 22:07:11 root ll
  402  2023-03-10 22:07:24 root cd apache-tomcat-10.1.7
  403  2023-03-10 22:07:25 root ll
  404  2023-03-10 22:07:53 root cd bin
  405  2023-03-10 22:07:54 root ll
  406  2023-03-10 22:08:56 root vi setclasspath.sh
  407  2023-03-10 22:09:50 root ./startup.sh
  408  2023-03-10 22:10:07 root ps -ef|grep tomcat

  1. 执行如下命令,进入tomcat目录。cd /root/tomcat
  2. 解压tomcat安装包到tomcat目录下。tar -xvf apache-tomcat-10.1.7.tar.gz 例如:以v8.5.78版本安装包为例,执行以下命令。 tar -xvf apache-tomcat-10.1.7.tar.gz
  3. 进入tomcat的bin目录,执行以下命令安装tomcat。cd /root/tomcat/apache-tomcat-x.x.xx/ cd bin/ 例如:以v8.5.78版本安装包为例,执行以下命令。 cd /root/tomcat/apache-tomcat-10.1.7/ cd bin/
  4. 执行如下命令编辑setclasspath.sh脚本。vi setclasspath.sh 并在setclasspath.sh脚本底部添加以下内容。
  5. 执行如下命令保存后退出。:wq
  6. 可输入以下命令启动tomcat。./startup.sh
  7. 执行如下命令查看tomcat进程。ps -ef | grep tomcat 若返回如下图所示,表示tomcat启动成功。
代码语言:javascript
复制
#执行如下命令编辑setclasspath.sh脚本。
vi setclasspath.sh

#set java environment
JAVA_HOME=/root/jdk/jdk1.8.0_361
JRE_HOME=$JAVA_HOME
PATH=$JAVA_HOME/bin:$PATH
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JRE_HOME/lib/tools.jar
export JAVA_HOME JRE_HOME PATH CLASSPATH

export JAVA_HOME=/root/jdk/jdk1.8.0_361
export JRE_HOME=$JAVA_HOME

2.3、Centos7.9上MySql8.0.30安装配置

  • 上传安装包到服务器
  • 安装配置
代码语言:shell
复制
 704  2023-03-11 14:25:29 root mkdir mysqldb
  705  2023-03-11 14:25:30 root ll
  706  2023-03-11 14:25:40 root mv mysql-8.0.30-1.el7.x86_64.rpm-bundle.tar ./mysqldb
  707  2023-03-11 14:25:41 root ll
  708  2023-03-11 14:25:49 root cd mysqldb
  709  2023-03-11 14:25:50 root ll
  710  2023-03-11 14:26:21 root tar -xvf mysql-8.0.30-1.el7.x86_64.rpm-bundle.tar
  711  2023-03-11 14:26:36 root ll
  712  2023-03-11 14:27:12 root rpm -ivh mysql-community-common-8.0.30-l.e17.x86_64.rpm
  713  2023-03-11 14:27:18 root ll
  714  2023-03-11 14:28:01 root rpm -ivh mysql-community-common-8.0.30-1.el7.x86_64.rpm
  715  2023-03-11 14:28:34 root rpm ivh mysql-community-client-plugins-8.0.30-1.el7.x86_64.rpm
  716  2023-03-11 14:30:01 root rpm -ivh mysql-community-client-plugins-8.0.30-1.el7.x86_64.rpm
  717  2023-03-11 14:30:54 root rpm -ivh mysql-community-libs-8.0.30-1.el7.x86_64.rpm
  718  2023-03-11 14:32:06 root rpm -ivh mysql-community-client-8.0.30-1.el7.x86_64.rpm
  719  2023-03-11 14:32:27 root yum -y install openssl-devel
  720  2023-03-11 14:32:54 root rpm -ivh mysql-community-devel-8.0.30-1.el7.x86_64.rpm
  721  2023-03-11 14:33:03 root yum -y install libaio
  722  2023-03-11 14:33:29 root rpm -ivh mysql-community-server-8.0.30-1.el7.x86_64.rpm
  723  2023-03-11 14:34:40 root ll
  724  2023-03-11 14:34:56 root rpm -ivh mysql-community-icu-data-files-8.0.30-1.el7.x86_64.rpm
  725  2023-03-11 14:35:03 root rpm -ivh mysql-community-server-8.0.30-1.el7.x86_64.rpm
  726  2023-03-11 14:35:40 root yum -y install net-tools
  727  2023-03-11 14:36:00 root vim /etc/my.cnf
  728  2023-03-11 14:47:22 root mysqld --initialize --console
  729  2023-03-11 14:48:03 root chown -R mysql:mysql /var/lib/mysql/
  730  2023-03-11 14:48:16 root chmod -R 755 /var/lib/mysql
  731  2023-03-11 14:48:25 root systemctl start mysqld.service
  732  2023-03-11 14:48:43 root systemctl status mysqld.service
  733  2023-03-11 14:49:12 root cat /var/log/mysqld.log|grep localhost
  734  2023-03-11 14:49:30 root mysql -uroot -p
  735  2023-03-11 14:53:17 root systemctl restart mysqld.service
  736  2023-03-11 14:53:30 root systemctl enable mysqld
  737  2023-03-11 14:53:59 root systemctl start firewalld.service
  738  2023-03-11 14:54:10 root firewall-cmd --zone=public --add-port=3306/tcp --permanent
  739  2023-03-11 14:54:19 root systemctl restart firewalld.service
  740  2023-03-11 14:54:32 root firewall-cmd --list-port
  741  2023-03-11 15:17:58 root pwd
  742  2023-03-11 15:18:08 root mysql -uroot -p
  743  2023-03-11 16:02:00 root 12345678
  744  2023-03-11 16:02:02 root mysql -uroot -p
  745  2023-03-11 17:02:26 root pwd

经历了多次尝试,最后成功。

2.4、Centos7.9上RabbitMQ安装配置

  • 采用先下载Erlang、RabbitMQ安装包,再安装配置,多次失败
  • 后改用在线安装旧版本,成功。
  • 配置
代码语言:javascript
复制
  880  2023-03-11 19:21:42 root yum -y install rabbitmq-server
  881  2023-03-11 19:22:07 root systemctl enable rabbitmq-server.service
  882  2023-03-11 19:22:26 root systemctl start rabbitmq-server.service

  # 添加新用户
  884  2023-03-11 19:27:31 root rabbitmqctl add_user admin admin
  
  # 设置权限
  885  2023-03-11 19:28:06 root rabbitmqctl set_user_tags admin administrator
  886  2023-03-11 19:28:43 root rabbitmqctl set_permissions -p admin ".*" ".*" ".*"
  # 开启web端ui
  889  2023-03-11 19:30:43 root rabbitmq-plugins enable rabbitmq_management
  890  2023-03-11 19:32:01 root systemctl restart rabbitmq-server.service
  891  2023-03-11 19:32:36 root systemctl start rabbitmq-server.service
  892  2023-03-11 19:33:18 root service rabbitmq-server   status
  893  2023-03-11 19:33:53 root rabbitmqctl -version
  894  2023-03-11 19:34:33 root rabbitmqctl list_users
  895  2023-03-11 19:35:15 root lsof -i:5672
  #添加开启一个端口
  #firewall-cmd --zone=public --add-port=5672/tcp --permanent     
  #firewall-cmd --zone=public --add-port=15672/tcp --permanent  
  896  2023-03-11 19:36:35 root firewall-cmd --zone=public --add-port=15672/tcp --permanent
  897  2023-03-11 19:37:06 root firewall-cmd --zone=public --add-port=5672/tcp --permanent
  898  2023-03-11 19:37:40 root firewall-cmd --zone=public --list-ports
  
  systemctl restart rabbitmq-server.service
  
  899  2023-03-11 19:38:17 root iptables -L
  900  2023-03-11 19:45:09 root service rabbitmq-server status

2.5、Centos7.9上安装配置fastfds

https://cloud.tencent.com/developer/article/1520710?areaSource=103001.5&traceId=WmRTRSzkMuNFD9XN0lnYz

2.6、Centos7.9上SpringBoot jar包程序 后台运行

代码语言:shell
复制

### springboot jar 后台运行
nohup java -jar mgeids-boot.war >/dev/null  &  
查询到程序相应的PID
ps aux
利用kill PID杀到进程
kill 6759

3、收获

  • 遇到了很多问题,分析问题,解决问题。
  • 积累了经验
  • 测试环境搭建运行成功

4、不足

  • RabbitMQ版本比开发环境底,抽时间再优化。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 1、运行环境
    • 1.1、服务器环境
      • 1.2、本机环境
        • 1.3、Springboot版本及主要组件版本
          • 1.4、准备工作
          • 2、主要步骤
            • 2.1、Centos7.9上JDK安装配置
              • 2.2、Centos7.9上Tomcat安装配置
                • 2.3、Centos7.9上MySql8.0.30安装配置
                  • 2.4、Centos7.9上RabbitMQ安装配置
                    • 2.5、Centos7.9上安装配置fastfds
                      • 2.6、Centos7.9上SpringBoot jar包程序 后台运行
                      • 3、收获
                      • 4、不足
                      相关产品与服务
                      云服务器
                      云服务器(Cloud Virtual Machine,CVM)提供安全可靠的弹性计算服务。 您可以实时扩展或缩减计算资源,适应变化的业务需求,并只需按实际使用的资源计费。使用 CVM 可以极大降低您的软硬件采购成本,简化 IT 运维工作。
                      领券
                      问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档