centos7初始化指令碼

2021-10-12 07:00:01 字數 1662 閱讀 4613

centos7初始化指令碼

新裝的虛擬機器或者linux伺服器的初始化指令碼

功能:

永久關閉防火牆,selinux

安裝常用工具

配置靜態ip位址

配置阿里源

#!/usr/bin/bash

#centos初始化指令碼

#time 2020-04-01

#防火牆設定

echo

"關閉防火牆和selinux"

systemctl stop firewalld && systemctl disable firewalld && setenforce 0 &&

sed -i 's/selinux=enforcing/selinux=disabled/' /etc/selinux/config

if[$? -eq 0 ]

;then

echo

"防火牆已關閉且開機不自啟"

else

echo

"防火牆關閉失敗請手動檢視"

exit 1

fisleep 2

#安裝相關配置常用工具

yum install -y lrzsz sysstat elinks wget vim net-tools bash-completion &

>/dev/null

if[$? -eq 0 ]

;then

echo

"安裝工具成功"

else

echo

"安裝工具失敗,請檢查yum源"

exit 2

fisleep 2

#配置固定ip位址

chack_ip()'

|awk -f"/"''`

net=255.255.255.0

gate=

`route -n |

awk'nr==3'

` dns=

`cat /etc/resolv.conf |

grep nameserver |

awk''`}

chack_ip

(cat

<<

eofipaddr=$ip

netmask=$net

gateway=$gate

dns1=$dns

eof)

>> /etc/sysconfig/network-scripts/ifcfg-ens33

systemctl restart network

if[$? -eq 0 ]

;then

echo

"配置ip位址成功"

else

echo

"配置ip位址失敗,請手動檢視"

exit 3

fisleep 2

#配置yum源-這裡選用阿里源

mv /etc/yum.repos.d/*.repo /tmp

wget -o /etc/yum.repos.d/centos-base.repo

wget -o /etc/yum.repos.d/epel.repo

echo

$(ls /etc/yum.repos.d)

sleep 2

exit 0

Centos7普通初始化指令碼

bash bash 關閉selinux echo set selinux disabled sed i s selinux selinux disabled etc selinux config setenforce 0 關閉防火牆 echo 關閉防火牆 systemctl stop firewal...

centos7系統初始化

echo arp引數,檢查一次相鄰層記錄的有效性的週期。當相鄰層記錄失效 etc sysctl.conf echo e net.ipv4.neigh.default.gc stale time 120 n etc sysctl.conf echo 路由設定 etc sysctl.conf echo ...

centos7系統初始化優化

防火牆優化 關閉防火牆 systemctl stop firewalld systemctl disable firewalld 開啟防火牆命令 新增乙個埠 firewall cmd zone public add port 80 tcp permanent permanent永久生效,沒有此引數重...