Spring Boot项目部署到Ubuntu

常用命令

sudo netstat -an|grep -e 3306 
sudo netstat -tap | grep mysql	#是否安装成功

一、安装MySQL

sudo apt-get install mysql-server
sudo netstat -tap | grep mysql

二、出现的问题

0、改密码

sudo cat /etc/mysql/debian.cnf
mysql -u debian-sys-maint -p
use mysql;
update user set authentication_string=password('root') where user='root' and Host ='localhost';
update user set plugin="mysql_native_password";
flush privileges;
quit;
sudo service mysql restart

mysql -u root -p // 启动后输入已经修改好的密码:root

1、mysql出现ERROR1698(28000):Access denied for user root@localhost错误解决方法

  1. 修改
sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
  1. 在[mysqld]中加入skip-grant-tables,之后重启mysql。
skip-grant-tables
/etc/init.d/mysql restart
  1. mysql -uroot -p,如果提示输入密码直接回车即可。进入mysqmysqll后执行:
use mysql;

select user,plugin from user;

# update user set authentication_string=password('root') where user='root' and Host ='localhost';

# GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'iflytek' WITH GRANT OPTION;

update user set authentication_string=password("123456"),plugin='mysql_native_password' where user='root';

flush privileges;
  1. 退出mysql,在/etc/mysql/mysql.conf.d/mysqld.cnf中删除skip-grant-tables,之后重启mysql即可进入。
  2. select user,plugin from user;
update user set authentication_string=password("123456"),plugin='mysql_native_password' where user='root';
启动
sudo service mysql start
sudo service mysql restart
sudo netstat -tap | grep mysql
登录
mysql -uroot -proot
重启mysql
/etc/init.d/mysql restart
检查mysql是不是在运行
sudo service mysql status
sudo netstat -tap | grep mysql  	查看mysql是否启动
#dsk@DSK:~$ sudo netstat -tap | grep mysql
#tcp6       0      0 [::]:mysql              [::]:*                  LISTEN      255100/mysqld
卸载:

首先在终端中查看MySQL的依赖项:

dpkg --list|grep mysql

卸载:

sudo apt-get autoremove --purge mysql-server-5.7

清除残留数据:

dpkg -l|grep ^rc|awk '{print$2}'|sudo xargs dpkg -P

再次查看MySQL的剩余依赖项:

dpkg --list|grep mysql

继续删除剩余依赖项,如:

sudo apt-get autoremove --purge mysql-apt-config
sudo apt purge mysql-*
sudo rm -rf /etc/mysql/ /var/lib/mysql
sudo apt autoremove

三、创建数据库

create database shared_device; 
use shared_device; 
source ./shared_device.sql

四、运行jar包

java -jar jar包名。
sudo fuser -v 8080/tcp			//查看8080端口进程

五、开启MySQL数据库远程访问权限

1、打开mysql配置文件

vi /etc/mysql/mysql.conf.d/mysqld.cnf
# 将bind-address = 127.0.0.1注销

2、修改数据库属性

mysql -uroot -p123456
mysql>use mysql; 
mysql>update user set host = '%' where user = 'root'; 
mysql>select host, user from user;
mysql>flush privileges;

Springboot部署到Ubuntu后MySql链接失败的问题

2020-11-19 17:30:50.420  INFO 349165 --- [           main] cn.smxy.MainApplication                  : Started MainApplication in 3.37 seconds (JVM running for 3.718)
2020-11-19 17:30:53.418  INFO 349165 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring DispatcherServlet 'dispatcherServlet'
2020-11-19 17:30:53.418  INFO 349165 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Initializing Servlet 'dispatcherServlet'
2020-11-19 17:30:53.424  INFO 349165 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Completed initialization in 6 ms
2020-11-19 17:31:00.896  INFO 349165 --- [nio-8080-exec-1] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
Thu Nov 19 17:31:01 CST 2020 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
2020-11-19 17:31:01.100 ERROR 349165 --- [nio-8080-exec-1] com.zaxxer.hikari.pool.HikariPool        : HikariPool-1 - Exception during pool initialization.

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

The last packet successfully received from the server was 86 milliseconds ago.  The last packet sent successfully to the server was 81 milliseconds ago.

第6行是关键

是Mysql数据库的SSL连接问题,提示警告不建议使用没有带服务器身份验证的SSL连接,是在MYSQL5.5.45+, 5.6.26+ and 5.7.6+版本中才有的这个问题。解决办法在警告中已经说明了:

1、SpringBoot启动报错:HikariPool-1 - Exception during pool initialization.

1、mysql-connector-java

由于springboot自带 mysql-connector-java版本过高,导致连接失败,最终导致连接池启动失败。
降低mysql-connector-java的版本。

<dependency>
	<groupId>mysql</groupId>
	<artifactId>mysql-connector-java</artifactId>
	<version>5.1.40</version>
	<scope>runtime</scope>
</dependency>

**2、在数据库连接的url中添加useSSL=false;*****2.url中添加useSSL=true,并且提供服务器的验证证书。**如果只是做一个测试的话,没必要搞证书那么麻烦啦,在连接后添加一个useSSL=false即可,例如:

url: jdbc:mysql://localhost:3306/myspringbootdatabase?useSSL=false

Vue项目部署到Nginx

一、安装依赖库

#更新源
sudo apt-get update
#安装c++依赖库
sudo apt-get install build-essential
sudo apt-get install libtool
#安装openssl依赖库
sudo apt-get install openssl
#安装pcre依赖库
sudo apt-get install libpcre3 libpcre3-dev
#安装zlib依赖库
sudo apt-get install zlib1g-dev

二、编译安装Nginx

下载nginx 1.1版本

wget http://nginx.org/download/nginx-1.11.3.tar.gz

解压并进入目录

tar -zxvf nginx-1.11.3.tar.gz

cd nginx-1.11.3

配置,将nginx安装到/usr/local/ngnix目录

./configure --prefix=/usr/local/nginx

编译

make
出现错误

问题描述

在Ubuntu18.04上安装Ngnix,在编译步骤出现如下错误:

cc1: all warnings being treated as errors
objs/Makefile:460: recipe for target ‘objs/src/core/ngx_murmurhash.o’ failed
make[1]: *** [objs/src/core/ngx_murmurhash.o] Error 1
make[1]: Leaving directory ‘/home/wzj/tools/nginx/nginx-1.11.3’
Makefile:8: recipe for target ‘build’ failed
make: *** [build] Error 2
解决办法
找到对应的Maakefile文件,将gcc参数中的-Werror去掉。

我上面显示的是objs/Makefile文件,我打开看了下,将第三行的-Werror去掉就可以

mysql Ubuntu springboot驱动 ubuntu部署springboot_nginx

安装

make install

三、测试是否安装成功

1. 执行下面命令启动nginx(root用户执行)

/usr/local/nginx/sbin/nginx

2.查看是否有nginx进程启动,有进程启动,说明安装成功了

ps -ef | grep nginx

四、Nginx常用命令

1.启动服务

/usr/local/nginx/sbin/nginx

2.停止服务

/usr/local/nginx/sbin/nginx  -s stop

3.重新加载配置

/usr/local/nginx/sbin/nginx  -s reload

4.测试配置文件是否正确

/usr/local/nginx/sbin/nginx -t

五 、路径配置

Vue项目目录

#配置到根目录下(root用户下cd ..)
mkdir var/
cd var/
mkdir www/
cd www/
mkdir VueProject/
cp -r ~/dist/ .			#复制到当前目录

修改nginx配置文件

配置文件为conf下的nginx.conf,修改nginx.conf中的server配置片段

#按照以上安装设置,其路径为
/usr/local/nginx/conf

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-D3VzfCXG-1616206067763)(D:\MyDocument\Study Note\搭建服务器\Vue部署到Nginx-1.png)]

/usr/local/nginx/sbin/nginx 			#启动服务
/usr/local/nginx/sbin/nginx  -s stop	#停止服务
ps -ef | grep nginx						#查看进程
sudo /usr/sbin/nginx 					#启动服务
 sudo /usr/sbin/nginx  -s stop

配置文件为conf下的nginx.conf,修改nginx.conf中的server配置片段

#按照以上安装设置,其路径为
/usr/local/nginx/conf

[外链图片转存中…(img-D3VzfCXG-1616206067763)]

/usr/local/nginx/sbin/nginx 			#启动服务
/usr/local/nginx/sbin/nginx  -s stop	#停止服务
ps -ef | grep nginx						#查看进程
sudo /usr/sbin/nginx 					#启动服务
 sudo /usr/sbin/nginx  -s stop