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 ...
随机推荐
- n个点的最长公共子串(别人的模板) poj 3080
没有理解代码.单纯记模板 题意:找最长的公共字串,长度相同就找字典序最小的(这一点wa了我13遍!!!)题解:kmp或者直接暴力列举当公共子串长度小于3时,有特判 #include<map> ...
- 左偏树(p4431)
难得不是左偏树,而是思维: 这道题在做得时候,有两个性质 1.如果a是一个不下降序列,那么b[i]==a[i]时取得最优解. 2.如果a是一个严格递减序列,则取a序列的中位数x,令b[1]=b[2]= ...
- 【Python】 运算符
什么是运算符? 本章节主要说明Python的运算符.举个简单的例子 4 +5 = 9 . 例子中,4 和 5 被称为操作数,"+" 称为运算符. 接下来让我们一个个来学习Pytho ...
- blog主题——樱花
贮存一下,blog代码 QAQ 页脚html <!--live2d--> <script src="https://blog-static.cnblogs.com/file ...
- Analog power pin UPF defination
在一个analog macro端口上,有些pin是always on的,有些是shut down的,如何描述这些pin的power属性?这是一个常见问题,驴就此机会大致描述一下常见的做法.对于这个问题 ...
- 读书笔记, Python - python-tricks-buffet-awesome-features
To be a Pythonista 1. assert syntax: assert expression1 [",", expression2] 大致相当于 if __debu ...
- JavaScript - what is "this"? this是什么?
https://fangyinghang.com/this-in-js/ Core func(p1, p2) // 等同于 func.call(undefined, p1, p2) this 就是ca ...
- jQuery的ajax方法的属性以及jsonp的随机数问题
原文地址[ http://www.cnblogs.com/know/archive/2011/10/09/2204005.html ] <!DOCTYPE html PUBLIC "- ...
- Presto入门介绍
(一)背景 MapReduce不能满足大数据快速实时adhoc查询计算的性能要求,Facebook2012年开发,2013年开源 (二)是什么 基于内存的并行计算,Facebook推出的分布式SQL交 ...
- UVA10600 ACM Contest and Blackout
用prim算法求最小生成树和次小生成树~ #include<cstdio> #include<algorithm> #include<cstring> using ...