springboot-vue-demo部署笔记

springboot-vue-demo部署

服务器配置

1核1G 10G内存 Centos7

环境

群里文档搬过来了

  • mysql

    • 下载安装包

      wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.33-linux-glibc2.12-x86_64.tar.gz
      
    • 解压

      tar -zxvf mysql-5.7.33-linux-glibc2.12-x86_64.tar.gz -C /user/local
      
    • 改名

      cd /usr/local
      mv mysql-5.7.33-linux-glibc2.12-x86_64 mysql
      
    • 创建用户和组

      groupadd mysql
      useradd -r -g mysql mysql
      chown -R mysql.mysql /usr/local/mysql
      
    • 创建data文件夹

      cd /usr/local/mysql
      mkdir data
      
    • 安装依赖包

      yum install libaio
      
    • 初始化 (记住初始密码)

      /usr/local/mysql/bin/mysqld --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data --initialize
      
    • 配置

      vim /etc/my.cnf
      

      配置文件:

      [mysqld]
      datadir=/usr/local/mysql/data
      basedir=/usr/local/mysql
      socket=/tmp/mysql.sock
      user=mysql
      port=3306
      character-set-server=utf8
      # 取消密码验证
      #skip-grant-tables
      # # Disabling symbolic-links is recommended to prevent assorted security risks
      symbolic-links=0
      [mysqld_safe]
      log-error=/var/log/mysqld.log
      pid-file=/var/run/mysqld/mysqld.pid
       
      
    • 将mysql加入到服务中

      cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
      
    • 开机启动

      chkconfig mysql on
      
    • 启动mysql

      service mysql start
      
    • 登录mysql

      /usr/local/mysql/bin/mysql -uroot -p
      
    • 设置权限

      # 进入mysql
      mysql> use mysql;
      mysql> update user set host ='%'where user ='root' and host ='localhost';
      mysql> flush privileges;
      

      设置完成远程客户端就可以访问了

    • 修改密码:

      set password for root@localhost = password('123456');
      
  • jdk

    • 官网下载压缩包,解压

      tar -zxvf jdk-8u291-linux-x64.tar.gz
      
    • 移动:

      mv jdk1.8.0_291 /usr/local/jdk1.8         
      
    • 修改配置文件:

      vim /etc/profile         
      
    • 添加配置:

      export JAVA_HOME=/usr/local/jdk1.8 export CLASSPATH=$:CLASSPATH:$JAVA_HOME/lib/ export PATH=$PATH:$JAVA_HOME/bin                 
      
    • 刷新配置:

      source /etc/profile             
      
  • nginx 反向代理

    • 安装依赖和相关库:

      [root@localhost ~]# yum -y install gcc-c++ zlib-devel openssl-devel libtool
      
    • 下载nginx安装包并解压:

      [root@localhost ~]# cd /usr/local
      [root@localhost local]# wget http://nginx.org/download/nginx-1.14.0.tar.gz
      [root@localhost local]# tar -zxvf nginx-1.14.0.tar.gz
      
    • 配置和安装

      [root@localhost local]# cd nginx-1.14.0
      [root@localhost nginx-1.14.0]# ./configure --prefix=/usr/local/nginx
      [root@localhost nginx-1.14.0]# make && make install
      
    • 启动nginx:

      [root@localhost nginx-1.14.0]# cd ../nginx/sbin
      [root@localhost sbin]# ./nginx
      
    • 查看nginx:

      [root@localhost nginx]# ps -ef | grep nginx
      root      13850      1  0 17:01 ?        00:00:00 nginx: master process ./nginx
      nobody    13851  13850  0 17:01 ?        00:00:00 nginx: worker process
      root      13879   1128  0 17:11 pts/0    00:00:00 grep --color=auto nginx
      
    • 停止和重启nginx:

      ./nginx -s reload   #重启
      ./nginx -s stop #关闭
      

vue

  • 修改一些配置(服务器不应写死ip)

    • /public/static/config.js(已有)

      window.server = {
          filesUploadUrl: "localhost"
      }
      
    • 文件上传

      • Book.vue(已修改)

      • Person.vue(注意action前面加:,以下相同)

        springboot-vue-demo部署笔记

        springboot-vue-demo部署笔记

    • 用户excel导入导出

      • User.vue

        springboot-vue-demo部署笔记

        springboot-vue-demo部署笔记

        springboot-vue-demo部署笔记

    • 富文本

      • News.vue

        springboot-vue-demo部署笔记

  • npm install #安装库
    
  • npm run build #打包得到dist文件夹
    
  • 将自己服务器ip配置到dist/static/config.js代替localhost

  • nginx 反向代理 dist

Nginx

  • /conf/nginx.conf 修改配置

    springboot-vue-demo部署笔记

  • 重启

    nginx -s reload
    

springboot

  • 修改配置文件application.properties

    我的写法是这样,将基本配置迁入dev,服务器配置迁入prod,主配置文件选择prod。

    springboot-vue-demo部署笔记

    springboot-vue-demo部署笔记

    spring.datasource.url=jdbc:mysql://47.93.254.136:3306/springboot-vue?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false&serverTimezone=GMT%2b8
    spring.datasource.username=root
    spring.datasource.password=root
    
    file.ip=47.93.254.136 
    # prod重点是文件上传ip 和数据库配置,其他无需改变
    
  • 添加了security后不允许//

    The request was rejected because the URL contained a potentially malicious String "//"

    添加如下代码到SecurityConfig

    @Bean
        public HttpFirewall allowUrlEncodedSlashHttpFirewall() {
            StrictHttpFirewall firewall = new StrictHttpFirewall();
            firewall.setAllowUrlEncodedDoubleSlash(true);
            return firewall;
        }
    
  • maven 生命周期 clean compile package 得到 springboot-0.0.1-SNAPSHOT.jar

  • nohup java -jar springboot-0.0.1-SNAPSHOT.jar & #后台启动,主配置文件已经指定prod我就没有添加指定参数
    
  • tail -f nohup.out #查看后台
    

Mysql

  • 使用navicat远程连接,创建相应数据库,导入数据表sql文件

成功

springboot-vue-demo部署笔记

上一篇:Java Servlet总结


下一篇:阿里云配置Nginx访问(docker部署)