在ubuntu上部署ssm web项目

在ubuntu上部署ssm web项目

安装mysql

sudo apt-get install mysql-server
sudo apt-get install mysql-common
sudo apt-get install mysql-client

实现远程链接服务器上的MySQL数据库

在阿里云中添加安全组

开放3306、80端口

初始化MySQL(MySQL 5.7并未设置默认密码,需要初始化,即运行安全向导)

sudo mysql_secure_installation

安全向导:

1.(是否设置随机密码,Y/y随机密码, N/n自己输入密码)

VALIDATE PASSWORD PLUGIN can be used to test passwords...
Press y|Y for Yes, any other key for No: N (我的选项)
Please set the password for root here...
New password: (输入密码)
Re-enter new password: (重复输入)

2.(是否删除匿名用户,建议删除)

By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them...
Remove anonymous users? (Press y|Y for Yes, any other key for No)

3.(是否禁止root账户远程登陆,建议禁止)

Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network...
Disallow root login remotely? (Press y|Y for Yes, any other key for No)

4.(是否删除test数据库,建议删除)

By default, MySQL comes with a database named 'test' that
anyone can access...
Remove test database and access to it? (Press y|Y for Yes, any other key for No)

5.(是否重新加载权限表,应该重新加载)

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
Reload privilege tables now? (Press y|Y for Yes, any other key for No) :

修改配置文件

将bind-address改为*0.0.0.0

sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf

使用CTRL+X

存并退出 nano 编辑器

  • 重启mysql服务
sudo systemctl restart mysql

将用作远程登录的账号host改为任意主机或固定ip

添加所有IP都可以访问的用户:

grant all privilege on *.* to '用户名'@'%' identified by '密码' with grant option;

或者也可以给root用户设置为所有ip都可访问:

update user set host='%' where user='root' and host='localhost';

刷新权限:

flush privileges;

查看用户权限:

select host,user from user; 

本地数据库迁移(可能出现编码问题)

服务器安装JDK

  • 通过xshell传输jdk到 usr/local/目录下

  • 解压jdk

    tar -zxvf jdk-15.0.2_linux-x64_bin.tar.gz
    
  • 删除jdk压缩包

    rm -f jdk-15.0.2_linux-x64_bin.tar.gz
    
  • 将jdk配置到/etc/profile

    vim /etc/profile
    
    • i进入编辑, 在文件尾部添加

      • jdk11以上没有jre
      JAVA_HOME=/usr/local/jdk-15.0.2CLASSPATH=.:${JAVA_HOME}/bin.tools.jarPATH=${JAVA_HOME}/bin:${PATH}export JAVA_HOME CLASSPATH PATHexport JRE_HOME=${JAVA_HOME}
      
      • jdk11以下
      export JAVA_HOME=/usr/local/jdk-15.0.2export JRE_HOME=${JAVA_HOME}/jreexport CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib:${JAVA_HOME}export JAVA_PATH=${JAVA_HOME}/bin:${JRE_HOME}/binexport PATH=$PATH:${JAVA_PATH}
      
    • esc-->:wq保存并退出

  • javac/java -version测试是否安装成功

安装tomcat

  • 通过xshell传输tomcat到 usr/local/目录下

  • 解压jdk

    tar -zxvf apache-tomcat-8.5.73.tar
    
  • 删除jdk压缩包

    rm -f apache-tomcat-8.5.73.tar
    
  • 重命名

    mv apache-tomcat-8.5.73.tar tomcat8
    
  • 将jdk配置到/etc/profile

    vim /etc/profile
    

部署web

  • 将war包放入/usr/local/tomcat8/webapps/目录下

启动tomcat服务器

  • 通过/usr/local/tomcat8/bin/startup.sh启动tomcat服务器
  • 通过/usr/local/tomcat8/bin/startup.sh关闭服务器
  • 已经将端口号改为80

问题

  • localhost无法访问MySQL : 可能是mysql版本升级 密码格式改变,需要设置成mysql native_password

  • 表单中文提交乱码: 数据库编码格式有误

    • 进入数据库查询当前编码格式:

      show variables like '%character%';
      

    • 更改默认编码:

      vi /etc/mysql/mysql.conf.d/mysqld.cnf
      

      添加编码格式:

    • 重启数据库

      systemctl restart mysql
      
    • 查询当前编码格式:

posted @ 2022-01-02 22:28  霹雳猪猪  阅读(117)  评论(0)    收藏  举报