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初始化脚本的更多相关文章

  1. CentOS 初始化脚本

    #!/bin/bash # curl https://yiyingcanfeng.github.io/centos-init.sh | bash # 可选参数base kernel python ph ...

  2. CentOS初始化脚本(未完)

    #!/bin/bash release=`` .shutdown selinux [ -e "/etc/selinux/config" ] && sed -i 's ...

  3. centos7初始化脚本(转)

    #!/bin/bash # 描述: CentOS 初始化脚本 # 加载配置文件 if [ -n "${1}" ];then /bin/} fi # 可接受配置(shell 变量格式 ...

  4. centos 7 初始化脚本

    #!/bin/bash # 时间: 2018-11-21 # 作者: HuYuan # 描述: CentOS 7 初始化脚本 # 加载配置文件 if [ -n "${1}" ];t ...

  5. bash-1 初始化CentOS系统的初始化脚本

    初始化CentOS系统的初始化脚本 #!/bin/bash # #******************************************************************* ...

  6. Centos7初始化脚本

    今天分享一个自己写的一个初始化的小脚本. 编写初始化系统要考虑到系统的版本问题,现在用的比较多的就是centos6和centos7,所以首先要判断一下系统的版本. cat /etc/redhat-re ...

  7. centos7 初始化脚本

    #!/bin/bash # 时间: 2018-11-21 # 作者: HuYuan # 描述: CentOS 7 初始化脚本 # 加载配置文件 if [ -n "${1}" ];t ...

  8. liunx用户环境初始化脚本

          liunx用户环境初始化脚本 编写生成脚本基本格式,包括作者,联系方式,版本,时间,描述等 [root@magedu ~]# vim .vimrc set ignorecase set c ...

  9. Linux初始化脚本

    以下脚本用于linux系统的初始化脚本,可以在服务器系统安装完毕之后立即执行.脚本结合各位大牛一些参数,已经在CentOS 5下通过. 使用方法:将其复制,保存为一个shell文件,比如init.sh ...

随机推荐

  1. 路飞-pip源

    pip安装源 介绍 """ 1.采用国内源,加速下载模块的速度 2.常用pip源: -- 豆瓣:https://pypi.douban.com/simple -- 阿里: ...

  2. 其他 - 阻塞 & 同步 的基本认识

    1. 概述 有些概念, 老是弄不清楚 同步异步 阻塞非阻塞 2. 准备 场景 角色 client 发起请求 接受请求 server 接受请求 执行操作 返回响应 行为 大致是一个 C/S 模式的模型 ...

  3. 五种网络IO模型以及多路复用IO中select/epoll对比

    下面都是以网络读数据为例 [2阶段网络IO] 第一阶段:等待数据 wait for data 第二阶段:从内核复制数据到用户 copy data from kernel to user 下面是5种网络 ...

  4. STL总结 (C++)

    一.一般介绍 STL(Standard Template Library),即标准模板库,是一个具有工业强度的,高效的C++程序库.它被容纳于C++标准程序库(C++ Standard Library ...

  5. K8S集群搭建之软路由的安装

    一.系统要求 ①镜像:win10 ②1C.4G.20G即可 ③仅主机模式(共享网卡上网) ④老毛桃PE ⑤ip为192.168.66网段(因为我设置的其他K8S节点也为该网段)---koolshare ...

  6. word写文档体会

    1.找一个文档规范要求. 2.根据文档的规范要求调整正文的格式,标题1的格式,标题2的格式,标题3的格式,图表的格式,把没用的那些格式都删除掉. 3.图注表注后空格一行. 4.设置页眉页脚. 5.生成 ...

  7. SPOJ Distinct Substrings

    给定一个字符串,求不相同子串个数.每个子串一定是某个后缀的前缀,那么原问题等价于求所有后缀之间的不相同子串个数.总数为n*(n-1)/2,再减掉height[i]的和就是答案 #include< ...

  8. provide 和 inject高阶使用

    provide 在祖先里授权导出 inject在后代负责接收 foo可以是本组件的函数方法 或者 变量foo 也可以是祖先组件自己 祖先组件foo: this 后代组件 foo.$options.da ...

  9. NLP开源工具

    最近有人问我几次NLP有哪些开源工具,这里做个笔记.

  10. vs2013编译soui并创建一个项目

    1.soui.10.sln改为soui.13.sln 2.用nodepad++打开soui.13.sln,作如下修改 注:第一行我是改为13.00,编译后似乎自己变为12.00了 编译结果: 注:这是 ...