# 防火墙状态,如果输出显示 Status: inactive,表示 UFW 处于禁用状态
sudo ufw status
# 关闭防火墙
sudo ufw disable
# 启动防火墙
sudo ufw enable
# 设置防火墙默认策略的命令,将所有出站连接允许通过防火墙
sudo ufw default allow outgoing
# 设置防火墙默认策略的命令,将所有入站连接禁止通过防火墙
sudo ufw default deny incoming
# 允许端口
sudo ufw allow 8000
# 开启 ssh 服务端口,默认端口是22
sudo ufw allow ssh
# 关闭特定端口
sudo ufw delete allow 8000
# 指定特定来源的源 IP 地址
sudo ufw allow from <IP 地址> to any port <端口号>
# 如配置 172.16.2.193 设备能访问或关闭服务器的 8000 端口
sudo ufw allow from 172.16.2.193 to any port 8000
sudo ufw delete allow from 172.16.2.193 to any port 8000
# 允许来自 192.168.1.100 IP 地址的 HTTP 流量通过防火墙
sudo ufw allow from 172.16.2.193 to any port 3336 proto tcp
sudo ufw delete allow from 172.16.2.193 to any port 3336 proto tcp
# 重新加载防火墙规则
sudo ufw reload
# 重置防火墙配置规则
sudo ufw reset
# 检查正在监听的端口
sudo netstat -tlpn | grep 8000
下载JDK
shell复制代码
apt -y install openjdk-8-jdk
安装mysql
更新apt源
shell复制代码
apt update
下载mysql-server
shell复制代码
apt -y install mysql-server
查看mysql的状态
shell复制代码
service mysql status # 查看运行状态
service mysql start # 启动mysql
service mysql stop # 关闭mysql
systemctl restart mysql # 重启mysql
systemctl enable mysql # 开机自启
进入mysql终端
shell复制代码
mysql
设置root密码
shell复制代码
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
登录mysql
shell复制代码
mysql -u root -p'123456'
回到不用密码的方式登录
shell复制代码
ALTER USER 'root'@'localhost' IDENTIFIED WITH auth_socket;
添加账户
shell复制代码
create user 'glt'@'%' identified by '%5245dsfdfd'; # %的意思是任意ip可访问,后面是密码
flush privileges;
root账号远程访问
shell复制代码
# 方式1
编辑MySQL配置文件,通常是/etc/mysql/mysql.conf.d/mysqld.cnf。找到bind-address行并将其注释掉或设置为0.0.0.0
# 方式2
use mysql;
update user set host = '%' where user = 'root'; # 二选一
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION; # 二选一
flush privileges;