linux初始化配置

linux系统初始化与优化设置

yum安装服务

yum install -y vim tree wget bash-completion bash-completion-extras lrzsz net-tools sysstat iotop iftop htop unzip nc nmap telnet bc psmisc httpd-tools bind-utils nethogs expect ntpdate

关闭防火墙

#关闭SELinux
sed -i '/^SELINUX=/c SELINUX=disabled' /etc/selinux/config
#getenforce命令可以查看
 
#关闭防火墙
systemctl disable --now firewalld  (centos7和8)
systemctl status firewalld命令可以查看

ssh远程连接加速优化设置

#修改ssh服务端配置文件
#1.注释掉已有的配置
sed -i '/^GSSAPIAuthentication/s@^@#@g'
/etc/ssh/sshd_config
#2.关闭对应功能
cat >>/etc/ssh/sshd_config<<EOF
UseDNS no
GSSAPIAuthentication no
EOF
#3.重启sshd
systemctl restart sshd
#4.检查
egrep '^(GSSAPIAuthentication|UseDNS)' /etc/ssh/sshd_config

时间同步

cat >/var/spool/cron/root<<EOF
#1. sync time by Jia at 20230101
*/3 * * * * /sbin/ntpdate ntp.aliyun.com &>/dev/null
EOF

修改IP脚本

cat /server/scripts/change.sh
#!/bin/bash
#author: supershy
#desc: change ip and hostname
eth0=/etc/sysconfig/network-scripts/ifcfg-eth0
eth1=/etc/sysconfig/network-scripts/ifcfg-eth1
#1.脚本参数个数
if [ $# -ne 2 ] ;then
 	echo "请输入2个参数"
	exit 1
fi

#2.模板机ip地址(最后1位)
ip=`hostname -I |awk '{print $1}'|sed 's#.*\.##g'`
#3.新的ip
ip_new=`echo $2 |sed 's#^.*\.##g'`
#4.新的主机名
hostname=$1

#5.修改ip
if [ -f $eth0 ];then
	sed -i "s#10.0.0.$ip#10.0.0.$ip_new#g" $eth0
else
	echo "eth0网卡不存在,修改失败"
fi
if [ -f $eth1 ];then
	sed -i "s#172.16.1.$ip#172.16.1.$ip_new#g" $eth1
else
	echo "eth1网卡不存在,修改失败"
fi
systemctl restart network

#6.修改主机名
hostnamectl set-hostname $hostname

ubutu22.04修改ip地址

踩坑记录
  • ubuntu22.04修改ip地址后重启系统未生效
ubuntu22.04修改ip地址后重启系统未生效
>>解决:
想到可能是文件编号的原因,新建配置文件为 01-network-manager-all.yaml 再试,果然系统重启后静态IP配置还在,50-cloud-init.yaml 依然被重置了。
  • WARNING:root:Cannot call Open vSwitch: ovsdb-server.service is not running.
root@master241:~# netplan apply 
WARNING:root:Cannot call Open vSwitch: ovsdb-server.service is not running.

>>解决:
apt install openvswitch-switch -y

openeuler配置ip地址

vi ifcfg-ens33
...
IPADDR=10.0.0.200
NETMASK=255.255.255.0
GATEWAY=10.0.0.2
DNS1=223.5.5.5
DNS2=223.6.6.6

#激活连接并检查状态
nmcli con up ens33 ifname ens33

#重启网卡
systemctl restart NetworkManager
1、双网卡绑定配置

centos配置双网卡主备参考链接:https://blog.51cto.com/u_12228/11862100

#将ens36和ens37两张网卡设置成主备绑定到bond0,ens36设置成主网卡
#nmcli connection show会显示出当前主机上正在工作中的网卡
[root@supershy ~]# nmcli connection show 
NAME   UUID                                  TYPE      DEVICE 
ens33  3a263d2c-a639-4f46-b08f-f3681dcf749f  ethernet  ens33  

#nmcli device会将本机所有网卡显示出来
[root@supershy ~]# nmcli device 
DEVICE  TYPE      STATE         CONNECTION 
ens33   ethernet  connected     ens33      
ens36   ethernet  disconnected  --         
ens37   ethernet  disconnected  --         
lo      loopback  unmanaged     --         
[root@supershy ~]# 

#如果nmcli connection show命令显示ens36和ens37的信息代表这两张网卡正在工作,则需删除操作,否则会影响bond0正常工作
# nmcli connection delete ens36
# nmcli connection delete ens37

[root@supershy ~]# cd /etc/sysconfig/network-scripts/
[root@supershy network-scripts]# ls ifcfg-*
ifcfg-ens33  ifcfg-lo

- primary ens36表示将ens36设置为主网卡,也可以不设置(备注:子网卡均正常时,primary网卡优先处于活跃状态)
- miimon 100: 以毫秒为单位指定MII链接监控的频率(默认为0,表示关闭,配置miimon时最好从100开始)
[root@supershy network-scripts]# nmcli connection add type bond ifname bond0 con-name bond0 miimon 100 mode active-backup primary ens36 ip4 10.0.0.66/24
Connection 'bond0' (7a86c969-ae47-4cd4-a86d-691dd5654cdd) successfully added.

[root@supershy network-scripts]# 
[root@supershy network-scripts]# cat ifcfg-bond0 
BONDING_OPTS="mode=active-backup miimon=100 primary=ens36"
TYPE=Bond
BONDING_MASTER=yes
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=none
IPADDR=10.0.0.66
PREFIX=24
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=bond0
UUID=7a86c969-ae47-4cd4-a86d-691dd5654cdd
DEVICE=bond0
ONBOOT=yes
[root@supershy network-scripts]# 
[root@supershy network-scripts]# nmcli connection add type bond-slave ifname ens36 con-name bond0-p1 master bond0 
Connection 'bond0-p1' (5b06a708-62ac-4762-a451-6394aec507d0) successfully added.
[root@supershy network-scripts]# 
[root@supershy network-scripts]# nmcli connection add type bond-slave ifname ens37 con-name bond0-p2 master bond0 
Connection 'bond0-p2' (2161e245-4b9b-44e6-b396-fa78c324ca81) successfully added.
[root@supershy network-scripts]# 
[root@supershy network-scripts]# cat ifcfg-bond0-p1
TYPE=Ethernet
NAME=bond0-p1
UUID=5b06a708-62ac-4762-a451-6394aec507d0
DEVICE=ens36
ONBOOT=yes
MASTER=bond0
SLAVE=yes
[root@supershy network-scripts]# cat ifcfg-bond0-p2 
TYPE=Ethernet
NAME=bond0-p2
UUID=2161e245-4b9b-44e6-b396-fa78c324ca81
DEVICE=ens37
ONBOOT=yes
MASTER=bond0
SLAVE=yes
[root@supershy network-scripts]# 
[root@supershy network-scripts]# 
[root@supershy network-scripts]# nmcli connection show --active 
NAME      UUID                                  TYPE      DEVICE 
ens33     3a263d2c-a639-4f46-b08f-f3681dcf749f  ethernet  ens33  
bond0     7a86c969-ae47-4cd4-a86d-691dd5654cdd  bond      bond0  
bond0-p1  5b06a708-62ac-4762-a451-6394aec507d0  ethernet  ens36  
bond0-p2  2161e245-4b9b-44e6-b396-fa78c324ca81  ethernet  ens37  
[root@supershy network-scripts]# 
[root@supershy network-scripts]# nmcli connection up bond0-p1
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/5)
[root@supershy network-scripts]# nmcli connection up bond0-p2
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/6)
[root@supershy network-scripts]# nmcli connection up bond0
Connection successfully activated (master waiting for slaves) (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/7)
[root@supershy network-scripts]# systemctl restart NetworkManager
[root@supershy network-scripts]# 
[root@supershy network-scripts]# cd /proc/net/bonding/
[root@supershy bonding]# ls
bond0
[root@supershy bonding]# cat bond0 
Ethernet Channel Bonding Driver: v5.10.0-136.12.0.86.oe2203sp1.x86_64

Bonding Mode: fault-tolerance (active-backup)
Primary Slave: ens36 (primary_reselect always)
Currently Active Slave: ens36
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0
Peer Notification Delay (ms): 0

Slave Interface: ens36
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:79:6e:d6
Slave queue ID: 0

Slave Interface: ens37
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:79:6e:e0
Slave queue ID: 0
[root@supershy bonding]# 

posted @   逃离这世界~  阅读(57)  评论(0编辑  收藏  举报
(评论功能已被禁用)
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· DeepSeek 开源周回顾「GitHub 热点速览」
点击右上角即可分享
微信分享提示