centos初始化脚本
centos初始化脚本
扩容
#!/bin/bash
#下述下个变量需要根据实际情况进行修改 disk="/dev/sdb"
partition="$disk"
num= help ()
{
echo ' ====================================================================='
echo ' The script has three variables: <<disk>>、<<partition>> and <<num>>'
echo ' If variables are defined, select < y > to execute'
echo ' If variables are not defined, select < q > to exit'
echo " "
echo " The disk is $disk;"
echo " The part is $partition;"
echo " The num is $num;"
echo ' ====================================================================='
}
help choose() {
read -p "Please enter your choice
y executing the script;
q exit the script;
Please input: " choice
case $choice in
q)
echo " "
echo "No initialize the disk, exit..." ;;
y)
echo "Initialize the disk..."
echo " "
kuorong ;;
*)
echo " "
echo " "
echo "Please input y or q"
choose ;;
esac
}
choose kuorong() {
echo "n
p t
8e
w
" | fdisk /dev/sdb &>/dev/null #判断分区是否成功
a="`fdisk -l | grep /dev/sdb1 | grep 8e | wc -l`"
if [ $a -ge ]; then
echo "分区成功,即将扩容;"
sleep
else
echo "分区失败,即将退出;"
sleep
exit
fi #创建物理PV,并进行扩容
#确定VG Name
vgname="`vgdisplay | grep "VG Name" | awk '{print $3}'`"
#定义需要扩容的目录
contents="`df -h | grep /dev/mapper/centos-root | awk '{print $1}'`" b="`cat /etc/fstab | grep $contents | grep "xfs" | wc -l`"
if [ $b -ge ]; then
echo "系统格式是xfs,可扩展;"
sleep
else
echo "系统格式不对,即将退出;"
sleep
exit
fi echo "pvcreate $partition
sleep
vgextend $vgname $partition
sleep
lvextend -L +"$num"G $contents
sleep
pvdisplay
quit
" | lvm &>/dev/null
sleep
xfs_growfs /dev/mapper/centos-root echo " "
echo " " vgdisplay | grep "VG Size" echo " "
echo " " df -h
}添加IP、主机名、挂载/dev/sdb1磁盘
#!/bin/bash
# ip=$
hostname=$ if [ -z $ip ] || [ -z $hostname ]; then
echo " "
echo "Sorry, IP or host is null"
echo "# The format : bash set.sh ip hostname"
echo "# For example: bash set.sh 192.168.72.13 node1"
echo " "
exit
fi function check_ip() {
VALID_CHECK=$(echo $ip|awk -F. '$1<=255&&$2<=255&&$3<=255&&$4<=255{print "yes"}')
if echo $ip|egrep "^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$">/dev/null; then
if [ ${VALID_CHECK:-no} == "yes" ]; then
echo "ip $ip available."
else
echo "ip $ip not available!"
exit
fi
else
echo "ip format error!"
exit
fi
} ndir="/etc/sysconfig/network-scripts/ifcfg-ens192"
ob="`grep "ONBOOT" $ndir`"
ipaddr="`grep "IPADDR" $ndir`"
gateway="`grep "GATEWAY" $ndir`"
gt="`echo ${ip%.*}`"
dns1="`grep "DNS1" $ndir`"
dns2="`grep "DNS2" $ndir`"
nt="`grep "NETMASK" $ndir`" sed -i "s/$ob/ONBOOT=yes/g" $ndir
sed -i "s/$ipaddr/IPADDR=$ip/g" $ndir
sed -i "s/$gateway/GATEWAY=$gt.1/g" $ndir
sed -i "s/$dns1/DNS1=8.8.8.8/g" $ndir
sed -i "s/$dns2/DNS2=114.114.114.114/g" $ndir
sed -i "s/$nt/NETMASK=255.255.255.0/g" $ndir systemctl restart network ping -c -W www.baidu.com &>/dev/null
if [ $? != ]; then
echo " "
echo " "
echo "The $ip is unavailable, Please check again......"
echo "The $ip is unavailable, Please check again......"
echo "The $ip is unavailable, Please check again......"
echo " "
echo " "
exit
else
echo " "
echo " "
echo "The $ip is OK !!!"
echo "The $ip is OK !!!"
echo "The $ip is OK !!!"
echo " "
echo " "
fi hostnamectl --static set-hostname $hostname echo "The name is `hostname`" echo " "
echo " " disk="/dev/sdb"
mpath="/opt/data" Format_disk() {
echo "n
p w
" | fdisk $disk &>/dev/null && mkfs.ext4 "$disk"1 &>/dev/null #mkdir $mpath
mount "$disk" $mpath
UUID=`blkid "$disk" | awk '{print $2}'`
echo "$UUID $mpath ext4 defaults 0 0" >> /etc/fstab
source /etc/fstab &>/dev/null
df -T | grep "$disk"
mount | grep "$disk"
} Judge() {
fnum="`fdisk -l | grep /dev/sdb | wc -l`"
if [ $fnum -ge ]; then
mkdir -p $mpath
echo "Initialize the disk $disk, and mount $mpath"
read -p "Please enter the number
No initialize the disk and exit;
Initialize the disk;
Please input: " num
case $num in
)
echo " "
echo "No initialize the disk, exit..." ;;
)
echo "Initialize the disk"
sleep
echo " "
Format_disk ;;
*)
echo " "
echo " "
echo "Please input 0 or 1"
Judge ;;
esac
else
echo "The server does not have this disk: $disk"
fi
} Judge
bash版本2
<#
Intro: This function will display a form to communicate with the user.
Input: -FormText -ButtonText
Example: MakeForm -FormText "ForInput" -ButtonText "Submit"
Use: To make the PowerShell program's interactivity better.
#>
function MakeForm{
param($FormText,$ButtonText)
$null = [Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
$form = New-Object Windows.Forms.Form
$form.size = New-Object Drawing.Size -Arg ,
$form.StartPosition = "CenterScreen"
$form.Text = $FormText.toString()
$textBox = New-Object Windows.Forms.TextBox
$textBox.Dock = "fill"
$form.Controls.Add($textBox)
$button = New-Object Windows.Forms.Button
$button.Text = $ButtonText
$button.Dock = "Bottom"
$button.add_Click(
{$global:resultText = $textBox.Text;$form.Close()})
$form.Controls.Add($button)
[Void]$form.ShowDialog()
} echo " "
echo "++++++ 添加IP ++++++"
echo " "
MakeForm -FormText "请输入主机IP:" -ButtonText "Submit"
echo "即将配置: $resultText 到此服务器" $wmi = Get-WmiObject win32_networkadapterconfiguration -filter "ipenabled = 'true'" #注意: 此处是子网掩码,根据实际情况进行更改
$wmi.EnableStatic("$resultText", "255.255.255.0") | Out-Null $a = $resultText.split(".",)[]
$b = $resultText.split(".",)[]
$c = $resultText.split(".",)[]
$d = $resultText.split(".",)[]
$gateway = "$a.$b.$c.1" $wmi.SetGateways("$gateway") | Out-Null #注意: 此处是DNS,根据实际情况进行更改
$dns = "10.1.1.1", "10.1.1.1" $wmi.SetDNSSERVERSearchOrder($dns) | Out-Null ipconfig /flushdns | Out-Null
sleep
ipconfig /flushdns | Out-Null
#$CurrentyDir = Split-Path -Parent $MyInvocation.MyCommand.Definition
#C:\opstools\Init_file\ChangeName.vbs
netsh interface ip show config | Out-Null
sleep
#ping www.baidu.com echo " "
echo " " #注意:此处需要根据情况修改主机名
echo "++++++ 更改主机名 ++++++"
echo " "
#rename-computer -newname "BX-A-$c-$d" $newname="BX-A-$c-$d"
$computer=Get-WMIObject Win32_ComputerSystem
$computer.Rename( $NewName ) | out-null #C:\opstools\Init_file\ChangeName.vbs
#sleep
#echo "+++++ 主机名未生成 +++++"
#$result = Test-Path C:\opstools\Init_file\ComputerName.txt
#while ($result -cnotcontains "False")
# {
# $result = Test-Path C:\opstools\Init_file\ComputerName.txt
# echo " 等待输入 ComputerName"
# sleep
# } echo " "
echo "+++++ 获取更改后的主机名 +++++"
#$CName = Get-Content C:\opstools\Init_file\ComputerName.txt
#echo $CName
#echo " "
#echo " "
#sleep echo "+++++ 部署 Salt +++++"
Copy-Item "\\10.192.2.1\d$\opstools\salt-package" -Destination "d:\" -recurse
cmd.exe /c "d:\salt-package\Salt-Minion-2016.3.0-AMD64-Setup.exe /S /master=10.3.2.2 /minion-name=$newname"
#return Get-Service -Name salt-minion
sleep
#Remove-Item 'C:\opstools\Init_file\ComputerName.txt'
#sleep netsh interface ip show config
sleep
ping www.baidu.com
Shutdown.exe -r -t第三版
<#
Intro: This function will display a form to communicate with the user.
Input: -FormText -ButtonText
Example: MakeForm -FormText "ForInput" -ButtonText "Submit"
Use: To make the PowerShell program's interactivity better.
#>
function MakeForm{
param($FormText,$ButtonText)
$null = [Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
$form = New-Object Windows.Forms.Form
$form.size = New-Object Drawing.Size -Arg ,
$form.StartPosition = "CenterScreen"
$form.Text = $FormText.toString()
$textBox = New-Object Windows.Forms.TextBox
$textBox.Dock = "fill"
$form.Controls.Add($textBox)
$button = New-Object Windows.Forms.Button
$button.Text = $ButtonText
$button.Dock = "Bottom"
$button.add_Click(
{$global:resultText = $textBox.Text;$form.Close()})
$form.Controls.Add($button)
[Void]$form.ShowDialog()
} echo " "
echo "++++++ 添加IP ++++++"
echo " "
MakeForm -FormText "请输入主机IP:" -ButtonText "Submit"
echo "即将配置: $resultText 到此服务器" $wmi = Get-WmiObject win32_networkadapterconfiguration -filter "ipenabled = 'true'" #注意: 此处是子网掩码,根据实际情况进行更改
$wmi.EnableStatic("$resultText", "255.255.255.0") | Out-Null $a = $resultText.split(".",)[]
$b = $resultText.split(".",)[]
$c = $resultText.split(".",)[]
$d = $resultText.split(".",)[]
$gateway = "$a.$b.$c.1" $wmi.SetGateways("$gateway") | Out-Null #注意: 此处是DNS,根据实际情况进行更改
$dns = "10.23.110.201", "10.23.110.200" $wmi.SetDNSSERVERSearchOrder($dns) | Out-Null ipconfig /flushdns | Out-Null
sleep
ipconfig /flushdns | Out-Null
#$CurrentyDir = Split-Path -Parent $MyInvocation.MyCommand.Definition
#C:\opstools\Init_file\ChangeName.vbs
netsh interface ip show config | Out-Null
sleep echo " "
echo " " echo "++++++ 检测 IP 是否连通 ++++++"
ping www.baidu.com | Out-Null
$rw=$?
while ($rw -cnotcontains "False")
{
ping www.baidu.com | Out-Null
$rw=$?
if ("$rw" -eq "False")
{
echo " "
echo " IP 不通,请稍后..."
sleep
continue
}
else
{
echo " "
echo " IP is ok"
#exit
}
} echo " "
echo " " #注意:此处需要根据情况修改主机名
echo "++++++ 主机名 ++++++"
echo " "
#rename-computer -newname "BX-AP-$c-$d" $newname="BX-A-$c-$d"
$computer=Get-WMIObject Win32_ComputerSystem
$computer.Rename( $NewName ) | out-null
echo $newname #C:\opstools\Init_file\ChangeName.vbs
#sleep
#echo "+++++ 主机名未生成 +++++"
#$result = Test-Path C:\opstools\Init_file\ComputerName.txt
#while ($result -cnotcontains "False")
# {
# $result = Test-Path C:\opstools\Init_file\ComputerName.txt
# echo " 等待输入 ComputerName"
# sleep
# } echo " "
echo " "
#echo "+++++ 获取更改后的主机名 +++++"
#$CName = Get-Content C:\opstools\Init_file\ComputerName.txt
#echo $CName
#echo " "
#echo " "
#sleep echo "+++++ 部署 Salt +++++"
Copy-Item "\\10.1.1.1\d$\opstools\salt-package" -Destination "d:\" -recurse
cmd.exe /c "d:\salt-package\Salt-Minion-2016.3.0-AMD64-Setup.exe /S /master=10.1.1.1 /minion-name=$newname"
#return Get-Service -Name salt-minion
sleep
#Remove-Item 'C:\opstools\Init_file\ComputerName.txt'
#sleep netsh interface ip show config
sleep
#ping www.baidu.com
Shutdown.exe -r -t
centos初始化脚本的更多相关文章
- CentOS 初始化脚本
#!/bin/bash # curl https://yiyingcanfeng.github.io/centos-init.sh | bash # 可选参数base kernel python ph ...
- CentOS初始化脚本(未完)
#!/bin/bash release=`` .shutdown selinux [ -e "/etc/selinux/config" ] && sed -i 's ...
- centos7初始化脚本(转)
#!/bin/bash # 描述: CentOS 初始化脚本 # 加载配置文件 if [ -n "${1}" ];then /bin/} fi # 可接受配置(shell 变量格式 ...
- centos 7 初始化脚本
#!/bin/bash # 时间: 2018-11-21 # 作者: HuYuan # 描述: CentOS 7 初始化脚本 # 加载配置文件 if [ -n "${1}" ];t ...
- bash-1 初始化CentOS系统的初始化脚本
初始化CentOS系统的初始化脚本 #!/bin/bash # #******************************************************************* ...
- Centos7初始化脚本
今天分享一个自己写的一个初始化的小脚本. 编写初始化系统要考虑到系统的版本问题,现在用的比较多的就是centos6和centos7,所以首先要判断一下系统的版本. cat /etc/redhat-re ...
- centos7 初始化脚本
#!/bin/bash # 时间: 2018-11-21 # 作者: HuYuan # 描述: CentOS 7 初始化脚本 # 加载配置文件 if [ -n "${1}" ];t ...
- liunx用户环境初始化脚本
liunx用户环境初始化脚本 编写生成脚本基本格式,包括作者,联系方式,版本,时间,描述等 [root@magedu ~]# vim .vimrc set ignorecase set c ...
- Linux初始化脚本
以下脚本用于linux系统的初始化脚本,可以在服务器系统安装完毕之后立即执行.脚本结合各位大牛一些参数,已经在CentOS 5下通过. 使用方法:将其复制,保存为一个shell文件,比如init.sh ...
随机推荐
- AcWing 847. 图中点的层次
队列 #include <cstdio> #include <cstring> #include <iostream> #include <algorithm ...
- Lc626_换座位
626. 换座位 SQL架构 小美是一所中学的信息科技老师,她有一张 seat 座位表,平时用来储存学生名字和与他们相对应的座位 id. 其中纵列的 id 是连续递增的 小美想改变相邻俩学生的座位. ...
- IPSec无法建立?注意第一阶段hash sha !
该篇注意记录一下,有些情况下,我们配置了IPSec ,但是就是无法建立,发现连第一阶段都无法建立起来. 1.检查配置无问题 2.开启debug crypto isakmp发现有IKE的重传 3.sho ...
- Eclipse代码规范
配置代码自动格式化 1.导入规范文件 codeStyle.xml <?xml version="1.0" encoding="UTF-8" standa ...
- go基础_数组
数组有2种赋值方式 一种明确指定长度,另一种从赋值数目指定长度 package main import "fmt" func main() { //数组赋值方式1,指定长度 arr ...
- Linux list_head
在linux kernel里面链表应用非常广泛. 我们在应用程序中,定义一个链表结构通常要包含数据域,如下: typedef struct _listNode{ int data; struct _l ...
- app内区域截图利用html2Canvals保存到手机 截屏 (html2Canvals2版本1.0.0)
html2canvas($(], {scale:,logging:false,useCORS:true}).then(function(canvas) { var dataUrl = canvas.t ...
- CRT中国剩余定理 & Lucas卢卡斯定理
数论_CRT(中国剩余定理)& Lucas (卢卡斯定理) 前言 又是一脸懵逼的一天. 正文 按照道理来说,我们应该先做一个介绍. 中国剩余定理 中国剩余定理,Chinese Remainde ...
- OGG在windows环境下字符集的配置
windows环境下不配置字符集(默认使用windows自己的字符集),从linux等系统同步过来的表中如果含有中文字符列将显示为乱码,被ogg误认为虚拟列,从而导致进程abend. 设置ogg进程在 ...
- Java SimpleDateFormat 日期-时间格式参数
字母 日期或时间元素 表示 示例 G Era 标志符 Text AD y 年 Year 1996; 96 M 年中的月份 Month ...