Ubuntu1804(サーバ版)インストールおよび使用

インストール手順1

OS Version:1804
镜像下载:http://cdimage.ubuntu.com/releases/

1.1インストール言語を選択:

Ubuntu1804(サーバ版)インストールおよび使用

1.2は、システムのインストールのために、第一の取付インターフェイスを選択しました

Ubuntu1804(サーバ版)インストールおよび使用

1.3インストール時に使用する言語、だけでなく、デフォルト言語を使用して、インストール後にシステムを選択します

Ubuntu1804(サーバ版)インストールおよび使用

1.4選択エリア、アジア、中国の最終的な選択を入力して選択し、他に、ここで最後の項目を選択し、

Ubuntu1804(サーバ版)インストールおよび使用
Ubuntu1804(サーバ版)インストールおよび使用
Ubuntu1804(サーバ版)インストールおよび使用

1.5ロケールの選択

Ubuntu1804(サーバ版)インストールおよび使用

1.6チェックキーボードレイアウトを選択NO

Ubuntu1804(サーバ版)インストールおよび使用

1.7 USキーボードを選択

Ubuntu1804(サーバ版)インストールおよび使用

USキーボードを使用して1.8の確認

Ubuntu1804(サーバ版)インストールおよび使用

1.9ホスト名の設定

Ubuntu1804(サーバ版)インストールおよび使用

1.10通常のユーザーを作成し、パスワードを設定します。

Ubuntu1804(サーバ版)インストールおよび使用
Ubuntu1804(サーバ版)インストールおよび使用
Ubuntu1804(サーバ版)インストールおよび使用
Ubuntu1804(サーバ版)インストールおよび使用
Ubuntu1804(サーバ版)インストールおよび使用

1.11確認のタイムゾーン

Ubuntu1804(サーバ版)インストールおよび使用

1.12プレイヤーがパーティションを移動するディスクパーティション方式を選択

Ubuntu1804(サーバ版)インストールおよび使用

[ディスク1.13

Ubuntu1804(サーバ版)インストールおよび使用

ディスクパーティションの1.14確認

Ubuntu1804(サーバ版)インストールおよび使用

1.15ペアのディスクパーティション

Ubuntu1804(サーバ版)インストールおよび使用

1.16は、新しいパーティションを作成します。

Ubuntu1804(サーバ版)インストールおよび使用

1.17パーティションのサイズを指定し、ディスクパーティションの合計サイズが割り当てられます

Ubuntu1804(サーバ版)インストールおよび使用

1.18プライマリパーティション、プライマリパーティション選挙

Ubuntu1804(サーバ版)インストールおよび使用

1.19パーティションの完全な

Ubuntu1804(サーバ版)インストールおよび使用

完全なパーティションに1.20と書き込みデータ

Ubuntu1804(サーバ版)インストールおよび使用

ディスクに書き込まれた1.21の確認

Ubuntu1804(サーバ版)インストールおよび使用

1.22プロキシを使用するかどうか、ここに記入しません

Ubuntu1804(サーバ版)インストールおよび使用

1.23自動更新自動更新するかどうかを、ここではデフォルトを選択し、ありません

Ubuntu1804(サーバ版)インストールおよび使用

1.24選択しOpenSSHのサーバーを選択し、スペースキーを押して、対応するコンポーネントをインストールする必要が選択し、取付けアセンブリ、および

Ubuntu1804(サーバ版)インストールおよび使用

1.25 GRUBブートローダは、マスターブートレコードにインストールされます

Ubuntu1804(サーバ版)インストールおよび使用

1.26インストールを完了するために、サーバの再起動確認

Ubuntu1804(サーバ版)インストールおよび使用

1.27ログ

Ubuntu1804(サーバ版)インストールおよび使用

2基本的なシステム構成

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

2.1ホスト名を変更

# cat /etc/hostname 
hechunping

2.2変更ETHへのNICの名前*

# 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コンフィギュレーション・ルートリモートログイン

# 默认情况下,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

# 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アドレス

root@hechunping:~# 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: [192.168.7.132/24]
      gateway4: 192.168.7.2
      nameservers:
        addresses: [223.6.6.6]
root@hechunping:~# netplan apply

2.4.2のconfigure複数のNICの静的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.3単一のカードブリッジ

# 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.4複数のネットワークブリッジ

将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.5デュアルNICチーミング

需要提前安装好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.6デュアルNICが+ブリッジをチーミング

⽹卡绑定⽤于提供⽹卡接⼝冗余以及⾼可⽤和端⼝聚合功能,桥接⽹卡再给需要桥接设备的服务使⽤。

# 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.7マルチNICチーミングの内側と外側

多⽹络情况下实现⽹卡绑定。这里使用桥接(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.8 +結合内部および外部のマルチネットワークアダプタをブリッジ

# 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パッケージ管理

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 #安装软件包的时候指定安装具体的版本

3.3 dpkgのインストールパッケージの管理

rpm:RPM(Red Hat Package Manager),是基于Red hat的Linux Distribution的包管理系统,同时也指rpm包本⾝,RPM⽤于rpm包的管理(诸如安装、卸载、升级等)
"dpkg "是"Debian Packager "的简写,为 "Debian"专⻔开发的套件管理系统,⽅便软件的安装、更新及移除。所有源⾃“Debian”的“Linux ”发⾏版都使⽤ “dpkg”,例如 “Ubuntu”、“Knoppix ”等。

dpkg -i gitlab-ce_11.9.8-ce.0_amd64.deb #安装某个软件包
dpkg -r gitlab-ce #删除某个软件包保留配置⽂件
dpkg -r -P gitlab-ce #删除某个软件包不保留配置⽂件
dpkg -I gitlab-ce_11.9.8-ce.0_amd64.deb #查看软件包信息
dpkg -c gitlab-ce_11.9.8-ce.0_amd64.deb #查看软件包内的⽂件及⽬录内容
dpkg -l #列出本机已经安装的所有软件

設定されたOracle JDK 3.4環境

# pwd
/usr/local/src
解压⼆进制⽂件并设置软连接:
# tar xf jdk-8u212-linux-x64.tar.gz
# ln -sv /usr/local/src/jdk1.8.0_212 /usr/local/jdk
配置环境变量:
# vim /etc/profile
export JAVA_HOME=/usr/local/jdk
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH
export CLASSPATH=.$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$JAVA_HOME/lib/tools.jar
重新导⼊环境变量并验证:
# source /etc/profile
# java -version
java version "1.8.0_212"
Java(TM) SE Runtime Environment (build 1.8.0_212-b10)
Java HotSpot(TM) 64-Bit Server VM (build 25.212-b10, mixed mode)

3.5インストールのOpenJDK

# apt install openjdk-8-jdk

3.6インストール、使用頻度の高いシステムコマンド

# apt purge ufw lxd lxd-client lxcfs lxc-common
# apt install iproute2 ntpdate tcpdump telnet traceroute nfs-kernel-server nfs-common lrzsz tree openssl libssl-dev libpcre3 libpcre3-dev zlib1g-dev ntpdate tcpdump telnet traceroute gcc openssh-server lrzsz tree openssl libssl-dev libpcre3 libpcre3-dev zlib1g-dev ntpdate tcpdump telnet traceroute iotop unzip zip

システムリソース制限の3.7最適化

#cat /etc/security/limits.conf
#root账⼾的资源软限制和硬限制
root soft core unlimited
root hard core unlimited
root soft nproc 1000000
root hard nproc 1000000
root soft nofile 1000000
root hard nofile 1000000
root soft memlock 32000
root hard memlock 32000
root soft msgqueue 8192000
root hard msgqueue 8192000
#其他账⼾的资源软限制和硬限制
* soft core unlimited
* hard core unlimited
* soft nproc 1000000
* hard nproc 1000000
* soft nofile 1000000
* hard nofile 1000000
* soft memlock 32000
* hard memlock 32000
* soft msgqueue 8192000
* hard msgqueue 8192000

3.8eカーネルパラメータの最適化

# Controls source route verification
net.ipv4.conf.default.rp_filter = 1
net.ipv4.ip_nonlocal_bind = 1
net.ipv4.ip_forward = 1
# Do not accept source routing
net.ipv4.conf.default.accept_source_route = 0
# Controls the System Request debugging functionality of the kernel
kernel.sysrq = 0
# Controls whether core dumps will append the PID to the core filename.
# Useful for debugging multi-threaded applications.
kernel.core_uses_pid = 1
# Controls the use of TCP syncookies
net.ipv4.tcp_syncookies = 1
# Disable netfilter on bridges.
net.bridge.bridge-nf-call-ip6tables = 0
net.bridge.bridge-nf-call-iptables = 0
net.bridge.bridge-nf-call-arptables = 0
# Controls the default maxmimum size of a mesage queue
kernel.msgmnb = 65536
# # Controls the maximum size of a message, in bytes
kernel.msgmax = 65536
# Controls the maximum shared segment size, in bytes
kernel.shmmax = 68719476736
# # Controls the maximum number of shared memory segments, in pages
kernel.shmall = 4294967296
# TCP kernel paramater
net.ipv4.tcp_mem = 786432 1048576 1572864
net.ipv4.tcp_rmem = 4096 87380 4194304
net.ipv4.tcp_wmem = 4096 16384 4194304
net.ipv4.tcp_window_scaling = 1
net.ipv4.tcp_sack = 1
# socket buffer
net.core.wmem_default = 8388608
net.core.rmem_default = 8388608
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.core.netdev_max_backlog = 262144
net.core.somaxconn = 20480
net.core.optmem_max = 81920
# TCP conn
net.ipv4.tcp_max_syn_backlog = 262144
net.ipv4.tcp_syn_retries = 3
net.ipv4.tcp_retries1 = 3
net.ipv4.tcp_retries2 = 15
# tcp conn reuse
net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_tw_reuse = 0
net.ipv4.tcp_tw_recycle = 0
net.ipv4.tcp_fin_timeout = 1
net.ipv4.tcp_max_tw_buckets = 20000
net.ipv4.tcp_max_orphans = 3276800
net.ipv4.tcp_synack_retries = 1
net.ipv4.tcp_syncookies = 1
# keepalive conn
net.ipv4.tcp_keepalive_time = 300
net.ipv4.tcp_keepalive_intvl = 30
net.ipv4.tcp_keepalive_probes = 3
net.ipv4.ip_local_port_range = 10001 65000
# swap
vm.overcommit_memory = 0
vm.swappiness = 10
#net.ipv4.conf.eth1.rp_filter = 0
#net.ipv4.conf.lo.arp_ignore = 1
#net.ipv4.conf.lo.arp_announce = 2
#net.ipv4.conf.all.arp_ignore = 1
#net.ipv4.conf.all.arp_announce = 2

おすすめ

転載: blog.51cto.com/hexiaoshuai/2462800