Ubuntu18.04 Server版安装(详细版)

  • A+
所属分类:Linux基础

一、系统安装操作步骤

准备工作

镜像下载:官网下载 或者 网盘下载

1.1 选择安装语言:

Ubuntu18.04 Server版安装(详细版)

1.2 安装界面选择第一项进行系统安装

Ubuntu18.04 Server版安装(详细版)

1.3 选择安装过程中使用的语言,也是系统安装完后使用的默认语言

Ubuntu18.04 Server版安装(详细版)

1.4 选择地区,这里先选择最后一项other,然后回车再选择Asia,最后选择China

Ubuntu18.04 Server版安装(详细版)
Ubuntu18.04 Server版安装(详细版)
Ubuntu18.04 Server版安装(详细版)

1.5 选择语言环境

Ubuntu18.04 Server版安装(详细版)

1.6 键盘布局检查,选择NO

Ubuntu18.04 Server版安装(详细版)

1.7 选择美式键盘

Ubuntu18.04 Server版安装(详细版)

1.8 确认使用美式键盘

Ubuntu18.04 Server版安装(详细版)

1.9 配置主机名

Ubuntu18.04 Server版安装(详细版)

1.10 创建一个普通用户和为其设置密码

Ubuntu18.04 Server版安装(详细版)
Ubuntu18.04 Server版安装(详细版)
Ubuntu18.04 Server版安装(详细版)

1.11 确认时区

Ubuntu18.04 Server版安装(详细版)

1.12 选择磁盘分区的方法,这里选手动分区

Ubuntu18.04 Server版安装(详细版)

1.13 选择磁盘

Ubuntu18.04 Server版安装(详细版)

1.14 确认对磁盘分区

Ubuntu18.04 Server版安装(详细版)

1.15 对磁盘进行分区

Ubuntu18.04 Server版安装(详细版)

1.16 创建新分区

Ubuntu18.04 Server版安装(详细版)

1.17 指定分区大小,这里将磁盘的全部大小划分给该分区

Ubuntu18.04 Server版安装(详细版)

1.18 选择分区类型,这里选主分区

Ubuntu18.04 Server版安装(详细版)

1.19 分区完成

Ubuntu18.04 Server版安装(详细版)

1.20 完成分区并写入数据

Ubuntu18.04 Server版安装(详细版)

1.21 确认写入磁盘

Ubuntu18.04 Server版安装(详细版)

1.22 是否使用代理,不填

Ubuntu18.04 Server版安装(详细版)

1.23 是否自动更新,这里选择默认,不自动更新

Ubuntu18.04 Server版安装(详细版)

1.24 选择安装组件,选择对应需要安装的组件,然后按空格键,通常选择OpenSSH Server 方便远程连接,如果忘记选也可以进系统在线安装

Ubuntu18.04 Server版安装(详细版)

1.25 将GRUB引导加载程序安装到主引导记录

Ubuntu18.04 Server版安装(详细版)

1.26 完成安装,确认重启服务器

Ubuntu18.04 Server版安装(详细版)
Ubuntu18.04 Server版安装(详细版)

1.27 登录系统

Ubuntu18.04 Server版安装(详细版)
Ubuntu18.04 Server版安装(详细版)

二、 系统基础配置

官方文档:https://help.ubuntu.com/

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 #安装软件包的时候指定安装具体的版本
  • 微信公众号
  • 扫一扫关注微信公众号
  • weinxin
  • 运维交流群
  • 扫一扫二维码加入群聊
  • weinxin

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: