1、基本命令
# 查看ubuntu版本
lsb_release -a
# 修改密码
sudo passwd ubuntu
# 修改远程端口
vim /etc/ssh/sshd_config
sudo service ssh restart
# 基础软件安装
sudo apt install iputils-ping -y
sudo apt install net-tools -y
sudo apt install vim -y
sudo apt install ufw -y
2、防火墙
sudo ufw status
sudo ufw enable
sudo ufw disable
#开通端口
sudo ufw allow 53306/tcp
#关闭端口
sudo ufw delete allow 53306/tcp
3、设置固定ip
# 查看当前网络
ip a
# 修改配置文件
vim /etc/netplan/xxxx.yaml
network:
version: 2
ethernets:
enp1s0:
dhcp4: no
addresses: [192.168.8.23/24]
routes:
- to: default
via: 192.168.8.1
nameservers:
addresses: [8.8.8.8, 8.8.4.4]
# 应用配置
sudo netplan apply
4、安装docker
sudo apt update
sudo apt install -y ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo tee /usr/share/keyrings/docker-archive-keyring.gpg > /dev/null
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt update
sudo apt install -y docker-ce
sudo systemctl start docker
sudo systemctl enable docker # 设置开机启动
sudo docker --version # 查看 Docker 版本
#配置国内镜像:
vim /etc/docker/daemon.json
{
"registry-mirrors": [
"https://y8yh50dy.mirror.aliyuncs.com",
"https://docker.m.daocloud.io"
]
}
#验证镜像是否可访问:curl -I https://docker.m.daocloud.io
#重启docker:
sudo systemctl daemon-reload
sudo systemctl restart docker
#进入容器
docker pull hello-world:latest
sudo docker run hello-world
docker exec -it 容器名称 bash
# 卸载:
# 0.停止docker
systemctl stop docker.socket
systemctl disable docker.socket
systemctl stop docker
systemctl disable docker
# 1. 查找 Docker 相关的包并卸载
dpkg -l | grep -i docker
sudo apt remove --purge -y <package-name>
# 2. 检查和删除 Docker 二进制文件
sudo rm /usr/local/bin/docker
sudo rm /usr/local/bin/dockerd
# 3. 清理 Docker 残留的配置和数据目录
sudo rm -rf /var/lib/docker
sudo rm -rf /etc/docker
sudo rm -rf /var/lib/containerd
sudo rm -rf /run/docker
# 4. 检查 /usr/bin 目录中的 Docker 可执行文件
sudo rm -f /usr/bin/docker
sudo rm -f /usr/bin/dockerd
# 5. 清除 APT 缓存
sudo apt autoremove -y
sudo apt autoclean
# 6. 验证卸载是否成功,收入命令:docker --version。如果系统返回 docker: command not found,则表示 Docker 已被完全卸载。
docker --version
5、安装nginx
sudo apt install nginx -y
sudo systemctl restart nginx
sudo systemctl status nginx
cp /etc/nginx/nginx.conf /etc/nginx/nginx_bak.conf
vim /etc/nginx/nginx.conf
6、安装mysql
sudo systemctl status mysql
sudo systemctl restart mysql
# 修改mysql默认端口,以及设置远程可连接
sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
# port = 53306
# mysqlx = 0 // 禁用MySQL 8.0 中引入的新的X Protocol 端口
# bind-address = 0.0.0.0
sudo netstat -tulnp | grep mysql
# mysql设置向导
sudo mysql_secure_installation
# 设置msyql root@localhost密码
sudo mysql -u root -p
alter user 'root'@'localhost' IDENTIFIED BY 'Root@123';
flush privileges;
# 设置mysql在宿主机上也需要密码验证
select user,host,plugin from mysql.user;
update mysql.user set plugin = 'mysql_native_password' where user = 'root';
# 创建mysql数据库及用户
create database db_dianchi;
create user 'test'@'%' identified by '12345678';
alter user 'test'@'%' identified by '12345678';
grant all privileges on db_dianchi.* to 'test'@'%';
flush privileges;