Contents
Preface
This article is mainly for record purpose, so as to save you from installing various software every time you install a new debian virtual machine. Why mention debian virtual machine? Because debian's LXC has already installed most of the basic software as long as it is newly created. The following article assumes that the console is logged in as root user, so I will not type sudo to save a few words.
注1:下面第1,2步操作只能在控制台里操作。
注2:因为我是在本地使用debian官网提供的mini镜像进行安装,默认基本什么软件都有没有,所以需要自己手动安装。而如果是其他部署环境,比如是云主机之类,供应商默认提供的镜像可能已经集成了其中一些软件,所以可以不用单独安装。
注3:根据自己的实际需求来判断是否需要进行本文中的一些操作或者是否需要安装一些工具,毕竟本文是按照我自己的需求来记录的。
1、安装vim
这是首要大事,命令如下:
apt install vim
2. Install and configure ssh server
Install openssh-server:
apt install openssh-server
Allow ssh login using the root account:
vim /etc/ssh/sshd_config
RemovePermitRootLogin
The previous #, and modified toyes
Allow the root user to log in to ssh using username and password:
vim /etc/ssh/ssh_config
RemovePasswordAuthentication
The previous #, and change it to yes
After the modification is complete, restart the ssh service:
systemctl restart ssh
Or you can restart it using the service command:
service ssh restart
In fact, I recommend logging in directly with the public key, which is safer. However, I need to connect from many terminals, and I don't like to configure each one, so I just log in with the account and password. If you usually manage 1 or 2 terminals, I suggest you log in directly with the public key. I will write another article about the configuration of public key login.
The following operations can be done using an ssh client and directly using copy and paste operations without having to use the difficult-to-use console. :)
3、配置时区
安装过程已经配置好的这步就可以跳过了:
timedatectl list-timezones \\List time zones timedatectl set-timezone your_time_zone \\Change time zone, usually Asia/Shanghai
4、修改hostname
这步也不是必须,视大家需要而定,有3种方式:
usehostnamectl
Command, after modification, it is permanently effective and requires restart:
hostnamectl set-hostname your-hostname
Edit the hostname file directly. The modification is permanent and requires a restart:
vim /etc/hostname
Use the hostname command:
hostname your-hostname
It takes effect immediately, but becomes invalid after reboot.
5、修改IP地址
debian 11的修改方式:
vim /etc/network/interfaces
The content is similar to the following:
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
Change tomanaged=true
6、修改DNS地址
Temporary modification:
vim /etc/resolv.conf
The content is similar to the following:
nameserver 119.29.29.29 #设置首选dns,国外尽量选1.1.1.1或者8.8.8.8
nameserver 8.8.8.8 #设置备用dns
Just modify as needed.
Permanent modification:
vim /etc/systemd/resolved.conf
Then add a line and modify the DNS address as needed:
DNS=8.8.8.8 114.114.114.114
After configuring steps 5 and 6, you need to restart the network service to take effect:
service networking restart
7、安装常用网络工具
The command is as follows:
apt install net-tools
运行上面命令会安装一组经典的网络工具,包括 ifconfig、netstat、route、arp、hostname 和 mii-tool,这些工具常用于网络接口配置、路由表查看、ARP缓存管理和网络故障排除等任务。
8、安装DNS排查工具
apt install dnsutils
运行上面命令会安装一组DNS查询工具,包括 dig、nslookup 和 host,这些工具用于执行DNS查询、解析和诊断,帮助排查域名解析问题。
9、配置apt源(主机在国内才需要)
The default repository source is configured in /etc/apt/sources.list
In, and each software's own source is in/etc/apt/sources.list.d/
in the directory.
Here we assume that we use the USTC source of debian12 and use the cat command to add it directly:
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
Of course, you can also use vim, whatever you like.
After changing the source, remember to useapt update
Command update. (The principle of apt is: a list of software package information is saved locally, such as software size, version number, dependencies, etc. The apt update command updates this information list instead of updating the source (updating the source is done by the server). If this list is not updated, an old version of the software package may be installed when installing the software.)
Note that the sources for different versions are different, for example, debian12 corresponds to bookworm, and debian11 corresponds to 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
暂时先记录这么多,后续遇到了再添加。