1 System installation
1.1 iso download
ubuntu official website
https://cn.ubuntu.com/
1.2 Install ubuntu-22.04.2
1.2.1 System update settings
Select continue without updating
1.2.2 Partition settings
Disk selection custom configuration
Select a free partition, press Enter, and choose to add a GPT partition.
Allocate 1G space to boot partition
The remaining capacity is allocated to the root partition. If the capacity is not filled in, all remaining capacity is allocated.
After the partition is set, click Finish
1.2.3 User settings
Create a user and set the hostname
1.2.4 ssh service settings
Install ssh service
1.2.5 Pre-installed services
Select the services that need to be installed when installing the system. If not, you can skip it directly. After selecting this step, the system installation will begin.
Restart directly after the installation is completed. View full log can view the installation log.
2 User configuration
2.1 Log in to the system
Log in to the system using the user created when installing the system
2.2 root user configuration
2.2.1 Set root password
Ubuntu 22 requires setting the ubuntu root password after installing the system in order to log in normally.
zl@ubuntu:~$ sudo passwd root ##为root用户设置密码
[sudo] password for zl: ##输入zl用户的密码
New password: ##设置root用户的密码
Retype new password: ##重复root用户的密码
passwd: password updated successfully
zl@ubuntu:~$
zl@ubuntu:~$ su root ##尝试是否能登录root用户
Password:
root@ubuntu:/home/zl# id
uid=0(root) gid=0(root) groups=0(root)
root@ubuntu:/home/zl#
2.2.2 Allow ssh to log in as root user
You need to use the root user to edit and restart the ssh service
root@ubuntu:/home/zl# grep PermitRoot /etc/ssh/sshd_config
#PermitRootLogin prohibit-password
PermitRootLogin yes
# the setting of "PermitRootLogin without-password".
root@ubuntu:/home/zl# systemctl restart sshd
3 Network configuration
3.1 dhcp configuration
dhcp configuration is relatively simple
root@ubuntu:/etc/netplan# pwd
/etc/netplan
root@ubuntu:/etc/netplan# cat 00-installer-config.yaml
# This is the network config written by 'subiquity'
network:
ethernets:
ens3:
dhcp4: true
version: 2
root@ubuntu:/etc/netplan# netplan apply ##应用配置
In the above file we have used the following:
- ens3: interface name
- dhcp4: enable dhcp
3.2 Static IP configuration
In Ubuntu Server 22.04, the network is controlled by NetPlan Utility, so we will use NetPlan to configure a static IP address on Ubuntu Server.
Log in to your server and look for the NetPlan configuration file. It is located in the /etc/netplan directory and is a file in yaml format.
root@ubuntu:/etc/netplan# pwd
/etc/netplan
root@ubuntu:/etc/netplan# cat 00-installer-config.yaml ##修改如下内容,设置网卡ip及密码
# This is the network config written by 'subiquity'
network:
renderer: networkd
ethernets:
ens3:
addresses:
- 172.18.100.112/16
nameservers:
addresses: [114.114.114.114, 8.8.8.8]
routes:
- to: default
via: 172.18.0.1
version: 2
In the above file we have used the following:
- ens3: interface name
- addresses: used to set static IP
- nameservers: used to set up DNS server
- routes: used to set the gateway
For the above changes to take effect, apply them using the following netplan command
root@ubuntu:/etc/netplan# netplan apply
4 Software package management
4.1 Network source configuration
The source of each version is different. This example is the configuration method of version 22.04.
root@ubuntu:/etc/netplan# mv /etc/apt/sources.list /etc/apt/sources.list.bak
root@ubuntu:/etc/netplan# cat /etc/apt/sources.list ##新编辑一个文件,内容如下
deb http://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ jammy-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse
- The first fields deb and deb-src refer to the software package (deb) and source code package (deb-src)
- The second field points to the location of the software library. apt will automatically grab the software index (/dists) and software package or source code package (/pool) information based on the location of the software library and the information in the third field.
- The third field represents the release version, which corresponds to the folder under the dists directory in the URL path.
4.2 Use of package management tool apt
4.2.1 apt introduction
The full name of apt is Advanced Packaging Tool, which is an installation package management tool under Linux system.
Initially, you need to install software in the Linux system and compile various software by yourself. There is a lack of a unified management tool for software packages. Afterwards, when the Debian system appeared, the dpkg management tool was designed. After that, in order to install various software more quickly and conveniently, dpkg's front-end tool APT also appeared. In the Ubuntu16.04 system, the apt command function has been strengthened, making it more convenient, faster and more popular.
4.2.2 Common commands
- check
root@ubuntu:/etc/netplan# apt list --installed ##列出已安装的包
root@ubuntu:/etc/netplan# apt-cache show vim ##查看vim包的详细信息
- increase
root@ubuntu:/etc/netplan# apt-get install monkeysphere=0.43-3 ##安装包并指定版本为0.43-3
root@ubuntu:/etc/netplan# apt-get -f install ##如果安装包报依赖错误,可以执行该语句
- delete
root@ubuntu:/etc/netplan# apt-get remove vim --purge ##带--purge参数,不但会删除包,还会删除配置文件
4.3 Use of software management tool dpkg
4.3.1 dpkg introduction
dpkg is the abbreviation of Debian package, a package management system specially developed for the "Debian" operating system, used for software installation, update and removal.
All Linux distributions derived from "Debian" use dpkg, such as "Ubuntu"
- check
root@ubuntu:/etc/netplan# dpkg -L vim ##列出vim包的安装时的文件,类似rpm -ql
root@ubuntu:/etc/netplan# dpkg -l vim ##查看包的版本信息
root@ubuntu:/etc/netplan# dpkg -s vim ##查看包的详细信息
root@ubuntu:/etc/netplan# dpkg -c vim.dep ##列出某个包的内容
root@ubuntu:/etc/netplan# dpkg -S /usr/share/vim/vim82/indent/dylan.vim ##查看某个文件属于哪个包,类似于rpm -qf
vim-runtime: /usr/share/vim/vim82/indent/dylan.vim
root@ubuntu:/etc/netplan# dpkg --unpack vim.dep ##解包
- increase
root@ubuntu:/etc/netplan# dpkg -i vim.dep ##安装软件
- delete
root@ubuntu:/etc/netplan# dpkg -r vim ##卸载软件包,但保留软件包的配置文件
root@ubuntu:/etc/netplan# dpkg -P vim ##完全卸载软件包,包括其二进制文件、库文件和配置文件。
dpkg -r
Command is used to uninstall a package but keep the package's configuration files. It removes the package's binaries and associated library files from the system, but retains the configuration files so that previous configuration options can be preserved when the package is reinstalled. After using this command, the package will be marked as "rc" (removed but configured) status.dpkg -P
Command is used to completely uninstall a software package, including its binaries, libraries, and configuration files. It completely removes the package and all its associated files and configuration from the system. After using this command, the package will be marked in the "purge" state.
5. Enable logging
5.1 Enable message log
In the Ubuntu system, sometimes we need to view the service startup log through journalctl -xe, but the log is not fully printed, so we still need to view it through the /var/log/messages file.
In some new ubuntu systems, this file does not exist. We need to set it up and modify the file /etc/rsyslog.d/50-default.conf
root@ubuntu:~# grep message -B 3 /etc/rsyslog.d/50-default.conf ##注释以下几行
*.=info;*.=notice;*.=warn;\
auth,authpriv.none;\
cron,daemon.none;\
mail,news.none -/var/log/messages
root@ubuntu:~# systemctl restart rsyslog
root@ubuntu:~# tail -f /var/log/messages ##此时能看到/var/log/message日志输出
Welcome to follow the personal public account singless. Please indicate the source when reprinting.