一、系統安裝操作步驟
准備工作
1.1 選擇安裝語言:
1.2 安裝界面選擇第一項進行系統安裝
1.3 選擇安裝過程中使用的語言,也是系統安裝完后使用的默認語言
1.4 選擇地區,這里先選擇最后一項other,然后回車再選擇Asia,最后選擇China
1.5 選擇語言環境
1.6 鍵盤布局檢查,選擇NO
1.7 選擇美式鍵盤
1.8 確認使用美式鍵盤
1.9 配置主機名
1.10 創建一個普通用戶和為其設置密碼
1.11 確認時區
1.12 選擇磁盤分區的方法,這里選手動分區
1.13 選擇磁盤
1.14 確認對磁盤分區
1.15 對磁盤進行分區
1.16 創建新分區
1.17 指定分區大小,這里將磁盤的全部大小划分給該分區
1.18 選擇分區類型,這里選主分區
1.19 分區完成
1.20 完成分區並寫入數據
1.21 確認寫入磁盤
1.22 是否使用代理,不填
1.23 是否自動更新,這里選擇默認,不自動更新
1.24 選擇安裝組件,選擇對應需要安裝的組件,然后按空格鍵,通常選擇OpenSSH Server 方便遠程連接,如果忘記選也可以進系統在線安裝
1.25 將GRUB引導加載程序安裝到主引導記錄
1.26 完成安裝,確認重啟服務器
1.27 登錄系統
二、 系統基礎配置
2.1 更改主機名
# cat /etc/hostname hechunping
2.2 更改網卡名稱為eth*
# sed -i '/GRUB_CMDLINE_LINUX=/s/"$/net.ifnames=0 biosdevname=0"/' /etc/default/grub # update-grub Sourcing file `/etc/default/grub' Generating grub configuration file ... Found linux image: /boot/vmlinuz-4.15.0-55-generic Found initrd image: /boot/initrd.img-4.15.0-55-generic done # reboot # sed -i 's/ens33/eth0/' /etc/netplan/01-netcfg.yaml
2.3 配置root遠程登錄
# 默認情況下,ubuntu不允許root⽤⼾遠程ssh,如果有實際場景需要允許root⽤⼾遠程ssh,則需要設置root密碼,並且編輯/etc/ssh/sshd_config⽂件修改如下: ~$ sudo vim /etc/ssh/sshd_config 32 #PermitRootLogin prohibit-password #默認為禁⽌登錄 33 PermitRootLogin yes #改為允許登錄 57 #PasswordAuthentication yes 58 PasswordAuthentication yes #打開密碼認證,其實默認就是允許通過密碼認證登錄 ~$ sudo su - root #切換到root⽤⼾環境 ~# passwd #設置密碼 Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully ~# systemctl restart sshd #重啟ssh服務並測試root⽤⼾遠程ssh連接
2.4 網絡配置
官方文檔:https://netplan.io/ Ubuntu 從 17.10 開始,已放棄在 /etc/network/interfaces ⾥固定IP的配置,⽽是改成 netplan ⽅式,配置⽂件是:/etc/netplan/01-netcfg.yaml 單網卡靜態IP地址配置詳細見https://mefj.com.cn/lur1220.html # ubuntu 17.04及之前的靜態IP配置⽅式: ~# cat /etc/network/interfaces root@hechunping:~# cat /etc/network/interfaces # interfaces(5) file used by ifup(8) and ifdown(8) auto lo iface lo inet loopback auto eth0 #⽹卡⾃啟動,寫⾃⼰要配置IP的實際⽹卡名稱 iface eth0 inet static #配置靜態IP,寫⾃⼰要配置IP的實際⽹卡名稱 address 172.18.3.12 #IP地址 netmask 255.255.0.0 #掩碼 gateway 172.18.0.1 #⽹關 dns-nameservers 223.6.6.6 #DNS dns-nameservers 223.5.5.5 #重啟⽹絡服務 ~# /etc/init.d/networking restart ~# systemctl restart networking.service
2.4.1 配置多網卡靜態IP
# cat /etc/netplan/01-netcfg.yaml
# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
version: 2
renderer: networkd
ethernets:
eth0:
dhcp4: no
addresses: [172.20.7.34/16]
gateway4: 172.20.0.1
nameservers:
addresses: [223.6.6.6]
eth1:
dhcp4: no
addresses: [192.168.7.34/24]
routes:
- to: 172.20.0.0/16
via: 192.168.7.2
# netplan apply
2.4.2 單網卡橋接
# cat /etc/netplan/01-netcfg.yaml
# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
version: 2
renderer: networkd
ethernets:
eth0:
dhcp4: no
bridges:
br0:
dhcp4: no
addresses: [172.20.7.34/16]
gateway4: 172.20.0.1
nameservers:
addresses: [223.6.6.6]
interfaces:
- eth0
# netplan apply
2.4.3 多網卡橋接
將br0和br1分別橋接到eth0和eth1。
# cat /etc/netplan/01-netcfg.yaml
# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
version: 2
renderer: networkd
ethernets:
eth0:
dhcp4: no
eth1:
dhcp4: no
bridges:
br0:
dhcp4: no
addresses: [172.20.7.34/16]
gateway4: 172.20.0.1
nameservers:
addresses: [223.6.6.6]
interfaces:
- eth0
br1:
dhcp4: no
addresses: [192.168.7.34/24]
routes:
- to: 172.20.0.0/16
via: 192.168.7.2
interfaces:
- eth1
root@hechunping:~# netplan apply
2.4.4 雙網卡綁定
需要提前安裝好bridge命令,兩塊網卡使用同一種網絡模式
# cat /etc/netplan/01-netcfg.yaml
# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
version: 2
renderer: networkd
ethernets:
eth0:
dhcp4: no
eth1:
dhcp4: no
bonds:
bond0:
interfaces:
- eth0
- eth1
addresses: [172.20.7.34/16]
gateway4: 172.20.0.1
nameservers:
addresses: [223.6.6.6,223.5.5.5]
parameters:
mode: active-backup
mii-monitor-interval: 100
# poweroff
# netplan apply
2.4.5 雙網卡綁定+橋接
⽹卡綁定⽤於提供⽹卡接⼝冗余以及⾼可⽤和端⼝聚合功能,橋接⽹卡再給需要橋接設備的服務使⽤。
# cat /etc/netplan/01-netcfg.yaml
# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
version: 2
renderer: networkd
ethernets:
eth0:
dhcp4: no
eth1:
dhcp4: no
bonds:
bond0:
interfaces:
- eth0
- eth1
parameters:
mode: active-backup
mii-monitor-interval: 100
bridges:
br0:
dhcp4: no
addresses: [172.20.7.34/16]
gateway4: 172.20.0.1
nameservers:
addresses: [223.6.6.6,223.5.5.5]
interfaces:
- bond0
# netplan apply
2.4.6 內外多網卡綁定
多⽹絡情況下實現⽹卡綁定。這里使用橋接(eth0,eth1)和NAT(eth2,eth3)兩種網絡模式
# cat /etc/netplan/01-netcfg.yaml
# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
version: 2
renderer: networkd
ethernets:
eth0:
dhcp4: no
eth1:
dhcp4: no
eth2:
dhcp4: no
eth3:
dhcp4: no
bonds:
bond0:
interfaces:
- eth0
- eth1
addresses: [172.20.7.34/16]
gateway4: 172.20.0.1
nameservers:
addresses: [223.6.6.6,223.5.5.5]
parameters:
mode: active-backup
mii-monitor-interval: 100
bond1:
interfaces:
- eth2
- eth3
addresses: [192.168.7.34/24]
parameters:
mode: active-backup
mii-monitor-interval: 100
routes:
- to: 172.20.0.0/16
via: 192.168.7.2
# netplan apply
2.4.7 內外多網卡綁定+橋接
# cat /etc/netplan/01-netcfg.yaml
# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
version: 2
renderer: networkd
ethernets:
eth0:
dhcp4: no
eth1:
dhcp4: no
eth2:
dhcp4: no
eth3:
dhcp4: no
bonds:
bond0:
interfaces:
- eth0
- eth1
parameters:
mode: active-backup
mii-monitor-interval: 100
bond1:
interfaces:
- eth2
- eth3
parameters:
mode: active-backup
mii-monitor-interval: 100
bridges:
br0:
dhcp4: no
addresses: [172.20.7.34/16]
gateway4: 172.20.0.1
nameservers:
addresses: [223.6.6.6,223.5.5.5]
interfaces:
- bond0
br1:
dhcp4: no
addresses: [192.168.7.34/24]
routes:
- to: 172.20.0.0/16
via: 192.168.7.2
interfaces:
- bond1
# netplan apply
三、 軟件包管理
3.1 修改軟件倉庫地址
阿⾥雲倉庫地址:https://developer.aliyun.com/mirror 中科⼤:http://mirrors.ustc.edu.cn/help/ubuntu.html 清華⼤學:https://mirror.tuna.tsinghua.edu.cn/help/ubuntu/ 華為:https://mirrors.huaweicloud.com/ ###### 清華源配置 ###### Ubuntu 的軟件源配置文件是 /etc/apt/sources.list。將系統自帶的該文件做個備份,將該文件替換為下面內容,即可使用 TUNA 的軟件源鏡像。 # cd /etc/apt/ # cp -p sources.list sources.list.bak # vim sources.list # 默認注釋了源碼鏡像以提高 apt update 速度,如有需要可自行取消注釋 deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse # 預發布軟件源,不建議啟用 # deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse # apt update #更新本地軟件包列表索引,修改了apt倉庫后必須執⾏ ###### 阿里源配置 ###### # sed -i 's/cn.archive.ubuntu/mirrors.aliyun/' /etc/apt/sources.list # apt update #更新本地軟件包列表索引,修改了apt倉庫后必須執⾏
3.2 apt工具使用
apt list #apt列出倉庫軟件包,等於yum list apt search NAME #搜索安裝包 apt show apache2 #查看某個安裝包的詳細信息 apt install apache2 #在線安裝軟件包 apt remove apache2 #卸載單個軟件包但是保留配置⽂件 apt autoremove apache2 #刪除安裝包並解決依賴關系 apt update #更新本地軟件包列表索引,修改了apt倉庫后必須執⾏ apt purge apache2 #卸載單個軟件包刪除配置⽂件 apt upgrade #升級所有已安裝且可升級到新版本的軟件包 apt full-upgrade #升級整個系統,必要時可以移除舊軟件包。 apt edit-sources #編輯source源⽂件 apt-cache madison nginx #查看倉庫中軟件包有哪些版本可以安裝 apt install nginx=1.14.0-0ubuntu1.6 #安裝軟件包的時候指定安裝具體的版本
