linux

将IDEA开发的java web项目移植到腾讯云服务器

一、Ubuntu 更换国内源

1.备份原来源

ubuntu@VM-16-7-ubuntu:~$ sudo cp /etc/apt/sources.list /etc/apt/sources_init.list

2.先卸载 gedit并且重新安装gedit

ubuntu@VM-16-7-ubuntu:~$ sudo apt-get remove gedit

ubuntu@VM-16-7-ubuntu:~$ sudo apt-get install gedit

3.修改源

ubuntu@VM-16-7-ubuntu:~$ sudo vim /etc/apt/sources.list
deb http://mirrors.tencentyun.com/ubuntu/ focal main restricted universe multiverse
deb http://mirrors.tencentyun.com/ubuntu/ focal-security main restricted universe multiverse
deb http://mirrors.tencentyun.com/ubuntu/ focal-updates main restricted universe multiverse
#deb http://mirrors.tencentyun.com/ubuntu/ focal-proposed main restricted universe multiverse
#deb http://mirrors.tencentyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src http://mirrors.tencentyun.com/ubuntu/ focal main restricted universe multiverse
deb-src http://mirrors.tencentyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src http://mirrors.tencentyun.com/ubuntu/ focal-updates main restricted universe multiverse
#deb-src http://mirrors.tencentyun.com/ubuntu/ focal-proposed main restricted universe multiverse
#deb-src http://mirrors.tencentyun.com/ubuntu/ focal-backports main restricted universe multiverse

二、Ubuntu 20.04 LTS(64bits)安装 Oracle JDK-17

1.Ubuntu下安装lrzsz工具,方便windows和linux间的文件上传下载

ubuntu@VM-16-7-ubuntu:~$ sudo apt-get install lrzsz

2.rz命令将本地上传文件到服务器

下载.tar.gz文件:https://www.oracle.com/java/technologies/downloads/
ubuntu@VM-16-7-ubuntu:~$ cd /opt/
ubuntu@VM-16-7-ubuntu:~$ sudo su
root@VM-16-7-ubuntu:/opt$ rz 
root@VM-16-7-ubuntu:/opt$ ls
jdk-17_linux-x64_bin.tar.gz

3.解压缩jdk

ubuntu@VM-16-7-ubuntu:/opt$ sudo tar -xzvf jdk-17_linux-x64_bin.tar.gz 
ubuntu@VM-16-7-ubuntu:/opt$ ls
jdk-17.0.2  jdk-17_linux-x64_bin.tar.gz

4.环境变量配置

ubuntu@VM-16-7-ubuntu:/opt$ sudo vi /etc/profile

JAVA_HOME=/opt/jdk-17.0.2
CLASSPATH=.
PATH=$JAVA_HOME/bin:$PATH
export JAVA_HOME CLASSPATH PATH


ubuntu@VM-16-7-ubuntu:/opt$ source /etc/profile
ubuntu@VM-16-7-ubuntu:/opt$ java -version
java version "17.0.2" 2022-01-18 LTS
Java(TM) SE Runtime Environment (build 17.0.2+8-LTS-86)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.2+8-LTS-86, mixed mode, sharing)

三、安装tomcat

1.rz命令将本地Tomcat上传到服务器

下载.tar.gz文件:https://tomcat.apache.org/download-80.cgi
ubuntu@VM-16-7-ubuntu:~$ cd /opt/
ubuntu@VM-16-7-ubuntu:~$ sudo su
root@VM-16-7-ubuntu:/home/ubuntu# ls
root@VM-16-7-ubuntu:/opt$ rz 
root@VM-16-7-ubuntu:/opt# ls
apache-tomcat-8.5.60.tar.gz  jdk-17.0.2  jdk-17_linux-x64_bin.tar.gz

2.解压

root@VM-16-7-ubuntu:/opt# sudo tar -xzvf apache-tomcat-8.5.60.tar.gz 

3.环境变量

root@VM-16-7-ubuntu:/opt/apache-tomcat-8.5.60# cd bin/
root@VM-16-7-ubuntu:/opt/apache-tomcat-8.5.60/bin# ls
bootstrap.jar       ciphers.sh                    daemon.sh         shutdown.bat     tomcat-native.tar.gz
catalina.bat        commons-daemon.jar            digest.bat        shutdown.sh      tool-wrapper.bat
catalina.sh         commons-daemon-native.tar.gz  digest.sh         startup.bat      tool-wrapper.sh
catalina-tasks.xml  configtest.bat                setclasspath.bat  startup.sh       version.bat
ciphers.bat         configtest.sh                 setclasspath.sh   tomcat-juli.jar  version.sh
root@VM-16-7-ubuntu:/opt/apache-tomcat-8.5.60/bin# sudo vim startup.sh 
JAVA_HOME=/opt/jdk-17.0.2
CLASSPATH=.
PATH=$JAVA_HOME/bin:$PATH
export JAVA_HOME CLASSPATH PATH

export TOMCAT_HOME=/opt/apache-tomcat-8.5.60
root@VM-16-7-ubuntu:/opt/apache-tomcat-8.5.60/bin# sudo vim shutdown.sh 
JAVA_HOME=/opt/jdk-17.0.2
CLASSPATH=.
PATH=$JAVA_HOME/bin:$PATH
export JAVA_HOME CLASSPATH PATH

export TOMCAT_HOME=/opt/apache-tomcat-8.5.60

exec "$PRGDIR"/"$EXECUTABLE" stop -force "$@"

4.启动服务

root@VM-16-7-ubuntu:/opt/apache-tomcat-8.5.60/bin# ./startup.sh

5.访问

服务器公网ip:8080

6.关闭服务

root@VM-16-7-ubuntu:/opt/apache-tomcat-8.5.60/bin# ./shutdown.sh 

四、安全mysql数据库

1.先退出root用户,切换到ubuntu用户

root@VM-16-7-ubuntu:su ubuntu
ubuntu@VM-16-7-ubuntu:cd ~

2.安装mysql

ubuntu@VM-16-7-ubuntu:sudo apt-get install mysql-server

3.查看是否安装成功

ubuntu@VM-16-7-ubuntu:systemctl status mysql
#出现下面表示成功
 mysql.service - MySQL Community Server
     Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
     Active: active (running) since Thu 2022-03-03 11:08:42 CST; 4min 32s ago
   Main PID: 17930 (mysqld)
     Status: "Server is operational"
      Tasks: 37 (limit: 4603)
     Memory: 358.0M
     CGroup: /system.slice/mysql.service
             └─17930 /usr/sbin/mysqld

Mar 03 11:08:41 VM-16-7-ubuntu systemd[1]: Starting MySQL Community Server...
Mar 03 11:08:42 VM-16-7-ubuntu systemd[1]: Started MySQL Community Server.

4.查看账号信息

ubuntu@VM-16-7-ubuntu:~$ sudo cat /etc/mysql/debian.cnf

# Automatically generated for Debian scripts. DO NOT TOUCH!
[client]
host     = localhost
user     = debian-sys-maint
password = 9nnZkp7lBkq81MK6
socket   = /var/run/mysqld/mysqld.sock
[mysql_upgrade]
host     = localhost
user     = debian-sys-maint
password = 9nnZkp7lBkq81MK6
socket   = /var/run/mysqld/mysqld.sock

5.修改密码

ubuntu@VM-16-7-ubuntu:~$ sudo mysql -u root -p 
Enter password: 

mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root密码';
Query OK, 0 rows affected (0.01 sec)

参考:https://blog.csdn.net/skh2015java/article/details/80156278

6.将sql文件导入到服务器的mysql数据库

ubuntu@VM-16-7-ubuntu:~$ sudo su
root@VM-16-7-ubuntu:/home/ubuntu# ls
root@VM-16-7-ubuntu:/home/ubuntu# mkdir sql_documents
root@VM-16-7-ubuntu:/home/ubuntu# ls
sql_documents
root@VM-16-7-ubuntu:/home/ubuntu# cd sql_documents/
root@VM-16-7-ubuntu:/home/ubuntu/sql_documents# ls
root@VM-16-7-ubuntu:/home/ubuntu/sql_documents# rz
root@VM-16-7-ubuntu:/home/ubuntu/sql_documents# ls
UITIN.sql
root@VM-16-7-ubuntu:/home/ubuntu/sql_documents# mysql -uroot -p
mysql> create database UITIN;
Query OK, 1 row affected (0.01 sec)

mysql> use UITIN;
Database changed

mysql> source /home/ubuntu/sql_documents/UITIN.sql;

mysql> show tables;
+-----------------+
| Tables_in_uitin |
+-----------------+
| article         |
| first_title     |
| message         |
| user            |
| user_ability    |
+-----------------+
5 rows in set (0.00 sec)

mysql> 

五、将war上传运行java项目

1.将idea项目打包war

网上很多教程就不介绍了

2.将war文件上传到服务器

root@VM-16-7-ubuntu:/home/ubuntu/sql_documents# sudo su
root@VM-16-7-ubuntu:/home/ubuntu/sql_documents# cd /opt/
root@VM-16-7-ubuntu:/opt# ls
apache-tomcat-8.5.60  apache-tomcat-8.5.60.tar.gz  jdk-17.0.2  jdk-17_linux-x64_bin.tar.gz
root@VM-16-7-ubuntu:/opt# cd apache-tomcat-8.5.60
root@VM-16-7-ubuntu:/opt/apache-tomcat-8.5.60# ls
bin  BUILDING.txt  conf  CONTRIBUTING.md  lib  LICENSE  logs  NOTICE  README.md  RELEASE-NOTES  RUNNING.txt  temp  webapps  work
root@VM-16-7-ubuntu:/opt/apache-tomcat-8.5.60# cd bin/
root@VM-16-7-ubuntu:/opt/apache-tomcat-8.5.60/bin# ls

root@VM-16-7-ubuntu:/opt/apache-tomcat-8.5.60/bin# ./shutdown.sh

root@VM-16-7-ubuntu:/opt/apache-tomcat-8.5.60/bin# ./startup.sh

root@VM-16-7-ubuntu:/opt/apache-tomcat-8.5.60/bin# cd ..
root@VM-16-7-ubuntu:/opt/apache-tomcat-8.5.60# ls
bin  BUILDING.txt  conf  CONTRIBUTING.md  lib  LICENSE  logs  NOTICE  README.md  RELEASE-NOTES  RUNNING.txt  temp  webapps  work
root@VM-16-7-ubuntu:/opt/apache-tomcat-8.5.60# cd webapps/
root@VM-16-7-ubuntu:/opt/apache-tomcat-8.5.60/webapps# ls
docs  examples  host-manager  manager  ROOT

#上传打包好的java的war文件
root@VM-16-7-ubuntu:/opt/apache-tomcat-8.5.60/webapps# rz

参考:https://blog.csdn.net/weixin_38468077/article/details/102610671

3.公网ip地址:8080/项目路径访问

http://124.221.147.35:8080/cx1/
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值