# 防火墙状态,如果输出显示 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 服务端口,默认端口是22sudo 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 8000sudo 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
# 检查正在监听的端口sudonetstat-tlpn|grep8000
下载JDK
apt-yinstall openjdk-8-jdk
安装mysql
更新apt源
apt update
下载mysql-server
apt-yinstall mysql-server
查看mysql的状态
service mysql status # 查看运行状态service mysql start # 启动mysqlservice mysql stop # 关闭mysql
systemctl restart mysql # 重启mysql
systemctl enable mysql # 开机自启
进入mysql终端
mysql
设置root密码
ALTER USER'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
登录mysql
mysql -u root -p'123456'
回到不用密码的方式登录
ALTER USER'root'@'localhost' IDENTIFIED WITH auth_socket;
添加账户
create user 'glt'@'%' identified by '%5245dsfdfd';# %的意思是任意ip可访问,后面是密码
flush privileges;
root账号远程访问
# 方式1
编辑MySQL配置文件,通常是/etc/mysql/mysql.conf.d/mysqld.cnf。找到bind-address行并将其注释掉或设置为0.0.0.0
# 方式2
use mysql;
update user sethost='%' where user ='root';# 二选一
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;# 二选一
flush privileges;