Ubantu基础设置以及多网卡绑定

2024-03-01 16:30

本文主要是介绍Ubantu基础设置以及多网卡绑定,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

更改主机名称

~$ sudo -i
~# vim /etc/hostname
hosname
~# reboot

更改网卡名称为eth*

~$ sudo vim /etc/default/grub
GRUB_DEFAULT=0
GRUB_TIMEOUT_STYLE=hidden
GRUB_TIMEOUT=2
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT=""
GRUB_CMDLINE_LINUX="net.ifnames=0 biosdevname=0" #只要修改此项即可~$ sudo update-grub           #重新更新加载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
~$ sudo reboot        #重启

配置root远程登录

~$ sudo vim /etc/ssh/sshd_config
32 #PermitRootLogin prohibit-password #默认为禁⽌登录
33 PermitRootLogin yes                #改为允许登录57 #PasswordAuthentication yes
58 PasswordAuthentication yes         #打开密码认证,其实默认就是允许通过密码认证登录~$ sudo su - root                     #切换到root⽤⼾环境
~# passwd                             #设置root账号密码
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
~# systemctl restart sshd            #重启ssh服务并测试root⽤⼾远程ssh连接

查看ubantu版本

root@ubuntu1-server:~# cat /etc/issue
Ubuntu 18.04.3 LTS \n \lroot@ubuntu1-server:~# cat /proc/version
Linux version 4.15.0-55-generic (buildd@lcy01-amd64-029) (gcc version 7.4.0 
(Ubuntu 7.4.0-1ubuntu1~18.04.1)) 
#60-Ubuntu SMP Tue Jul 2 18:22:20 UTC 2019root@ubuntu1-server:~# uname -a
Linux ubuntu1-server 4.15.0-55-generic #60-Ubuntu SMP Tue Jul 2 18:22:20 UTC 2019 
x86_64 x86_64 x86_64 GNU/Linuxroot@ubuntu1-server:~# lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 18.04.3 LTS
Release:	18.04
Codename:	bionic
root@ubuntu1-server:~#

Ubuntu 18.04网络配置

Ubuntu 从 17.10 开始,已放弃在 /etc/network/interfaces ⾥固定IP的配置,⽽是改成 netplan ⽅式,
配置⽂件是:/etc/netplan/01-netcfg.yaml

ubuntu 17.04及之前的静态IP配置⽅式

~# cat /etc/network/interfaces
root@ubantu:~# 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.20.32.100  #IP地址
netmask 255.255.0.0  #掩码
gateway 172.20.0.1  #⽹关
dns-nameservers 223.6.6.6   #DNS
dns-nameservers 223.5.5.5
#重启⽹络服务
~# /etc/init.d/networking restart
~# systemctl restart networking.service

单网卡静态IP地址:

~#sudo vim /etc/netplan/01-netcfg.yaml
# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:version: 2renderer: networkdethernets:eth0:dhcp4: nodhcp6: noaddresses: [172.18.3.18/16]gateway4: 172.18.0.1nameservers:addresses: [223.6.6.6]
# sudo netplan apply

配置多网卡静态IP

~# sudo vim /etc/netplan/01-netcfg.yaml
# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:version: 2renderer: networkdethernets:eth0:dhcp4: nodhcp6: noaddresses: [172.18.3.18/16]gateway4: 172.18.0.1nameservers:addresses: [223.6.6.6]eth1:dhcp4: nodhcp6: noaddresses: [10.20.3.18/16]routes:- to: 172.20.0.0/16via: 10.20.0.1- to: 10.20.0.0/16via: 10.20.0.1- to: 10.2.0.0/16via: 10.20.0.1- to: 10.8.0.0/16via: 10.20.0.1
~# sudo netplan apply

单网卡桥接


~# sudo cat /etc/netplan/01-netcfg.yaml
# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:version: 2renderer: networkdethernets:eth0:dhcp4: nodhcp6: nobridges:br0:dhcp4: nodhcp6: noaddresses: [172.18.3.18/16]gateway4: 172.18.0.1nameservers:addresses: [223.6.6.6]interfaces:          #桥接在哪一个网卡  把br0桥接到eth0- eth0

多网卡桥接

ubuntu 18.04多⽹卡的桥接配置,将br0和br1分别桥接到eth0和eth1

~# sudo cat /etc/netplan/01-netcfg.yaml
# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:version: 2renderer: networkdethernets:eth0:dhcp4: nodhcp6: noeth1:dhcp4: nodhcp6: nobridges:br0:dhcp4: nodhcp6: noaddresses: [172.18.3.18/16]gateway4: 172.18.0.1nameservers:addresses: [223.6.6.6]interfaces:- eth0- br1:dhcp4: nodhcp6: noaddresses: [10.20.3.18/16]routes:- to: 172.20.0.0/16via: 10.20.0.1- to: 10.20.0.0/16via: 10.20.0.1- to: 10.2.0.0/16via: 10.20.0.1- to: 10.8.0.0/16via: 10.20.0.1interfaces:- eth1

双网卡绑定

七种bond模式说明
第⼀种模式:mod=0,即:(balance-rr) Round-robin policy(平衡抡循环策略)
特点:传输数据包顺序是依次传输(即:第1个包⾛eth0,下⼀个包就⾛eth1….⼀直循环下去,直到最后⼀个传输完
毕),此模式提供负载平衡和容错能⼒。第⼆种模式:mod=1,即: (active-backup) Active-backup policy(主-备份策略)
特点:只有⼀个设备处于活动状态,当⼀个宕掉另⼀个⻢上由备份转换为主设备。mac地址是外部可⻅得,从外⾯看
来,bond的MAC地址是唯⼀的,以避免switch(交换机)发⽣混乱。此模式只提供了容错能⼒;由此可⻅此算法的优点
是可以提供⾼⽹络连接的可⽤性,但是它的资源利⽤率较低,只有⼀个接⼝处于⼯作状态,在有 N 个⽹络接⼝的情况
下,资源利⽤率为1/N。第三种模式:mod=2,即:(balance-xor) XOR policy(平衡策略)
特点:基于指定的传输HASH策略传输数据包。缺省的策略是:(源MAC地址 XOR ⽬标MAC地址) % slave数量。其他
的传输策略可以通过xmit_hash_policy选项指定,此模式提供负载平衡和容错能⼒。第四种模式:mod=3,即:broadcast(⼴播策略)
特点:在每个slave接⼝上传输每个数据包,此模式提供了容错能⼒。第五种模式:mod=4,即:(802.3ad) IEEE 802.3adDynamic link aggregation(IEEE 802.3ad 动态链接
聚合)
特点:创建⼀个聚合组,它们共享同样的速率和双⼯设定。根据802.3ad规范将多个slave⼯作在同⼀个激活的聚合体
下。
必要条件:
条件1:ethtool⽀持获取每个slave的速率和双⼯设定。
条件2:switch(交换机)⽀持IEEE 802.3ad Dynamic link aggregation。
条件3:⼤多数switch(交换机)需要经过特定配置才能⽀持802.3ad模式。第六种模式:mod=5,即:(balance-tlb) Adaptive transmit load balancing(适配器传输负载均衡)
特点:不需要任何特别的switch(交换机)⽀持的通道bonding。在每个slave上根据当前的负载(根据速度计算)分
配外出流量。如果正在接受数据的slave出故障了,另⼀个slave接管失败的slave的MAC地址。
该模式的必要条件:
ethtool⽀持获取每个slave的速率
第七种模式:mod=6,即:(balance-alb) Adaptive load balancing(适配器适应性负载均衡)特点:该模式包含了balance-tlb模式,同时加上针对IPV4流量的接收负载均衡(receive load balance,rlb),⽽且不需要任何switch(交换机)的⽀持。
ubuntu 18.04的双网卡绑定配置

需要提前安装好bridge命令

~# sudo vim /etc/netplan/01-netcfg.yaml
# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:version: 2renderer: networkdethernets:eth0:dhcp4: nodhcp6: noeth1:dhcp4: nodhcp6: nobonds:bond0:interfaces:- eth0- eth1addresses: [172.18.3.18/16]gateway4: 172.18.0.1nameservers:addresses: [223.6.6.6,223.5.5.5] #2个阿里的DNSparameters:mode: active-backup        #modemii-monitor-interval: 100
~# sudo netplan apply

双网卡绑定需要同一种类型的网卡类型。不能是仅主机和桥接混着使用。这里全部都是桥接网卡

在这里插入图片描述
可能需要自定义虚拟网络接口,2个都band的网卡需要统一。
ping不通网关bug:重启虚拟机即可。

双网卡绑定+桥接

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

~# sudo cat /etc/netplan/01-netcfg.yaml
# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:version: 2renderer: networkdethernets:eth0:dhcp4: nodhcp6: noeth1:dhcp4: nodhcp6: nobonds:bond0:          #绑定eth0和eth1interfaces:- eth0- eth1
#addresses: [172.18.3.18/16]     #地址、网关、DNS不需要配置在band0上面直接配置在br0中即可
#gateway4: 172.18.0.1        
#nameservers:
# addresses: [223.6.6.6,223.5.5.5]parameters:mode: active-backup        #MODEmii-monitor-interval: 100bridges:br0:dhcp4: nodhcp6: noaddresses: [172.18.3.18/16]gateway4: 172.18.0.1nameservers:addresses: [223.6.6.6,223.5.5.5]interfaces:- bond0          #调用的下一级接口   下一层bond0接口调用eth0和eth1
~#netplay apply	
~#reboot

内外多网卡绑定+桥接

多⽹络情况下实现⽹卡绑定。

~# sudo cat /etc/netplan/01-netcfg.yaml
# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:version: 2renderer: networkdethernets:eth0:dhcp4: nodhcp6: noeth1:dhcp4: nodhcp6: noeth2:dhcp4: nodhcp6: noeth3:dhcp4: nodhcp6: nobonds:bond0:interfaces:- eth0- eth1addresses: [172.18.3.18/16]gateway4: 172.18.0.1nameservers:addresses: [223.6.6.6,223.5.5.5]parameters:mode: active-backupmii-monitor-interval: 100bond1:interfaces:- eth2- eth3addresses: [10.20.3.18/16]parameters:mode: active-backupmii-monitor-interval: 100routes:- to: 172.20.0.0/16via: 10.20.0.1- to: 10.20.0.0/16via: 10.20.0.1- to: 10.2.0.0/16via: 10.20.0.1- to: 10.8.0.0/16via: 10.20.0.1
~#reboot		  

内网多网卡绑定+桥接

~# sudo cat /etc/netplan/01-netcfg.yaml
# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:version: 2renderer: networkdethernets:eth0:dhcp4: nodhcp6: noeth1:dhcp4: nodhcp6: noeth2:dhcp4: nodhcp6: noeth3:dhcp4: nodhcp6: nobonds:bond0:interfaces:- eth0- eth1parameters:mode: active-backupmii-monitor-interval: 100bond1:interfaces:- eth2- eth3parameters:mode: active-backupmii-monitor-interval: 100bridges:br0:dhcp4: nodhcp6: noaddresses: [172.18.3.18/16]gateway4: 172.18.0.1nameservers:addresses: [223.6.6.6,223.5.5.5]interfaces:- bond0br1:dhcp4: nodhcp6: nointerfaces:- bond1addresses: [10.20.3.18/16]routes:- to: 172.20.0.0/16via: 10.20.0.1- to: 10.20.0.0/16via: 10.20.0.1- to: 10.2.0.0/16via: 10.20.0.1- to: 10.8.0.0/16via: 10.20.0.1
~#reboot		  

修改软件仓库

阿⾥云仓库地址:https://opsx.alibaba.com/mirror
中科⼤:http://mirrors.ustc.edu.cn/help/ubuntu.html
清华⼤学:https://mirror.tuna.tsinghua.edu.cn/help/ubuntu/
华为:https://mirrors.huaweicloud.com/

apt/apt-get

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

安装常用系统命令

root@ubuntu1-server:~# apt purge ufw lxd lxd-client lxcfs lxc-common -y #卸载不必要的系统命令root@ubuntu1-server:~# 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 -y             #安装常用系统命令

系统资源限制优化

实际生产环境中工作中的经验值

root@ubuntu1-server:~# ulimit -n
1024
经过测试最大 ulimit -n 的最大值为1048576
#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#其他账⼾的资源软限制和硬限制       #在centos中下面这些即可,在ubantu中root需要单独配置
* 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

内核参数优化

实际生产环境中工作中的经验值

root@ubuntu1-server:~# vim /etc/sysctl.conf 
# 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 = 2root@ubuntu1-server:~# sysctl -p   #加载

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 #安装某个软件包 后缀叫做deb i:install
# 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                                 #列出本机已经安装的所有软件

这篇关于Ubantu基础设置以及多网卡绑定的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/763084

相关文章

idea设置快捷键风格方式

《idea设置快捷键风格方式》在IntelliJIDEA中设置快捷键风格,打开IDEA,进入设置页面,选择Keymap,从Keymaps下拉列表中选择或复制想要的快捷键风格,点击Apply和OK即可使... 目录idea设www.chinasem.cn置快捷键风格按照以下步骤进行总结idea设置快捷键pyth

Java利用Spire.Doc for Java实现在模板的基础上创建Word文档

《Java利用Spire.DocforJava实现在模板的基础上创建Word文档》在日常开发中,我们经常需要根据特定数据动态生成Word文档,本文将深入探讨如何利用强大的Java库Spire.Do... 目录1. Spire.Doc for Java 库介绍与安装特点与优势Maven 依赖配置2. 通过替换

MyBatis配置文件中最常用的设置

《MyBatis配置文件中最常用的设置》文章主要介绍了MyBatis配置的优化方法,包括引用外部的properties配置文件、配置外置以实现环境解耦、配置文件中最常用的6个核心设置以及三种常用的Ma... 目录MyBATis配置优化mybatis的配置中引用外部的propertis配置文件⚠️ 注意事项X

JavaScript装饰器从基础到实战教程

《JavaScript装饰器从基础到实战教程》装饰器是js中一种声明式语法特性,用于在不修改原始代码的情况下,动态扩展类、方法、属性或参数的行为,本文将从基础概念入手,逐步讲解装饰器的类型、用法、进阶... 目录一、装饰器基础概念1.1 什么是装饰器?1.2 装饰器的语法1.3 装饰器的执行时机二、装饰器的

Java JAR 启动内存参数配置指南(从基础设置到性能优化)

《JavaJAR启动内存参数配置指南(从基础设置到性能优化)》在启动Java可执行JAR文件时,合理配置JVM内存参数是保障应用稳定性和性能的关键,本文将系统讲解如何通过命令行参数、环境变量等方式... 目录一、核心内存参数详解1.1 堆内存配置1.2 元空间配置(MetASPace)1.3 线程栈配置1.

C#借助Spire.XLS for .NET实现Excel工作表自动化样式设置

《C#借助Spire.XLSfor.NET实现Excel工作表自动化样式设置》作为C#开发者,我们经常需要处理Excel文件,本文将深入探讨如何利用C#代码,借助强大的Spire.XLSfor.N... 目录为什么需要自动化工作表样式使用 Spire.XLS for .NET 实现工作表整体样式设置样式配置

从基础到高级详解Go语言中错误处理的实践指南

《从基础到高级详解Go语言中错误处理的实践指南》Go语言采用了一种独特而明确的错误处理哲学,与其他主流编程语言形成鲜明对比,本文将为大家详细介绍Go语言中错误处理详细方法,希望对大家有所帮助... 目录1 Go 错误处理哲学与核心机制1.1 错误接口设计1.2 错误与异常的区别2 错误创建与检查2.1 基础

Spring的基础事务注解@Transactional作用解读

《Spring的基础事务注解@Transactional作用解读》文章介绍了Spring框架中的事务管理,核心注解@Transactional用于声明事务,支持传播机制、隔离级别等配置,结合@Tran... 目录一、事务管理基础1.1 Spring事务的核心注解1.2 注解属性详解1.3 实现原理二、事务事

Java实现为PDF设置背景色和背景图片

《Java实现为PDF设置背景色和背景图片》在日常的文档处理中,PDF格式因其稳定性和跨平台兼容性而广受欢迎,本文将深入探讨如何利用Spire.PDFforJava库,以简洁高效的方式为你的PDF文档... 目录库介绍与安装步骤Java 给 PDF 设置背景颜色Java 给 PDF 设置背景图片总结在日常的

C#中通过Response.Headers设置自定义参数的代码示例

《C#中通过Response.Headers设置自定义参数的代码示例》:本文主要介绍C#中通过Response.Headers设置自定义响应头的方法,涵盖基础添加、安全校验、生产实践及调试技巧,强... 目录一、基础设置方法1. 直接添加自定义头2. 批量设置模式二、高级配置技巧1. 安全校验机制2. 类型