目录
一、apt
apt(Advanced Packaging Tool), Linux软件包管理工具,用于在Ubuntu、Debian和相关Linux发行版上安装、更新、删除和管理deb软件包。大多数apt命令必须以具有sudo权限的用户身份运行。
apt常用命令:
列出所有软件包 :
apt list
输出所有包的列表,内容比较多,可以使用grep命令过滤输出。
apt list | grep "java"
更新软件包数据库。
sudo apt-get update
apt实际上在可用软件包的数据库上工作。如果数据库没有更新, 系统将不知道是否有更新的软件包可用。这就是为什么在安装任何Linux系统之后,第一件事应该是更新apt数据库。运行此命令时,将看到从各种服务器检索到的软件包信息。如果切换到root用户,命令前就不需要加 sudo了 。
切换为root用户的命令:
sudo su
安装软件包:
sudo apt install package_name
移出软件包:
sudo apt remove package_name
remove命令将卸载给定的软件包,但可能会留下一些配置文件。如果要删除包含所有配置文件的软件包,请使用purge而不是remove。
apt remove 和 apt purge 的区别:
apt remove 删除包的二进制文件,它留下了残留的配置文件。
apt purge 删除与包相关的所有内容,包括配置文件。
如果弄乱了程序的配置,希望从系统中完全清除它的痕迹再重新开始,可以使用apt purge 。通常使用 apt remove 就足够。
二、JDK
2.1 更新软件包
sudo apt-get update
执行结果:
ubuntu@VM-24-3-ubuntu:~$ sudo apt-get update #更新软件包
Hit:1 http://mirrors.tencentyun.com/ubuntu jammy InRelease
Hit:2 http://mirrors.tencentyun.com/ubuntu jammy-updates InRelease
Hit:3 http://mirrors.tencentyun.com/ubuntu jammy-security InRelease
Reading package lists... Done
2.2 安装openjdk
#查找jdk包
apt list |grep "jdk"
#安装jdk
sudo apt install openjdk-17-jdk
执行结果:
root@bite:~# apt list |grep "jdk" #查找jdk
openjdk-8-doc/focal-updates,focal-updates,focal-security,focal-security 8u382-
ga-1~20.04.1 all
openjdk-8-jdk-headless/focal-updates,focal-security,now 8u382-ga-1~20.04.1
amd64 [installed,automatic]
openjdk-8-jdk-headless/focal-updates,focal-security 8u382-ga-1~20.04.1 i386
openjdk-8-jdk/focal-updates,focal-security,now 8u382-ga-1~20.04.1 amd64
[installed]
openjdk-8-jdk/focal-updates,focal-security 8u382-ga-1~20.04.1 i386
openjdk-8-jre-headless/focal-updates,focal-security,now 8u382-ga-1~20.04.1
amd64 [installed,automatic]
openjdk-8-jre-headless/focal-updates,focal-security 8u382-ga-1~20.04.1 i386
openjdk-8-jre-zero/focal-updates,focal-security 8u382-ga-1~20.04.1 amd64
openjdk-8-jre-zero/focal-updates,focal-security 8u382-ga-1~20.04.1 i386
openjdk-8-jre/focal-updates,focal-security,now 8u382-ga-1~20.04.1 amd64
[installed,automatic]
openjdk-8-jre/focal-updates,focal-security 8u382-ga-1~20.04.1 i386
openjdk-8-source/focal-updates,focal-updates,focal-security,focal-security
8u382-ga-1~20.04.1 all
ubuntu@VM-24-3-ubuntu:~$ sudo apt install openjdk-17-jdk #输⼊安装命令
Reading package lists... Done
Building dependency tree... Done
Reading 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
验证是否安装成功:
ubuntu@VM-24-3-ubuntu:~$ java -version #查看jdk版本
openjdk version "17.0.10" 2024-01-16
OpenJDK Runtime Environment (build 17.0.10+7-Ubuntu-120.04.1)
OpenJDK 64-Bit Server VM (build 17.0.10+7-Ubuntu-120.04.1, mixed mode, sharing)
卸载OpenJDK:检查安装的是哪个OpenJDK # dpkg --list | grep -i jdk 移除 openjdk包: # apt-get purge openjdk* 卸载 OpenJDK 相关包: # apt-get purge icedtea-* openjdk-* 检查所有 OpenJDK包是否都已卸载完毕: # dpkg --list | grep -i jdk
三、MySQL
3.1 使用apt安装MySQL
#查找安装包
apt list |grep "mysql-server"
#安装mysql
sudo 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) ...
3.2 查看MySQL的状态
sudo systemctl status mysql
执行结果:
ubuntu@VM-24-3-ubuntu:~$ sudo systemctl status mysql
● mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor
preset: enabled)
Active: active (running) since Tue 2023-10-31 15:05:59 CST; 13min ago
Process: 70739 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre
(code=exited, status=0/SUCCESS)
Main PID: 70747 (mysqld)
Status: "Server is operational"
Tasks: 37 (limit: 2220)
Memory: 369.2M
CPU: 2.360s
CGroup: /system.slice/mysql.service
└─70747 /usr/sbin/mysqld
Oct 31 15:05:58 VM-24-3-ubuntu systemd[1]: Starting MySQL Community Server...
Oct 31 15:05:59 VM-24-3-ubuntu systemd[1]: Started MySQL Community Server.
3.3 MySQL 安装安全设置
默认的 MySQL 设置是不安全的,MySQL 安装提供了一个安全脚本,用于解决不太安全的默认选项。
运行以下命令:
sudo mysql_secure_installation
接下来按照提示输入:
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-userpassword-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!
3.4 设置密码
连接mysql数据库:
sudo mysql
使用alter user 命令修改密码:
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY
'BITE@yyds.666';
卸载MySQL:#停止mysql sudo systemctl stop mysql #卸载mysql sudo apt-get remove --purge mysql-server mysql-client mysql-common #删除 MySQL 配置文件和数据 sudo rm -rf /etc/mysql /var/lib/mysql #清理残留文件和目录 sudo apt-get autoremove sudo apt-get autoclean #验证卸载结果 mysql --version