2.2. Install the Ubuntu operating system on the host
The host of this article uses the VMware Workstation virtual machine to install the Ubuntu operating system. The installation file of the operating system is ubuntu-20.04.3-desktop-amd64.
2.2.1. Ubuntu system installation
The first step is to create the Ubuntu image storage folder and the VMware virtual machine disk storage folder
Create an "Ubuntu" folder on the desktop of the local computer, and then copy the ubuntu-20.04.3-desktop-amd64.iso image to the "Ubuntu" folder, as shown in Figure 1.
Create a "Virtual Machine OS Storage/Ubuntu" folder in the D disk of the local computer to store the VMware virtual machine files created later, as shown in Figure 2.
The second step is to create a new virtual machine and edit the configuration of the virtual machine
There is not much difference from the configuration of the CentOS system, so it will not be demonstrated here. For details, please refer to the relevant content of "KVM Virtualization Solution Series - KVM Deployment (1-3)".
The third step is to start the virtual machine, enter the Ubuntu operating system installation interface, select "Chinese (simplified)" language, and then press the "Install Ubuntu" button to continue, as shown in Figure 3
The fourth step, the system enters the "Keyboard Layout" interface, select "Chinese", and click the "Continue" button, as shown in Figure 4
The fifth step, the system enters the "Update and other software" interface, select "Normal installation", and then click the "Continue" button, as shown in Figure 5
Step 6, the system enters the "Installation Type" interface, select "Clear the entire disk and follow Ubuntu", and then click the "Install Now" button, as shown in Figure 6
Step 7, the system pops up the "Write Changes to Disk" interface, click the "Continue" button, as shown in Figure 7
The eighth step, the system enters the time zone selection interface, select the "Shanghai" time zone, and then click the "Continue" button, as shown in Figure 8
The ninth step, the system enters the user name and password setting interface, fill in the user name and password according to the actual situation, select "Require password when logging in", and then click the "Continue button", as shown in Figure 9
In the tenth step, the system enters the installation process, and the entire installation takes about 7 minutes, as shown in Figure 10
The eleventh step, the system installation is complete, you need to restart to use the Ubuntu system, click the "Restart Now" button, as shown in Figure 11
The twelfth step, open the terminal command window in the graphical user interface, the command can be used normally, as shown in Figure 12
2.2.2. Basic network configuration
Set the network card IP address, subnet mask, gateway, and DNS in the graphical interface to ensure that the Ubuntu server is connected to the Internet.
The first step, in the graphical interface, select the "wired settings" option to configure the network, as shown in Figure 13
Step 2: In the network graphical interface, click the network card configuration button to enter the network configuration interface, as shown in Figure 14
Step 3: In the network card configuration interface, select the "Manual" configuration method, configure the IP address, subnet mask, gateway and DNS information, and then click the "Apply" button, as shown in Figure 15
Step 4: In the network interface, click the restart button of the network card to make the network card configuration take effect, as shown in Figure 16
The fifth step, use the ping command to check whether you can access the Internet
root@kvm02:~# ping www.baidu.com
PING www.a.shifen.com (14.215.177.39) 56(84) bytes of data.
64 比特,来自 14.215.177.39 (14.215.177.39): icmp_seq=1 ttl=55 时间=8.33 毫秒
64 比特,来自 14.215.177.39 (14.215.177.39): icmp_seq=2 ttl=55 时间=7.80 毫秒
64 比特,来自 14.215.177.39 (14.215.177.39): icmp_seq=3 ttl=55 时间=8.09 毫秒
64 比特,来自 14.215.177.39 (14.215.177.39): icmp_seq=4 ttl=55 时间=8.12 毫秒
2.2.3. Enable SSH service for remote login
Unlike the CentOS 7 system, by default, Ubuntu does not enable remote login with SSH service, and you cannot use SSH tools such as Xshell, CRT, etc. for remote login. You need to enable SSH remote service login.
The first step is to check whether Ubuntu has installed the ssh-server service. By default, only the ssh-client service is installed.
root@kvm02:~# dpkg -l | grep ssh
ii libssh-4:amd64 0.9.3-2ubuntu2.1 amd64 tiny C SSH library (OpenSSL flavor)
ii openssh-client 1:8.2p1-4ubuntu0.3 amd64 secure shell (SSH) client, for secure access to remote machines
ii python3-paramiko 2.6.0-2 all Make ssh v2 connections (Python 3)
The second step is to install the ssh-server service
root@kvm02:~# apt-get install openssh-server
正在读取软件包列表... 完成
正在分析软件包的依赖关系树
正在读取状态信息... 完成
将会同时安装下列软件:
ncurses-term openssh-sftp-server ssh-import-id
建议安装:
molly-guard monkeysphere ssh-askpass
下列【新】软件包将被安装:
ncurses-term openssh-server openssh-sftp-server ssh-import-id
升级了 0 个软件包,新安装了 4 个软件包,要卸载 0 个软件包,有 95 个软件包未被升级。
需要下载 688 kB 的归档。
解压缩后会消耗 6,010 kB 的额外空间。
您希望继续执行吗? [Y/n] y
The third step is to check the ssh-server service again
root@kvm02:~# dpkg -l | grep ssh
ii libssh-4:amd64 0.9.3-2ubuntu2.1 amd64 tiny C SSH library (OpenSSL flavor)
ii openssh-client 1:8.2p1-4ubuntu0.3 amd64 secure shell (SSH) client, for secure access to remote machines
ii openssh-server 1:8.2p1-4ubuntu0.3 amd64 secure shell (SSH) server, for secure access from remote machines
ii openssh-sftp-server 1:8.2p1-4ubuntu0.3 amd64 secure shell (SSH) sftp server module, for SFTP access from remote machines
ii python3-paramiko 2.6.0-2 all Make ssh v2 connections (Python 3)
ii ssh-import-id 5.10-0ubuntu1 all securely retrieve an SSH public key and install it locally
The fourth step is to enable the ssh-server service
root@kvm02:~# service ssh start
The fifth step is to set the root password. You need to log in to SSH with root privileges, as shown in Figure 17
root@kvm02:~# passwd root
新的 密码:
重新输入新的 密码:
passwd:已成功更新密码
2.2.4. Modify the Ubuntu system YUM software source
The first step, use the command "ls /ect/apt" to view the default YUM source file of the system
root@kvm02:~# ls /etc/apt
apt.conf.d auth.conf.d preferences.d sources.list sources.list.d trusted.gpg.d
The second step is to use the command "cat /etc/apt/sources.list" to view the system's default YUM source file information
From the output information, we can see that the address of the YUM source file is http://cn.archive.ubuntu.com/ubuntu/, which is the official Ubuntu server. The speed of accessing the official Ubuntu server from China is relatively slow. time will be disconnected.
root@kvm02:~# cat /etc/apt/sources.list
……(省略)
deb http://cn.archive.ubuntu.com/ubuntu/ focal main restricted
deb http://cn.archive.ubuntu.com/ubuntu/ focal-updates main restricted
deb http://cn.archive.ubuntu.com/ubuntu/ focal universe
deb http://cn.archive.ubuntu.com/ubuntu/ focal-updates universe
deb http://cn.archive.ubuntu.com/ubuntu/ focal multiverse
deb http://cn.archive.ubuntu.com/ubuntu/ focal-updates multiverse
deb http://cn.archive.ubuntu.com/ubuntu/ focal-backports main restricted universe multiverse
……(省略)
The third step is to use the command "ping www.163.com" to detect the connectivity between the Ubuntu server and NetEase
root@kvm02:~# ping www.163.com
PING z163picipv6.v.bsgslb.cn (110.167.163.22) 56(84) bytes of data.
64 比特,来自 110.167.163.22 (110.167.163.22): icmp_seq=1 ttl=53 时间=54.2 毫秒
64 比特,来自 110.167.163.22 (110.167.163.22): icmp_seq=2 ttl=53 时间=53.8 毫秒
64 比特,来自 110.167.163.22 (110.167.163.22): icmp_seq=3 ttl=53 时间=54.2 毫秒
The fourth step, use the command "mv /etc/apt/sources.list /tmp" to back up the original YUM source file to /tmp
root@kvm02:~# mv /etc/apt/sources.list /tmp
The fifth step is to create a new YUM source file and add Netease YUM source address
Just replace the default address of http://cn.archive.ubuntu.com/ubuntu/ in the original sources.list file with Netease address http://mirrors.163.com/ubuntu/.
root@kvm02:~# vi /etc/apt/sources.list
deb http://mirrors.163.com/ubuntu/ focal main restricted
deb http://mirrors.163.com/ubuntu/ focal-updates main restricted
deb http://mirrors.163.com/ubuntu/ focal universe
deb http://mirrors.163.com/ubuntu/ focal-updates universe
deb http://mirrors.163.com/ubuntu/ focal multiverse
deb http://mirrors.163.com/ubuntu/ focal-updates multiverse
deb http://mirrors.163.com/ubuntu/ focal-backports main restricted universe multiverse
The sixth step, use the command "apt-get update" to update the YUM source
root@kvm02:~# apt-get update
获取:1 http://mirrors.163.com/ubuntu focal InRelease [265 kB]
获取:2 http://mirrors.163.com/ubuntu focal-updates InRelease [114 kB]
获取:3 http://mirrors.163.com/ubuntu focal-backports InRelease [101 kB]
……(省略)
获取:76 http://mirrors.163.com/ubuntu focal-backports/universe amd64 c-n-f Metadata [276 B]
获取:77 http://mirrors.163.com/ubuntu focal-backports/multiverse amd64 c-n-f Metadata [116 B]
已下载 43.6 MB,耗时 14秒 (3,229 kB/s)
正在读取软件包列表... 完成
The seventh step, use the command "apt-get upgrade" to update the components
root@kvm02:~# apt-get upgrade
正在读取软件包列表... 完成
正在分析软件包的依赖关系树
正在读取状态信息... 完成
正在计算更新... 完成
下列软件包将被升级:
……(省略)
正在处理用于 ca-certificates (20210119~20.04.2) 的触发器 ...
Updating certificates in /etc/ssl/certs...
0 added, 0 removed; done.
Running hooks in /etc/ca-certificates/update.d...
done.
So far, the default YUM source of the Ubuntu operating system has been changed to the NetEase YUM source, and it can be used normally.
2.2.5. Install ifconfig and vim command tools
The latest versions of Ubuntu do not support the ifconfig command by default. If you want to use the ifconfig command in Ubuntu, you need to install the net-tools network tools, as listed below.
root@kvm02:~# apt install net-tools
By default, Ubuntu does not support the vim tool, but only the vi tool. The use of vi is not as simple and convenient as vim. It is recommended to install the vim command tool, as listed below.
root@kvm02:~# apt install vim
2.2.6. Configure NTP time synchronization server
The asynchronous time between the Linux operating system and the virtualization platform will cause many problems, especially when the virtualization platform uses cluster functions and distributed storage functions, so it is very important to build an NTP server. The NTP server can be a physical server or a virtual machine.
Server NTP configuration (blue)
The first step, use the command "apt-get install ntp" to install ntp and ntpdate components
root@kvm02:~# apt-get install ntp
root@kvm02:~# apt-get install ntpdate
The second step is to use the ping command to detect the connectivity between the local NTP server and the public NTP server
Use the Alibaba Cloud NTP server as the public NTP server, and the Ubuntu server as the local NTP server needs to synchronize time with the public NTP server when necessary. Therefore, it is necessary to ensure the interconnection between the local NTP server and the Alibaba Cloud NTP server.
root@kvm02:~# ping ntp.aliyun.com
PING ntp.aliyun.com (203.107.6.88) 56(84) bytes of data.
64 比特,来自 203.107.6.88 (203.107.6.88): icmp_seq=1 ttl=53 时间=46.6 毫秒
64 比特,来自 203.107.6.88 (203.107.6.88): icmp_seq=2 ttl=53 时间=47.6 毫秒
64 比特,来自 203.107.6.88 (203.107.6.88): icmp_seq=3 ttl=53 时间=46.8 毫秒
root@kvm02:~# ping ntp1.aliyun.com
PING ntp1.aliyun.com (120.25.115.20) 56(84) bytes of data.
64 比特,来自 120.25.115.20 (120.25.115.20): icmp_seq=1 ttl=52 时间=6.50 毫秒
64 比特,来自 120.25.115.20 (120.25.115.20): icmp_seq=2 ttl=52 时间=6.83 毫秒
64 比特,来自 120.25.115.20 (120.25.115.20): icmp_seq=3 ttl=52 时间=6.82 毫秒
The third step is to modify the ntp configuration file /etc/ntp.conf, and cancel the default NTP server address of the configuration file
root@kvm02:~# vim /etc/ntp.conf
#pool 0.ubuntu.pool.ntp.org iburst
#pool 1.ubuntu.pool.ntp.org iburst
#pool 2.ubuntu.pool.ntp.org iburst
#pool 3.ubuntu.pool.ntp.org iburst
#pool ntp.ubuntu.com
The fourth step is to modify the ntp configuration file /etc/ntp.conf and add the following configuration
root@kvm02:~# vim /etc/ntp.conf
#授权192.168.150.0网段上所有机器可以从这台机器上查询和时间同步
restrict 192.168.150.0 mask 225.225.225.0 nomotify notrap
#ntp服务器地址
pool ntp1.aliyun.com
pool ntp2.aliyun.com
pool ntp3.aliyun.com
#当外部时间不可用时,使用本地时间
pool 127.0.0.1
fudge 127.0.0.1 stratum 10
#允许上层时间服务器主动修改本机时间
restrict ntp1.aliyun.com nomodify notrap noquery
restrict ntp2.aliyun.com nomodify notrap noquery
restrict ntp3.aliyun.com nomodify notrap noquery
The fifth step, save and exit, restart the ntp service, and add the automatic startup after booting
root@kvm02:~# service ntp start
root@kvm02:~# service ntp restart
The sixth step is to query the current NTP server source information
root@kvm02:~# ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
ntp1.aliyun.com .POOL. 16 p - 64 0 0.000 0.000 0.000
ntp2.aliyun.com .POOL. 16 p - 64 0 0.000 0.000 0.000
ntp3.aliyun.com .POOL. 16 p - 64 0 0.000 0.000 0.000
127.0.0.1 .POOL. 16 p - 64 0 0.000 0.000 0.000
120.25.115.20 10.137.53.7 2 u 61 64 3 6.461 -4.801 0.753
203.107.6.88 10.137.38.86 2 u 60 64 3 43.712 -2.133 1.782
The seventh step, when starting the ntp service, first manually synchronize the local time, note that this is the time synchronization between the local NTP server and the public NTP server
root@kvm02:~# ntpdate -u ntp1.aliyun.com
17 Oct 23:01:57 ntpdate[32973]: adjust time server 120.25.115.20 offset 0.002540 sec
The eighth step is to check whether the ntp synchronization time is started. If the execution result of the following command appears, it means that the synchronization time is started successfully
root@kvm02:~# ntpstat
synchronised to NTP server (120.25.115.20) at stratum 3
time correct to within 200 ms
polling server every 64 s
The ninth step, as an NTP server, you need to enable the ntp service in the firewall, otherwise the NTP client cannot synchronize the time
The ntp service uses dup port 123. By default, the Ubuntu firewall is turned off, and there is no restriction on the ntp service.
Linux client NTP configuration (blue font)
For details, see "KVM Virtualization Solution Series - KVM Deployment (1-3)"
Linux client and NTP server test (blue font)
For details, see "KVM Virtualization Solution Series - KVM Deployment (1-3)"
Win 10 client NTP configuration and NTP server test (blue font)
For details, see "KVM Virtualization Solution Series - KVM Deployment (1-3)"
So far, the NTP server and NTP client have been set up and can be used normally.