上传文件至 MD
This commit is contained in:
parent
d6bcb0f5bf
commit
033d03fa2b
271
MD/KVM批量管理脚本.txt
Normal file
271
MD/KVM批量管理脚本.txt
Normal file
@ -0,0 +1,271 @@
|
||||
#!/usr/bin/bash
|
||||
list(){
|
||||
echo "|--------------------------------|"
|
||||
echo "|---------批量管理工具箱-----------|"
|
||||
echo "|----1.创建自定义配置单个虚拟机------|"
|
||||
echo "|----2.批量创建自定义配置虚拟机------|"
|
||||
echo "|----3.批量创建默认配置虚拟机--------|"
|
||||
echo "|----4.删除虚拟机------------------|"
|
||||
echo "|----5.退出-----------------------|"
|
||||
}
|
||||
dgchuangjian(){
|
||||
read -p "请输入你的虚拟机名字" vm_name
|
||||
read -p "请输入内存大小(MB)" memory
|
||||
read -p "请输入cpu核数" vcpus
|
||||
read -p "请输入磁盘大小(G): " disk_size
|
||||
kvmuuid=`uuidgen`
|
||||
#kvmmac=`openssl rand -hex 3| sed -r 's/..\B/&:/g'`
|
||||
virsh define <(
|
||||
|
||||
cat <<EOF
|
||||
<domain type='kvm'>
|
||||
<name>$vm_name</name>
|
||||
<uuid>$kvmuuid</uuid>
|
||||
<metadata>
|
||||
<libosinfo:libosinfo xmlns:libosinfo="http://libosinfo.org/xmlns/libvirt/domain/1.0">
|
||||
<libosinfo:os id="http://centos.org/centos/7.0"/>
|
||||
</libosinfo:libosinfo>
|
||||
</metadata>
|
||||
<memory unit='KiB'>$(($memory * 1024))</memory>
|
||||
<currentMemory unit='KiB'>2048000</currentMemory>
|
||||
<vcpu placement='static'>$vcpus</vcpu>
|
||||
<os>
|
||||
<type arch='x86_64' machine='pc-q35-rhel9.4.0'>hvm</type>
|
||||
<boot dev='hd'/>
|
||||
</os>
|
||||
<features>
|
||||
<acpi/>
|
||||
<apic/>
|
||||
</features>
|
||||
<cpu mode='host-passthrough' check='none' migratable='on'/>
|
||||
<clock offset='utc'>
|
||||
<timer name='rtc' tickpolicy='catchup'/>
|
||||
<timer name='pit' tickpolicy='delay'/>
|
||||
<timer name='hpet' present='no'/>
|
||||
</clock>
|
||||
<on_poweroff>destroy</on_poweroff>
|
||||
<on_reboot>restart</on_reboot>
|
||||
<on_crash>destroy</on_crash>
|
||||
<pm>
|
||||
<suspend-to-mem enabled='no'/>
|
||||
<suspend-to-disk enabled='no'/>
|
||||
</pm>
|
||||
<devices>
|
||||
<emulator>/usr/libexec/qemu-kvm</emulator>
|
||||
<disk type='file' device='disk'>
|
||||
<driver name='qemu' type='qcow2' discard='unmap'/>
|
||||
<source file='/var/lib/libvirt/images/$vm_name.qcow2'/>
|
||||
<target dev='vda' bus='virtio'/>
|
||||
<address type='pci' domain='0x0000' bus='0x04' slot='0x00' function='0x0'/>
|
||||
</disk>
|
||||
<disk type='file' device='cdrom'>
|
||||
<driver name='qemu' type='raw'/>
|
||||
<target dev='sda' bus='sata'/>
|
||||
<readonly/>
|
||||
<address type='drive' controller='0' bus='0' target='0' unit='0'/>
|
||||
</disk>
|
||||
<controller type='usb' index='0' model='qemu-xhci' ports='15'>
|
||||
<address type='pci' domain='0x0000' bus='0x02' slot='0x00' function='0x0'/>
|
||||
</controller>
|
||||
<controller type='pci' index='0' model='pcie-root'/>
|
||||
<controller type='pci' index='1' model='pcie-root-port'>
|
||||
<model name='pcie-root-port'/>
|
||||
<target chassis='1' port='0x10'/>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0' multifunction='on'/>
|
||||
</controller>
|
||||
<controller type='pci' index='2' model='pcie-root-port'>
|
||||
<model name='pcie-root-port'/>
|
||||
<target chassis='2' port='0x11'/>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x1'/>
|
||||
</controller>
|
||||
<controller type='pci' index='3' model='pcie-root-port'>
|
||||
<model name='pcie-root-port'/>
|
||||
<target chassis='3' port='0x12'/>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x2'/>
|
||||
</controller>
|
||||
<controller type='pci' index='4' model='pcie-root-port'>
|
||||
<model name='pcie-root-port'/>
|
||||
<target chassis='4' port='0x13'/>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x3'/>
|
||||
</controller>
|
||||
<controller type='pci' index='5' model='pcie-root-port'>
|
||||
<model name='pcie-root-port'/>
|
||||
<target chassis='5' port='0x14'/>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x4'/>
|
||||
</controller>
|
||||
<controller type='pci' index='6' model='pcie-root-port'>
|
||||
<model name='pcie-root-port'/>
|
||||
<target chassis='6' port='0x15'/>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x5'/>
|
||||
</controller>
|
||||
<controller type='pci' index='7' model='pcie-root-port'>
|
||||
<model name='pcie-root-port'/>
|
||||
<target chassis='7' port='0x16'/>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x6'/>
|
||||
</controller>
|
||||
<controller type='pci' index='8' model='pcie-root-port'>
|
||||
<model name='pcie-root-port'/>
|
||||
<target chassis='8' port='0x17'/>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x7'/>
|
||||
</controller>
|
||||
<controller type='pci' index='9' model='pcie-root-port'>
|
||||
<model name='pcie-root-port'/>
|
||||
<target chassis='9' port='0x18'/>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0' multifunction='on'/>
|
||||
</controller>
|
||||
<controller type='pci' index='10' model='pcie-root-port'>
|
||||
<model name='pcie-root-port'/>
|
||||
<target chassis='10' port='0x19'/>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x1'/>
|
||||
</controller>
|
||||
<controller type='pci' index='11' model='pcie-root-port'>
|
||||
<model name='pcie-root-port'/>
|
||||
<target chassis='11' port='0x1a'/>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x2'/>
|
||||
</controller>
|
||||
<controller type='pci' index='12' model='pcie-root-port'>
|
||||
<model name='pcie-root-port'/>
|
||||
<target chassis='12' port='0x1b'/>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x3'/>
|
||||
</controller>
|
||||
<controller type='pci' index='13' model='pcie-root-port'>
|
||||
<model name='pcie-root-port'/>
|
||||
<target chassis='13' port='0x1c'/>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x4'/>
|
||||
</controller>
|
||||
<controller type='pci' index='14' model='pcie-root-port'>
|
||||
<model name='pcie-root-port'/>
|
||||
<target chassis='14' port='0x1d'/>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x5'/>
|
||||
</controller>
|
||||
<controller type='sata' index='0'>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x1f' function='0x2'/>
|
||||
</controller>
|
||||
<controller type='virtio-serial' index='0'>
|
||||
<address type='pci' domain='0x0000' bus='0x03' slot='0x00' function='0x0'/>
|
||||
</controller>
|
||||
<interface type='network'>
|
||||
<mac address='52:54:00:c6:ca:2b'/>
|
||||
<source network='default'/>
|
||||
<model type='virtio'/>
|
||||
<address type='pci' domain='0x0000' bus='0x01' slot='0x00' function='0x0'/>
|
||||
</interface>
|
||||
<serial type='pty'>
|
||||
<target type='isa-serial' port='0'>
|
||||
<model name='isa-serial'/>
|
||||
</target>
|
||||
</serial>
|
||||
<console type='pty'>
|
||||
<target type='serial' port='0'/>
|
||||
</console>
|
||||
<channel type='unix'>
|
||||
<target type='virtio' name='org.qemu.guest_agent.0'/>
|
||||
<address type='virtio-serial' controller='0' bus='0' port='1'/>
|
||||
</channel>
|
||||
<input type='tablet' bus='usb'>
|
||||
<address type='usb' bus='0' port='1'/>
|
||||
</input>
|
||||
<input type='mouse' bus='ps2'/>
|
||||
<input type='keyboard' bus='ps2'/>
|
||||
<graphics type='vnc' port='-1' autoport='yes'>
|
||||
<listen type='address'/>
|
||||
</graphics>
|
||||
<audio id='1' type='none'/>
|
||||
<video>
|
||||
<model type='vga' vram='16384' heads='1' primary='yes'/>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x0'/>
|
||||
</video>
|
||||
<watchdog model='itco' action='reset'/>
|
||||
<memballoon model='virtio'>
|
||||
<address type='pci' domain='0x0000' bus='0x05' slot='0x00' function='0x0'/>
|
||||
</memballoon>
|
||||
<rng model='virtio'>
|
||||
<backend model='random'>/dev/urandom</backend>
|
||||
<address type='pci' domain='0x0000' bus='0x06' slot='0x00' function='0x0'/>
|
||||
</rng>
|
||||
</devices>
|
||||
</domain>
|
||||
|
||||
|
||||
EOF
|
||||
|
||||
)
|
||||
|
||||
# 创建磁盘镜像
|
||||
|
||||
qemu-img create -f qcow2 /var/lib/libvirt/images/$vm_name.qcow2 $(($disk_size * 1024))G
|
||||
|
||||
}
|
||||
|
||||
plchuangjian(){
|
||||
read -p "请输入虚拟机数量: " count
|
||||
|
||||
for ((i=1; i<=$count; i++)); do
|
||||
|
||||
dgchuangjian
|
||||
|
||||
done
|
||||
}
|
||||
plchaungjian1(){
|
||||
read -p "请输入虚拟机数量: " count
|
||||
|
||||
for ((i=1; i<=$count; i++)); do
|
||||
|
||||
read -p "请输入虚拟机名称: " vm_name
|
||||
|
||||
memory=2097152
|
||||
|
||||
vcpus=2
|
||||
|
||||
disk_size=10
|
||||
|
||||
dgchuangjian
|
||||
|
||||
done
|
||||
}
|
||||
shanchu(){
|
||||
virsh list --all | awk '/^.{2}/ { print $2 }'
|
||||
|
||||
read -p "请输入要删除的虚拟机名称: " vm_name
|
||||
|
||||
virsh destroy $vm_name
|
||||
|
||||
virsh undefine $vm_name
|
||||
|
||||
rm -f /var/lib/libvirt/images/$vm_name.qcow2
|
||||
|
||||
echo "虚拟机 '$vm_name' 已删除。"
|
||||
}
|
||||
tc(){
|
||||
exit
|
||||
}
|
||||
while :
|
||||
do
|
||||
list
|
||||
read -p "请输入您的选项:(1/2/3/4/5)" num
|
||||
case $num in
|
||||
1)
|
||||
dgchuangjian
|
||||
sleep 3
|
||||
;;
|
||||
2)
|
||||
plchuangjian
|
||||
sleep 3
|
||||
;;
|
||||
3)
|
||||
plchuangjian1
|
||||
sleep 3
|
||||
;;
|
||||
4)
|
||||
shanchu
|
||||
sleep 3
|
||||
;;
|
||||
5)
|
||||
tc
|
||||
sleep 1
|
||||
;;
|
||||
*)
|
||||
echo -e "\033[41;37m 请您按要求输入!!!!!! \033[0m"
|
||||
;;
|
||||
esac
|
||||
done
|
71
MD/O.sh
Normal file
71
MD/O.sh
Normal file
@ -0,0 +1,71 @@
|
||||
#/bin/bash
|
||||
#功能函数
|
||||
mem(){
|
||||
mem_total=`free -m |awk NR==2'{print $2}'`
|
||||
mem_used=`free -m |awk NR==2'{print $3}'`
|
||||
mem_free=`free -m |awk NR==2'{print $4}'`
|
||||
mem_cache=`free -m |awk NR==2'{print $6}'`
|
||||
mem_s=$((${mem_used}*100/${mem_total}))
|
||||
mem_f=$((100-$mem_s))
|
||||
echo "内存的使用率: $mem_s"
|
||||
echo "内存的总量: $mem_total"
|
||||
echo "内存的空闲率: $mem_f"
|
||||
echo "内存的缓存量: $mem_cache"
|
||||
echo "内存的空闲量: $mem_free"
|
||||
}
|
||||
disk(){
|
||||
read -p "请输入分区名称:" name
|
||||
case $name in
|
||||
"/")
|
||||
echo `df -Th | awk NR==2'{print "总量:"$3,"使用:"$4,"空闲:"$5}'`
|
||||
;;
|
||||
"/boot")
|
||||
echo `df -Th | awk NR==7'{print "总量:"$3,"使用:"$4,"空闲:"$5}'`
|
||||
;;
|
||||
esac
|
||||
|
||||
}
|
||||
system_info(){
|
||||
cat /etc/redhat-release | awk '{print "系统版本号:"$4}'
|
||||
echo "内核版本为:`uname -r`"
|
||||
ip a | grep "2:" | awk -F: '{print "网卡名称:"$2}'
|
||||
ip a | grep "cope global" | awk '{print $2}' |awk -F "/" '{print "IP地址是:"$1}'
|
||||
}
|
||||
cpu_info(){
|
||||
w | awk -F: NR==1'{print "CPU的平均负载:"$NF}'
|
||||
vmstat | awk NR==3'{print "CPU空闲率:"$(NF-2)}'
|
||||
cpu_id=`vmstat | awk NR==3'{print $(NF-2)}'`
|
||||
cpu_free=$((100-$cpu_id))
|
||||
echo "CPU使用率: $cpu_free"
|
||||
|
||||
}
|
||||
install_yum(){
|
||||
rm -rf /etc/yum.repos.d/*
|
||||
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
|
||||
curl -o /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/repo/epel-7.repo
|
||||
yum clean all &>/dev/null
|
||||
yum makecache fast &>/dev/nul
|
||||
}
|
||||
stop_firewalld(){
|
||||
systemctl stop firewalld && systemctl disable firewalld &>/dev/null
|
||||
setenforce 0 &>/dev/null
|
||||
sed -i '/^SELINUX/c SELINUX=disabled' /etc/selinux/config
|
||||
|
||||
}
|
||||
list(){
|
||||
cat <<EOF
|
||||
a: 内存使用情况
|
||||
b: 磁盘使用情况
|
||||
c: 服务器信息
|
||||
d: CPU使用情况
|
||||
e: YUM源更换
|
||||
f: 关闭防火墙
|
||||
q: 退出
|
||||
EOF
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
30
MD/P.sh
Normal file
30
MD/P.sh
Normal file
@ -0,0 +1,30 @@
|
||||
#!/bin/bash
|
||||
source ./O.sh
|
||||
while :
|
||||
do
|
||||
list
|
||||
read -p "请输入您的选项:" num
|
||||
case $num in
|
||||
a)
|
||||
mem
|
||||
;;
|
||||
b)
|
||||
disk
|
||||
;;
|
||||
c)
|
||||
system_info
|
||||
;;
|
||||
d)
|
||||
cpu_info
|
||||
;;
|
||||
e)
|
||||
install_yum
|
||||
;;
|
||||
f)
|
||||
stop_firewalld
|
||||
;;
|
||||
q)
|
||||
exit
|
||||
;;
|
||||
esac
|
||||
done
|
41
MD/xtrabackup.sh
Normal file
41
MD/xtrabackup.sh
Normal file
@ -0,0 +1,41 @@
|
||||
#!/usr/bin/env bash
|
||||
#write by blackmed/xingdian
|
||||
#xtrabackup
|
||||
read -p "请输入mysql的root密码:" mima
|
||||
time=`date +%a`
|
||||
if [ "${time}" == "Mon" ];then
|
||||
mkdir /backup/full -p
|
||||
innobackupex --user=root --password=${mima} /backup/full/
|
||||
elif [ "${time}" == "Tue" ];then
|
||||
cd /backup/full/;ls >/tmp/a.txt
|
||||
mkdir /backup/zeng
|
||||
file1=`cat /tmp/a.txt | sed '/^$/!h;$!d;g'`
|
||||
innobackupex --user=root --password=${mima} --incremental /backup/zeng/ --incremental-basedir=/backup/full/${file1}
|
||||
|
||||
elif [ "${time}" == "Wed" ];then
|
||||
cd /backup/zeng;ls >/tmp/a.txt
|
||||
file2=`cat /tmp/a.txt | sed '/^$/!h;$!d;g'`
|
||||
innobackupex --user=root --password=${mima} --incremental /backup/zeng/ --incremental-basedir=/backup/zeng/${file2}
|
||||
|
||||
elif [ "${time}" == "Thu" ];then
|
||||
cd /backup/zeng;ls >/tmp/a.txt
|
||||
file3=`cat /tmp/a.txt | sed '/^$/!h;$!d;g'`
|
||||
innobackupex --user=root --password=${mima} --incremental /backup/zeng/ --incremental-basedir=/backup/zeng/${file3}
|
||||
|
||||
elif [ "${time}" == "Fri" ];then
|
||||
cd /backup/zeng;ls >/tmp/a.txt
|
||||
file4=`cat /tmp/a.txt | sed '/^$/!h;$!d;g'`
|
||||
innobackupex --user=root --password=${mima} --incremental /backup/zeng/ --incremental-basedir=/backup/zeng/${file4}
|
||||
|
||||
elif [ "${time}" == "Sat" ];then
|
||||
cd /backup/zeng;ls >/tmp/a.txt
|
||||
file5=`cat /tmp/a.txt | sed '/^$/!h;$!d;g'`
|
||||
innobackupex --user=root --password=${mima} --incremental /backup/zeng/ --incremental-basedir=/backup/zeng/${file5}
|
||||
|
||||
elif [ "${time}" == "Sun" ];then
|
||||
cd /backup/zeng;ls >/tmp/a.txt
|
||||
file6=`cat /tmp/a.txt | sed '/^$/!h;$!d;g'`
|
||||
innobackupex --user=root --password=${mima} --incremental /backup/zeng/ --incremental-basedir=/backup/zeng/${file6}
|
||||
else
|
||||
echo ${time}
|
||||
fi
|
63
MD/zhuwenbao.sh
Normal file
63
MD/zhuwenbao.sh
Normal file
@ -0,0 +1,63 @@
|
||||
#!/usr/bin/bash
|
||||
#1判断路径是否存在及判断为目录或者文件
|
||||
#read -p "请输入文件的绝对路径: " file_dir
|
||||
#if [ -e $file_dir ] ; then
|
||||
# if [ -d $file_dir ] ; then
|
||||
# echo "$file_dir 为目录路径"
|
||||
# else
|
||||
# echo "$file_dir 为文件路径"
|
||||
# fi
|
||||
#else
|
||||
# echo "$file_dir 不存在"
|
||||
#fi
|
||||
##2判断IP是否能够被ping通
|
||||
#read -p "请输入一个IP: " ip_dir
|
||||
#ping -c 1 $id_dir &>/dev/null
|
||||
#if [ $? -eq 0 ] ; then
|
||||
# echo "该IP:$ip_dir 可以被ping通" | mail -s "结果" 15630451592@163.com
|
||||
#else
|
||||
# echo "该IP:$ip_dir 不可以被ping通" | mail -s "结果" 15630451592@163.com
|
||||
#fi
|
||||
##3配置NFS服务
|
||||
#systemctl stop firewalld
|
||||
#systemctl disable firewalld
|
||||
#setenforce 0
|
||||
#read -p "请输入一个对外共享的目录: " mkdir_dir
|
||||
#if [ -d $mkdir_dir ] ; then
|
||||
# echo "该目录已存在可以直接设置为共享目录"
|
||||
#else
|
||||
# mkdir $mkdir_dir -p
|
||||
# echo "已创建新的共享目录"
|
||||
#fi
|
||||
#rpm -qa | grep nfs-utils
|
||||
#if [ $? -ne 0 ] ; then
|
||||
# echo "该软件包正在安装..."
|
||||
# yum -y install nfs-utils &>/dev/null
|
||||
# systemctl start nfs
|
||||
# systemctl enable nfs
|
||||
# read -p "请输入共享IP或*: " ip_dir
|
||||
# cat >>/etc/exports<<ABC
|
||||
#$mkdir_dir $ip_dir(ro,sync,no_root_squash)
|
||||
#ABC
|
||||
# exportfs -rv &>/dev/null
|
||||
# systemctl restart nfs
|
||||
#else
|
||||
# echo "该软件包已安装"
|
||||
#fi
|
||||
##4删除空文件
|
||||
#read -p "请输入一个目录路径: " mkdir_dir4
|
||||
#file_ex_count=`find $mkdir_dir4 -empty | wc -l`
|
||||
#find $mkdir_dir4 -empty -delete &>/dev/null
|
||||
#echo "已删除所有空文件"
|
||||
#echo "空文件个数为$file_ex_count"
|
||||
#5报警脚本
|
||||
disk_size=`df -Th | grep centos-root | awk '{print $(NF-1)}' | awk -F'%' '{print $1}'`
|
||||
mem_total=`free -m | awk NR==2'{print $2}'`
|
||||
mem_used=`free -m | awk NR==2'{print $3}'`
|
||||
if [ $disk_size -gt 80 ]; then
|
||||
echo "根分区剩余空间不足20%" | mail -s "disk_warn" alice@163.com
|
||||
fi
|
||||
mem_used_=$(($mem_used*100/$mem_total))
|
||||
if [ $mem_used_ -gt 80 ];then
|
||||
echo "内存已用空间大于80%" | mail -s "mem_used" alice@163.com
|
||||
fi
|
Loading…
Reference in New Issue
Block a user