系统城装机大师 - 固镇县祥瑞电脑科技销售部宣传站!

当前位置:首页 > 系统教程 > Linux教程 > 详细页面

Ubuntu18.04 Server版安装及使用(图文)

时间:2019-12-30来源:系统城作者:电脑系统城

1 系统安装操作步骤

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

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 系统基础配置

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

2.1 更改主机名


 
  1. # cat /etc/hostname
  2. hechunping

2.2 更改网卡名称为eth*


 
  1. # sed -i '/GRUB_CMDLINE_LINUX=/s/"$/net.ifnames=0 biosdevname=0"/' /etc/default/grub
  2. # update-grub
  3. Sourcing file `/etc/default/grub'
  4. Generating grub configuration file ...
  5. Found linux image: /boot/vmlinuz-4.15.0-55-generic
  6. Found initrd image: /boot/initrd.img-4.15.0-55-generic
  7. done
  8. # reboot
  9. # sed -i 's/ens33/eth0/' /etc/netplan/01-netcfg.yaml

2.3 配置root远程登录


 
  1. # 默认情况下,ubuntu不允许root⽤⼾远程ssh,如果有实际场景需要允许root⽤⼾远程ssh,则需要设置root密码,并且编辑/etc/ssh/sshd_config⽂件修改如下:
  2. ~$ sudo vim /etc/ssh/sshd_config
  3. 32 #PermitRootLogin prohibit-password #默认为禁⽌登录
  4. 33 PermitRootLogin yes #改为允许登录
  5.  
  6. 57 #PasswordAuthentication yes
  7. 58 PasswordAuthentication yes #打开密码认证,其实默认就是允许通过密码认证登录
  8.  
  9. ~$ sudo su - root #切换到root⽤⼾环境
  10. ~# passwd #设置密码
  11. Enter new UNIX password:
  12. Retype new UNIX password:
  13. passwd: password updated successfully
  14. ~# systemctl restart sshd #重启ssh服务并测试root⽤⼾远程ssh连接

2.4 网络配置


 
  1. 官方文档:https://netplan.io/
  2.  
  3. Ubuntu 从 17.10 开始,已放弃在 /etc/network/interfaces ⾥固定IP的配置,⽽是改成 netplan ⽅式,配置⽂件是:/etc/netplan/01-netcfg.yaml
  4.  
  5. # ubuntu 17.04及之前的静态IP配置⽅式:
  6. ~# cat /etc/network/interfaces
  7. root@hechunping:~# cat /etc/network/interfaces
  8. # interfaces(5) file used by ifup(8) and ifdown(8)
  9. auto lo
  10. iface lo inet loopback
  11. auto eth0 #⽹卡⾃启动,写⾃⼰要配置IP的实际⽹卡名称
  12. iface eth0 inet static #配置静态IP,写⾃⼰要配置IP的实际⽹卡名称
  13. address 172.18.3.12 #IP地址
  14. netmask 255.255.0.0 #掩码
  15. gateway 172.18.0.1 #⽹关
  16. dns-nameservers 223.6.6.6 #DNS
  17. dns-nameservers 223.5.5.5
  18. #重启⽹络服务
  19. ~# /etc/init.d/networking restart
  20. ~# systemctl restart networking.service

2.4.1 单网卡静态IP地址


 
  1. root@hechunping:~# cat /etc/netplan/01-netcfg.yaml
  2. # This file describes the network interfaces available on your system
  3. # For more information, see netplan(5).
  4. network:
  5. version: 2
  6. renderer: networkd
  7. ethernets:
  8. eth0:
  9. dhcp4: no
  10. addresses: [192.168.7.132/24]
  11. gateway4: 192.168.7.2
  12. nameservers:
  13. addresses: [223.6.6.6]
  14. root@hechunping:~# netplan apply

2.4.2 配置多网卡静态IP


 
  1. # cat /etc/netplan/01-netcfg.yaml
  2. # This file describes the network interfaces available on your system
  3. # For more information, see netplan(5).
  4. network:
  5. version: 2
  6. renderer: networkd
  7. ethernets:
  8. eth0:
  9. dhcp4: no
  10. addresses: [172.20.7.34/16]
  11. gateway4: 172.20.0.1
  12. nameservers:
  13. addresses: [223.6.6.6]
  14. eth1:
  15. dhcp4: no
  16. addresses: [192.168.7.34/24]
  17. routes:
  18. - to: 172.20.0.0/16
  19. via: 192.168.7.2
  20. # netplan apply

2.4.3 单网卡桥接


 
  1. # cat /etc/netplan/01-netcfg.yaml
  2. # This file describes the network interfaces available on your system
  3. # For more information, see netplan(5).
  4. network:
  5. version: 2
  6. renderer: networkd
  7. ethernets:
  8. eth0:
  9. dhcp4: no
  10. bridges:
  11. br0:
  12. dhcp4: no
  13. addresses: [172.20.7.34/16]
  14. gateway4: 172.20.0.1
  15. nameservers:
  16. addresses: [223.6.6.6]
  17. interfaces:
  18. - eth0
  19. # netplan apply

2.4.4 多网卡桥接


 
  1. 将br0和br1分别桥接到eth0和eth1。
  2. # cat /etc/netplan/01-netcfg.yaml
  3. # This file describes the network interfaces available on your system
  4. # For more information, see netplan(5).
  5. network:
  6. version: 2
  7. renderer: networkd
  8. ethernets:
  9. eth0:
  10. dhcp4: no
  11. eth1:
  12. dhcp4: no
  13. bridges:
  14. br0:
  15. dhcp4: no
  16. addresses: [172.20.7.34/16]
  17. gateway4: 172.20.0.1
  18. nameservers:
  19. addresses: [223.6.6.6]
  20. interfaces:
  21. - eth0
  22. br1:
  23. dhcp4: no
  24. addresses: [192.168.7.34/24]
  25. routes:
  26. - to: 172.20.0.0/16
  27. via: 192.168.7.2
  28. interfaces:
  29. - eth1
  30. root@hechunping:~# netplan apply

2.4.5 双网卡绑定


 
  1. 需要提前安装好bridge命令,两块网卡使用同一种网络模式
  2. # cat /etc/netplan/01-netcfg.yaml
  3. # This file describes the network interfaces available on your system
  4. # For more information, see netplan(5).
  5. network:
  6. version: 2
  7. renderer: networkd
  8. ethernets:
  9. eth0:
  10. dhcp4: no
  11. eth1:
  12. dhcp4: no
  13. bonds:
  14. bond0:
  15. interfaces:
  16. - eth0
  17. - eth1
  18. addresses: [172.20.7.34/16]
  19. gateway4: 172.20.0.1
  20. nameservers:
  21. addresses: [223.6.6.6,223.5.5.5]
  22. parameters:
  23. mode: active-backup
  24. mii-monitor-interval: 100
  25. # poweroff
  26. # netplan apply

2.4.6 双网卡绑定+桥接


 
  1. ⽹卡绑定⽤于提供⽹卡接⼝冗余以及⾼可⽤和端⼝聚合功能,桥接⽹卡再给需要桥接设备的服务使⽤。
  2.  
  3. # cat /etc/netplan/01-netcfg.yaml
  4. # This file describes the network interfaces available on your system
  5. # For more information, see netplan(5).
  6. network:
  7. version: 2
  8. renderer: networkd
  9. ethernets:
  10. eth0:
  11. dhcp4: no
  12. eth1:
  13. dhcp4: no
  14. bonds:
  15. bond0:
  16. interfaces:
  17. - eth0
  18. - eth1
  19. parameters:
  20. mode: active-backup
  21. mii-monitor-interval: 100
  22. bridges:
  23. br0:
  24. dhcp4: no
  25. addresses: [172.20.7.34/16]
  26. gateway4: 172.20.0.1
  27. nameservers:
  28. addresses: [223.6.6.6,223.5.5.5]
  29. interfaces:
  30. - bond0
  31. # netplan apply

2.4.7 内外多网卡绑定


 
  1. 多⽹络情况下实现⽹卡绑定。这里使用桥接(eth0,eth1)和NAT(eth2,eth3)两种网络模式
  2. # cat /etc/netplan/01-netcfg.yaml
  3. # This file describes the network interfaces available on your system
  4. # For more information, see netplan(5).
  5. network:
  6. version: 2
  7. renderer: networkd
  8. ethernets:
  9. eth0:
  10. dhcp4: no
  11. eth1:
  12. dhcp4: no
  13. eth2:
  14. dhcp4: no
  15. eth3:
  16. dhcp4: no
  17. bonds:
  18. bond0:
  19. interfaces:
  20. - eth0
  21. - eth1
  22. addresses: [172.20.7.34/16]
  23. gateway4: 172.20.0.1
  24. nameservers:
  25. addresses: [223.6.6.6,223.5.5.5]
  26. parameters:
  27. mode: active-backup
  28. mii-monitor-interval: 100
  29.  
  30. bond1:
  31. interfaces:
  32. - eth2
  33. - eth3
  34. addresses: [192.168.7.34/24]
  35. parameters:
  36. mode: active-backup
  37. mii-monitor-interval: 100
  38. routes:
  39. - to: 172.20.0.0/16
  40. via: 192.168.7.2
  41. # netplan apply

2.4.8 内外多网卡绑定+桥接


 
  1. # cat /etc/netplan/01-netcfg.yaml
  2. # This file describes the network interfaces available on your system
  3. # For more information, see netplan(5).
  4. network:
  5. version: 2
  6. renderer: networkd
  7. ethernets:
  8. eth0:
  9. dhcp4: no
  10. eth1:
  11. dhcp4: no
  12. eth2:
  13. dhcp4: no
  14. eth3:
  15. dhcp4: no
  16. bonds:
  17. bond0:
  18. interfaces:
  19. - eth0
  20. - eth1
  21. parameters:
  22. mode: active-backup
  23. mii-monitor-interval: 100
  24.  
  25. bond1:
  26. interfaces:
  27. - eth2
  28. - eth3
  29. parameters:
  30. mode: active-backup
  31. mii-monitor-interval: 100
  32. bridges:
  33. br0:
  34. dhcp4: no
  35. addresses: [172.20.7.34/16]
  36. gateway4: 172.20.0.1
  37. nameservers:
  38. addresses: [223.6.6.6,223.5.5.5]
  39. interfaces:
  40. - bond0
  41. br1:
  42. dhcp4: no
  43. addresses: [192.168.7.34/24]
  44. routes:
  45. - to: 172.20.0.0/16
  46. via: 192.168.7.2
  47. interfaces:
  48. - bond1
  49. # netplan apply

3 软件包管理

3.1 修改软件仓库地址


 
  1. 阿⾥云仓库地址:https://developer.aliyun.com/mirror
  2. 中科⼤:http://mirrors.ustc.edu.cn/help/ubuntu.html
  3. 清华⼤学:https://mirror.tuna.tsinghua.edu.cn/help/ubuntu/
  4. 华为:https://mirrors.huaweicloud.com/
  5.  
  6. ###### 清华源配置 ######
  7. Ubuntu 的软件源配置文件是 /etc/apt/sources.list。将系统自带的该文件做个备份,将该文件替换为下面内容,即可使用 TUNA 的软件源镜像。
  8. # cd /etc/apt/
  9. # cp -p sources.list sources.list.bak
  10. # vim sources.list
  11. # 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
  12. deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
  13. # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
  14. deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
  15. # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
  16. deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
  17. # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
  18. deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
  19. # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
  20.  
  21. # 预发布软件源,不建议启用
  22. # deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
  23. # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
  24. # apt update #更新本地软件包列表索引,修改了apt仓库后必须执⾏
  25.  
  26. ###### 阿里源配置 ######
  27. # sed -i 's/cn.archive.ubuntu/mirrors.aliyun/' /etc/apt/sources.list
  28. # apt update #更新本地软件包列表索引,修改了apt仓库后必须执⾏

3.2 apt工具使用


 
  1. apt list #apt列出仓库软件包,等于yum list
  2. apt search NAME #搜索安装包
  3. apt show apache2 #查看某个安装包的详细信息
  4. apt install apache2 #在线安装软件包
  5. apt remove apache2 #卸载单个软件包但是保留配置⽂件
  6. apt autoremove apache2 #删除安装包并解决依赖关系
  7. apt update #更新本地软件包列表索引,修改了apt仓库后必须执⾏
  8. apt purge apache2 #卸载单个软件包删除配置⽂件
  9. apt upgrade #升级所有已安装且可升级到新版本的软件包
  10. apt full-upgrade #升级整个系统,必要时可以移除旧软件包。
  11. apt edit-sources #编辑source源⽂件
  12. apt-cache madison nginx #查看仓库中软件包有哪些版本可以安装
  13. apt install nginx=1.14.0-0ubuntu1.6 #安装软件包的时候指定安装具体的版本

3.3 dpkg安装包管理


 
  1. rpm:RPM(Red Hat Package Manager),是基于Red hat的Linux Distribution的包管理系统,同时也指rpm包本⾝,RPM⽤于rpm包的管理(诸如安装、卸载、升级等)
  2. "dpkg "是"Debian Packager "的简写,为 "Debian"专⻔开发的套件管理系统,⽅便软件的安装、更新及移除。所有源⾃“Debian”的“Linux ”发⾏版都使⽤ “dpkg”,例如 “Ubuntu”、“Knoppix ”等。
  3.  
  4. dpkg -i gitlab-ce_11.9.8-ce.0_amd64.deb #安装某个软件包
  5. dpkg -r gitlab-ce #删除某个软件包保留配置⽂件
  6. dpkg -r -P gitlab-ce #删除某个软件包不保留配置⽂件
  7. dpkg -I gitlab-ce_11.9.8-ce.0_amd64.deb #查看软件包信息
  8. dpkg -c gitlab-ce_11.9.8-ce.0_amd64.deb #查看软件包内的⽂件及⽬录内容
  9. dpkg -l #列出本机已经安装的所有软件

3.4 设置oracle JDK环境


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

3.5 安装OpenJDK


 
  1. # apt install openjdk-8-jdk

3.6 安装常⽤系统命令


 
  1. # apt purge ufw lxd lxd-client lxcfs lxc-common
  2. # 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 系统资源限制优化


 
  1. #cat /etc/security/limits.conf
  2. #root账⼾的资源软限制和硬限制
  3. root soft core unlimited
  4. root hard core unlimited
  5. root soft nproc 1000000
  6. root hard nproc 1000000
  7. root soft nofile 1000000
  8. root hard nofile 1000000
  9. root soft memlock 32000
  10. root hard memlock 32000
  11. root soft msgqueue 8192000
  12. root hard msgqueue 8192000
  13. #其他账⼾的资源软限制和硬限制
  14. * soft core unlimited
  15. * hard core unlimited
  16. * soft nproc 1000000
  17. * hard nproc 1000000
  18. * soft nofile 1000000
  19. * hard nofile 1000000
  20. * soft memlock 32000
  21. * hard memlock 32000
  22. * soft msgqueue 8192000
  23. * hard msgqueue 8192000

3.8e 内核参数优化


 
  1. # Controls source route verification
  2. net.ipv4.conf.default.rp_filter = 1
  3. net.ipv4.ip_nonlocal_bind = 1
  4. net.ipv4.ip_forward = 1
  5. # Do not accept source routing
  6. net.ipv4.conf.default.accept_source_route = 0
  7. # Controls the System Request debugging functionality of the kernel
  8. kernel.sysrq = 0
  9. # Controls whether core dumps will append the PID to the core filename.
  10. # Useful for debugging multi-threaded applications.
  11. kernel.core_uses_pid = 1
  12. # Controls the use of TCP syncookies
  13. net.ipv4.tcp_syncookies = 1
  14. # Disable netfilter on bridges.
  15. net.bridge.bridge-nf-call-ip6tables = 0
  16. net.bridge.bridge-nf-call-iptables = 0
  17. net.bridge.bridge-nf-call-arptables = 0
  18. # Controls the default maxmimum size of a mesage queue
  19. kernel.msgmnb = 65536
  20. # # Controls the maximum size of a message, in bytes
  21. kernel.msgmax = 65536
  22. # Controls the maximum shared segment size, in bytes
  23. kernel.shmmax = 68719476736
  24. # # Controls the maximum number of shared memory segments, in pages
  25. kernel.shmall = 4294967296
  26. # TCP kernel paramater
  27. net.ipv4.tcp_mem = 786432 1048576 1572864
  28. net.ipv4.tcp_rmem = 4096 87380 4194304
  29. net.ipv4.tcp_wmem = 4096 16384 4194304
  30. net.ipv4.tcp_window_scaling = 1
  31. net.ipv4.tcp_sack = 1
  32. # socket buffer
  33. net.core.wmem_default = 8388608
  34. net.core.rmem_default = 8388608
  35. net.core.rmem_max = 16777216
  36. net.core.wmem_max = 16777216
  37. net.core.netdev_max_backlog = 262144
  38. net.core.somaxconn = 20480
  39. net.core.optmem_max = 81920
  40. # TCP conn
  41. net.ipv4.tcp_max_syn_backlog = 262144
  42. net.ipv4.tcp_syn_retries = 3
  43. net.ipv4.tcp_retries1 = 3
  44. net.ipv4.tcp_retries2 = 15
  45. # tcp conn reuse
  46. net.ipv4.tcp_timestamps = 0
  47. net.ipv4.tcp_tw_reuse = 0
  48. net.ipv4.tcp_tw_recycle = 0
  49. net.ipv4.tcp_fin_timeout = 1
  50. net.ipv4.tcp_max_tw_buckets = 20000
  51. net.ipv4.tcp_max_orphans = 3276800
  52. net.ipv4.tcp_synack_retries = 1
  53. net.ipv4.tcp_syncookies = 1
  54. # keepalive conn
  55. net.ipv4.tcp_keepalive_time = 300
  56. net.ipv4.tcp_keepalive_intvl = 30
  57. net.ipv4.tcp_keepalive_probes = 3
  58. net.ipv4.ip_local_port_range = 10001 65000
  59. # swap
  60. vm.overcommit_memory = 0
  61. vm.swappiness = 10
  62. #net.ipv4.conf.eth1.rp_filter = 0
  63. #net.ipv4.conf.lo.arp_ignore = 1
  64. #net.ipv4.conf.lo.arp_announce = 2
  65. #net.ipv4.conf.all.arp_ignore = 1
  66. #net.ipv4.conf.all.arp_announce = 2

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我们。

分享到:

相关信息

  • linux定时关机设置教程

    当linux在运作时不能直接关闭电源容易将档案系统损毁,因此需要用shutdown以安全的方式关闭,那么这个操作该怎么实现呢?下面就为大家带来了详细教程。...

    2022-11-07

  • linux强制删除文件教程

    由于linux系统和我们常用的windows系统是不一样的,所以如果是初学者,可能会不知道linux怎么强制删除文件,其实我们只要打开终端,使用命令就可以删除了。...

    2022-11-03

系统教程栏目

栏目热门教程

人气教程排行

站长推荐

热门系统下载