1.Linux优势
1.开源免费
2.稳定(相比于其他的操作系统,linux可以稳定运行很多年)
3.`安全
4.社区支持
总之,linux还有很多优势
2.Linux环境搭建
2.1使用云服务器
搭建Linux环境我们 一般使用云服务器.我们将项目部署在云服务器上之后就可以直接被外网访问到了.也就是让我们自己写的程序能给别人去使用.
1.首先我们可以去阿里云或者腾讯云申请一个服务器,这里我使用的是Ubuntu 22.04LTS
2025主会场_智惠采购季 就上阿里云-阿里云采购季https://www.aliyun.com/activity/purchase/purchasing?utm_content=se_1020449845申请云服务器后我们要确认下是否有外网IP.
此时我们就相当于有了一台Linux系统的电脑,申请完服务器之后我们要使用终端软件来连接Linux服务器
2.2使用终端软件(XSHELL)
使用终端软件来连接我们的主机
1.先和主机建立连接
2. 填写账号密码
3.连接成功
3.Linux常用命令
3.1 ls
语法: ls [选项] [目录或者文件]
功能:对于目录,这个命令是列出这个目录下的所有子目录或文件.对于文件,将列出文件名以及其他信息
3.2pwd
功能:显示当前用户所在目录
3.3 cd
语法: cd [目录名]
功能:可以跳转到指定的目录下面
//返回上级目录
cd ..
//进入用户目录
cd ~
//返回最近访问目录
cd -
⼏个特殊的⽬录:•/ 称为根⽬录•. 称为当前⽬录•.. 称为当前⽬录的上级⽬录
3.4 touch
语法:touch [文件名]
功能:可以创建一个文件,也可以对文件进行时间修改
表示在temp目录下创建了一个text.txt文件
3.5 cat
语法:cat [文件名]
功能:查看文件内的内容
3.6 mkdir
语法:mkdir [目录名]
功能:创建一个目录[文件夹].
3.7 vim
语法 vim [文件名]
功能:用于编辑文件内容
输入指令后我们进入这个页面.此时我们需要按一下 i 键,下方出现INSERT就可以开始编辑了
输入完文本后我们需要 按下ESC键,然后在--INSERT--位置输入 :wq 就可以保存退出了
但是如果我们写完不想保存 可以点击ESC键后输入 :q! 就完成了退出
此时我们设置的值并没有出现
3.8 grep
语法: grep[参数] [文件名]
功能:用于查找文件中是否包含参数中的字符串,包含返回所有包含的行.
-n<⾏数> 显⽰的⾏数-w 全字匹配. 要求整个单词都完全相同的结果才能匹配出来, ⽽不仅仅是⼀个单词的⼀部分.-r 递归查找. 可以搜索多级⽬录下的所有⽂件.--color ⾼亮查找到的结果--include 指定查找某些⽂件--exclude 指定排除某些⽂件
3.9 ps
语法:ps[参数]
功能:用于查看当前系统的进程
a 显⽰⼀个终端的所有进程u 以⽤⼾为主的格式来显⽰程序状况x 显⽰所有程序, 不⽌是会话中的进程e 显⽰所有进程, 包括系统守护进程f 显⽰完整格式输出
3.10 netstat
语法:netstat[参数]
功能:查看系统上网络的状态
a 显⽰所有正在或不在侦听的套接字-n 显⽰数字形式地址⽽不是去解析主机、端⼝或⽤⼾名-p 显⽰套接字所属进程的PID和名称
3.11管道
管道是将前⼀个指令标准输出的内容, 作为第⼆个指令的标准输⼊内容. 在Linux中用 | 表示
常见的指令就介绍到这里,还有很多指令这里就不多介绍了,有需要的话查询下就可以了
4.搭建Java部署环境
4.1 apt
是一个Linux的软件包管理工具.类似于我们手机上的应用商店一样.

4.1.1 列出所有软件包
apt list
由于软件包会很多,所以一般搭配一些筛选指令使用 比如 apt list | grep 'java'
4.1.2 更新软件包数据库
sudo apt-get update
4.1.3 安装软件包
apt install '软件包名'
4.1.4 移除软件包
apt remove package_name
4.2 JDK
4.2.1 更新软件包
apt-get update
ubuntu@VM-24-3-ubuntu:~$ sudo apt-get update #更新软件包Hit:1 http://mirrors.tencentyun.com/ubuntu jammy InReleaseHit:2 http://mirrors.tencentyun.com/ubuntu jammy-updates InReleaseHit:3 http://mirrors.tencentyun.com/ubuntu jammy-security InReleaseReading package lists... Done
4.2.2安装 openjdk
# 查找 jdk 包apt list |grep "jdk"# 安装 jdksudo apt install openjdk-8-jdk 不是绝对的,可以安装jdk17或者其他版本
执行的结果
root@bite:~# apt list |grep "jdk" #查找jdkopenjdk-8-doc/focal-updates,focal-updates,focal-security,focal-security 8u382-gaopenjdk-8-jdk-headless/focal-updates,focal-security,now 8u382-ga-1~20.04.1 amd64openjdk-8-jdk-headless/focal-updates,focal-security 8u382-ga-1~20.04.1 i386openjdk-8-jdk/focal-updates,focal-security,now 8u382-ga-1~20.04.1 amd64 [installopenjdk-8-jdk/focal-updates,focal-security 8u382-ga-1~20.04.1 i386openjdk-8-jre-headless/focal-updates,focal-security,now 8u382-ga-1~20.04.1 amd64openjdk-8-jre-headless/focal-updates,focal-security 8u382-ga-1~20.04.1 i386openjdk-8-jre-zero/focal-updates,focal-security 8u382-ga-1~20.04.1 amd64openjdk-8-jre-zero/focal-updates,focal-security 8u382-ga-1~20.04.1 i386openjdk-8-jre/focal-updates,focal-security,now 8u382-ga-1~20.04.1 amd64 [installopenjdk-8-jre/focal-updates,focal-security 8u382-ga-1~20.04.1 i386openjdk-8-source/focal-updates,focal-updates,focal-security,focal-security 8u382ubuntu@VM-24-3-ubuntu:~$ sudo apt install openjdk-8-jdk #输⼊安装命令Reading package lists... DoneBuilding dependency tree... DoneReading state information... Done...0 upgraded, 126 newly installed, 0 to remove and 154 not upgraded.Need to get 102 MB of archives.After this operation, 400 MB of additional disk space will be used.Do you want to continue? [Y/n] Y #输⼊Y继续下⼀步...done.done.Processing triggers for libglib2.0-0:amd64 (2.72.4-0ubuntu2.2) ...Processing triggers for libc-bin (2.35-0ubuntu3.4) ...Setting up at-spi2-core (2.44.0-3) ...Processing triggers for libgdk-pixbuf-2.0-0:amd64 (2.42.8+dfsg-1ubuntu0.2) ...
使用java -version验证是否安装成功
4.3 安装MySQL
# 查找安装包apt list |grep "mysql-server"
# 安装 mysqlsudo apt install mysql-server
执行结果:
root@bite:~# apt list |grep "mysql-server" #查找mysql的安装包
WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
default-mysql-server-core/focal,focal 1.0.5ubuntu2 all
default-mysql-server/focal,focal 1.0.5ubuntu2 all
mysql-server-8.0/focal-updates,focal-security 8.0.35-0ubuntu0.20.04.1 amd64
mysql-server-8.0/focal-updates,focal-security 8.0.35-0ubuntu0.20.04.1 i386
mysql-server-core-8.0/focal-updates,focal-security 8.0.35-0ubuntu0.20.04.1
amd64
mysql-server-core-8.0/focal-updates,focal-security 8.0.35-0ubuntu0.20.04.1 i386
mysql-server/focal-updates,focal-updates,focal-security,focal-security 8.0.35-
0ubuntu0.20.04.1 all
ubuntu@VM-24-3-ubuntu:~$ sudo apt install mysql-server #输⼊安装命令
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
...
After this operation, 243 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y #输⼊Y确认
emitting matrix : 100% |###########################################|
done!
update-alternatives: using /var/lib/mecab/dic/ipadic-utf8 to provide
/var/lib/mecab/dic/debian (mecab-dictionary) in auto mode
Setting up libhtml-parser-perl:amd64 (3.76-1build2) ...
Setting up libhttp-message-perl (6.36-1) ...
Setting up mysql-server (8.0.35-0ubuntu0.22.04.1) ...
Setting up libcgi-pm-perl (4.54-1) ...
Setting up libhtml-template-perl (2.97-1.1) ...
Setting up libcgi-fast-perl (1:2.15-1) ...
Processing triggers for man-db (2.10.2-1) ...
Processing triggers for libc-bin (2.35-0ubuntu3.4) ...
查看登录SQL状态
systemctl status mysql
MySQL 安全配置
mysql_secure_installation
MySQL 安装提供了⼀个安全脚本, ⽤于解决不太安全的默认选项,运行这个命令
root@hcss-ecs-0bb1:~# sudo mysql_secure_installation #安装安全设置
Securing the MySQL server deployment.
Connecting to MySQL using a blank password.
VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?
Press y|Y for Yes, any other key for No: Y #是否设置验证密码组件
There are three levels of password validation policy:
LOW Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary
file
Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2 #设置密码强度
Skipping password set for root as authentication with auth_socket is used by
default.
If you would like to use password authentication instead, this can be done
with the "ALTER_USER" command.
See https://dev.mysql.com/doc/refman/8.0/en/alter-user.html#alter-user password-management for more information.
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. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.
Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y #默认情
况下,MySQL安装有⼀个匿名⽤⼾, 允许任何⼈登录MySQL. 是否删除匿名⽤⼾?
Success.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) : Y #仅
应允许root从'localhost'连接
Success.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.
Remove test database and access to it? (Press y|Y for Yes, any other key for
No) : Y #默认情况下, MySQL带有⼀个test数据库, 是否删除?
- Dropping test database...
Success.
- Removing privileges on test database...
Success.
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) : Y #是
否现在加载配置, 使刚才的修改⽣效?
Success.
All done!
设置密码:
sudo mysql 连接MySQL服务器
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY
'想要设置的密码';
切记,一定要设置密码!!!!
5.部署Web项目到Linux
5.1什么是环境
5.2环境配置

#pom.xml设置
<profiles>
<profile>
<id>dev</id>
<properties>
<profile.name>dev</profile.name>
</properties>
</profile>
<profile>
<id>prod</id>
<properties>
<profile.name>prod</profile.name>
</properties>
</profile>
</profiles>
//配置文件 appcation.yml设置
spring:
profiles:
active: @profile.name@
配置文件中的active: @profile.name@要和pom文件中的名字一致
此时插件中就有我们设置的两个了
5.3构建项目并打包

5.4 上传到服务器并执行
安装
apt-get install lrzsz
将jar包直接拖到终端.
持续运行,即使关闭后台也可以运行
nohup 'jar包名字' &
5.5 杀掉进程
如果我们需要重启服务, 或者重新部署等, 都需要先停⽌之前的服务
指令
kill -6 '进程pid'
或者也可以用强制杀死进程
kill -9 '进程pid'