Contents
前言
这篇文章主要是记录性质,省得自己每次新安装了debian虚拟机以后东一下,西一下的安装各种软件。为什么单提debian虚拟机?因为debian的LXC只要一新建好基本软件已经装得七七八八了。下文假定是控制台是root用户登录,我就不打sudo了,省几个字。
注1:下面第1,2步操作只能在控制台里操作。
注2:因为我是在本地使用debian官网提供的mini镜像进行安装,默认基本什么软件都有没有,所以需要自己手动安装。而如果是其他部署环境,比如是云主机之类,供应商默认提供的镜像可能已经集成了其中一些软件,所以可以不用单独安装。
注3:根据自己的实际需求来判断是否需要进行本文中的一些操作或者是否需要安装一些工具,毕竟本文是按照我自己的需求来记录的。
1、安装vim
这是首要大事,命令如下:
apt install vim
2、安装并配置ssh服务器
安装openssh-server:
apt install openssh-server
允许使用root账号登录ssh:
vim /etc/ssh/sshd_config
去掉PermitRootLogin
前面的#,并修改为yes
允许root用户使用用户名及密码登录ssh:
vim /etc/ssh/ssh_config
去掉PasswordAuthentication
前面的#,并修改为yes
修改完成后重启ssh服务即可:
systemctl restart ssh
或者用service命令重启也行:
service ssh restart
其实我更推荐直接用公钥登录,更安全,只不过我因为需要从很多终端连接,每个都要配置一次我嫌烦,所以就直接使用账号密码登录,如果你平时都是1,2个管理终端,我建议直接用公钥登录。公钥登录的配置我另起一篇文章单独说。
接下来的操作就可以使用ssh客户端并且直接使用复制粘贴操作了,不用使用难用的控制台了。:)
3、配置时区
安装过程已经配置好的这步就可以跳过了:
timedatectl list-timezones \\列出时区
timedatectl set-timezone your_time_zone \\改时区,这里一般是Asia/Shanghai
4、修改hostname
这步也不是必须,视大家需要而定,有3种方式:
使用hostnamectl
命令,修改后永久有效,需要重启:
hostnamectl set-hostname your-hostname
直接编辑hostname文件,修改后永久有效,需要重启:
vim /etc/hostname
使用hostname命令:
hostname your-hostname
即时生效,但是重启后失效。
5、修改IP地址
debian 11的修改方式:
vim /etc/network/interfaces
内容类似下面:
auto lo auto eth0 #设置开机自动连接网络
iface lo inet loopback allow-hotplug
eth0 iface eth0 inet static #static表示使用固定IP地址上网,dhcp表示使用动态ip address 192.168.9.100 #设置静态ip地址,注意只是address,没有ip
netmask 255.255.255.0 #子网掩码 gateway 192.168.9.254 #网关
如果是静态ip地址修改,直接改address后的地址即可;如果是dhcp,将static改为dhcp,同时注释掉address和netmask这2行即可。
debian 12的修改方式:
debian12网络修改和以前版本不一样,不再使用vim /etc/network/interfaces方式(说真心话,我真的很讨厌改变IP地址设置方式的行为),而是使用network-manager:
apt install network-manager
安装NetworkManager包后,命令行中多出两个命令,一个是nmcli
纯命令的网络配置工具,一个是nmtui
的终端图形配置工具。
networkmanager的配置文件路径:/etc/NetworkManager/NetworkManager.conf
,需要修改其中的配置:把managed=false
改为managed=true
6、修改DNS地址
临时修改:
vim /etc/resolv.conf
内容类似下面:
nameserver 119.29.29.29 #设置首选dns,国外尽量选1.1.1.1或者8.8.8.8
nameserver 8.8.8.8 #设置备用dns
按需修改即可。
永久修改:
vim /etc/systemd/resolved.conf
然后添加一行,按需修改dns地址:
DNS=8.8.8.8 114.114.114.114
第5,6步配置以后,需要重启网络服务才能生效:
service networking restart
7、安装常用网络工具
命令如下:
apt install net-tools
运行上面命令会安装一组经典的网络工具,包括 ifconfig、netstat、route、arp、hostname 和 mii-tool,这些工具常用于网络接口配置、路由表查看、ARP缓存管理和网络故障排除等任务。
8、安装DNS排查工具
apt install dnsutils
运行上面命令会安装一组DNS查询工具,包括 dig、nslookup 和 host,这些工具用于执行DNS查询、解析和诊断,帮助排查域名解析问题。
9、配置apt源(主机在国内才需要)
默认的仓库源配置在 /etc/apt/sources.list
中,而各个软件自己的源在/etc/apt/sources.list.d/
目录中。
此处假定我们使用debian12的中科大源,使用cat命令直接添加:
cat > /etc/apt/sources.list << EOF
deb https://mirrors.ustc.edu.cn/debian/ bookworm main contrib non-free non-free-firmware
deb-src https://mirrors.ustc.edu.cn/debian/ bookworm main contrib non-free non-free-firmware
deb https://mirrors.ustc.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware
deb-src https://mirrors.ustc.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware
deb https://mirrors.ustc.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware
deb-src https://mirrors.ustc.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware
deb https://mirrors.ustc.edu.cn/debian-security/ bookworm-security main contrib non-free non-free-firmware
deb-src https://mirrors.ustc.edu.cn/debian-security/ bookworm-security main contrib non-free non-free-firmware
EOF
当然也可以用vim方式,随你喜欢就好。
更改源以后,记得使用apt update
命令更新。(apt的原理是:本地保存了一份软件包信息的列表,比如软件大小,版本号,依赖等,apt update命令是更新这个信息列表,而不是更新源(更新源是服务端做的事情),如果不更新这个列表,安装软件的时候可能就安装了旧版本的软件包。)
注意不同版本的源是不一样的,比如debian12对应bookworm,debian11对应bullseye。
10、部署docker环境
首先,安装一些必要的软件包:
apt update
apt upgrade -y
apt install curl vim wget gnupg dpkg apt-transport-https lsb-release ca-certificates
然后加入 Docker 的 GPG 公钥和 apt 源,(Debian系统)命令如下:
curl -sSL https://download.docker.com/linux/debian/gpg | gpg --dearmor > /usr/share/keyrings/docker-ce.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-ce.gpg] https://download.docker.com/linux/debian $(lsb_release -sc) stable" > /etc/apt/sources.list.d/docker.list
最后更新及安装:
apt update && apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
暂时先记录这么多,后续遇到了再添加。