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. Nuxt的路由动画效果

    Nuxt.js提供两种方法为路由提供动画效果,一种是全局的,一种是针对单独页面的 全局动画默认使用page来进行设置,例如现在我们为每个页面都设置一个进入和退出时的渐隐渐现的效果.我们可以先在根目录的 ...

  2. 离线安装paramiko以及pysftp linux,windows

    离线安装 paramiko python37 pip download -d ./dependency -r requirements.txt pip install --no-index --ign ...

  3. Dart语言学习(二) Dart的常量和变量

    1.使用var声明变量,可赋予不同类型的值 Dart是一个强大的脚本类语言,可以不预先定义变量类型 ,自动会类型推导 Dart中定义变量可以通过var关键字可以通过类型来申明变量 var str='t ...

  4. mysql 导出sql文件

    1:find  / -name mysqldump -print 先找到mysqldump 目录位置 2:/usr/local/mysql/bin/mysqldump -u root -p hanwe ...

  5. C:产生随机数

    函数说明 #include <time.h> time_t time(time_t *t); 功能:获取当前系统时间 参数:常设置为NULL 返回值:当前系统时间, time_t 相当于l ...

  6. selenium配合phantomjs实现爬虫功能,并把抓取的数据写入excel

    # -*- coding: UTF-8 -*- ''' Created on 2016年5月13日 @author: csxie ''' import datetime from Base impor ...

  7. mysql-8.0.18-winx64 环境变量的配置

    1. 鼠标右击   此电脑    -->属性 如图:进行步骤 1->2->3 接下来就可以使用命令mysql  -u  root  -p登录mysql了 启动mysql的命令为net ...

  8. python正则表达式中括号的作用,形如 "(\w+)\s+\w+"

    先看一个例子: import re string="abcdefg acbdgef abcdgfe cadbgfe" #带括号与不带括号的区别 regex=re.compile(& ...

  9. 使用JavaScript获取样式的属性值

    1 . 在js中可以使用style属性来获取样式的属性值(只能获取内联样式的属性值) 语法格式为: HTML元素.style.样式属性; 2 .   在IE浏览器中,使用currentStyle来获取 ...

  10. 「ZJOI2008」树的统计

    树剖模板题啊! 这道题的话,最通(jian)俗(dan)易(cu)懂(bao)的解法应该就是树剖了. 加上线段树维护树上路径的最大权值(\(Max\))和路径和(\(sum\)). 至于\(LCT\) ...