vi /root/serverkaiji.sh
#!/bin/bash ls /tlvnksc/ | egrep -v "^c|^f" > /root/service.list for name in $(more /root/service.list) do workhome=/tlvnksc/${name}/ workjar=${workhome}${name}.jar nohup java -jar ${workjar} > ${workhome}spring.log & done
[root@localhost ~]# cat /root/service.list
dygaeureka
dygazuul
cp serverkaiji.sh stopserverkaiji.sh
vi stopserverkaiji.sh
#!/bin/bash ls /tlvnksc/ | egrep -v "^c|^f" > /root/service.list for name in $(more /root/service.list) do pid=`ps -ef|grep ${name}.jar|grep -v 'grep' | awk '{print $2}'` kill -9 $pid done
chmod 700 serverkaiji.sh
vi /usr/lib/systemd/system/jar-server.service
[Unit]
Description=jar
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
ExecStart=/root/serverkaiji.sh
ExecStop=/root/stopserverkaiji.sh
[Install]
WantedBy=multi-user.target
systemctl enable jar-server.service
systemctl status jar-server.service
systemctl stop jar-server.service
systemctl start jar-server.service
参考
https://www.cnblogs.com/feixiablog/p/8426881.html
多目录遍历拷贝
vi /testlvnksc/cpxm.sh
#!/bin/bash for name in $(more /root/service.list) do /testlvnksc/fabu.sh ${name} done
vi /testlvnksc/fabu.sh
#!/bin/bash
A=$1
cp -r dygaeureka $A
sed -i 's/dygaeureka/'$A'/g' $A/deploy.sh
cat $A/deploy.sh
ls /testlvnksc/dygaeureka
vi /root/service.list
a b
https://www.bilibili.com/video/av68396271?p=2
mysql备份脚本
sudo crontab -l
0 * * * * sh /root/databak.sh
vi /root/databak.sh
#!/bin/bash date=$(date +%Y%m%d%H%M%S) /opt/mysql/mysql-5.7.26-el7-x86_64/bin/mysqldump -uroot -p'xxx' -A > /root/$date-192.168.1.135.sql if [ $? -eq 0 ];then echo “数据库备份完成” scp /root/$date-192.168.1.135.sql 192.168.1.112:/data/rsyncdata/databak/ sleep 4 echo “远程备份完成” rm -rf /root/$date-192.168.1.135.sql fi
rsync服务端日志打包删除旧包数据
sudo tar cfz /data/date-databak.tar.gz /data/rsyncdata/databak #测试打包 sh /data/tar-dabao.sh #测试任务 crontab -e 0 0 * * * vi tar-dabao.sh #!/bin/bash date=$(date +%Y%m%d%H%M) sudo tar cfz /data/rsyncdata/$date-databak.tar.gz /data/rsyncdata/databak sleep 4 rm -rf /data/rsyncdata/databak/*
防火墙规则检测不存在这插入
vi iptables.sh
#!/bin/sh function admin() { status=$(iptables -nvL | grep 192.168.100.118 | wc -l) if [ $status -eq 0 ]; then iptables -I INPUT -s 192.168.100.118 -j ACCEPT echo "防火墙设置完成" else echo "防火墙已经设置过了" exit 0; fi } function admin2() { status=$(iptables -nvL | grep 192.168.100.119 | wc -l) if [ $status -eq 0 ]; then iptables -I INPUT -s 192.168.100.119 -j ACCEPT echo "防火墙设置完成" else echo "防火墙已经设置过了" exit 0; fi } echo "设置防火墙通过100.119" admin2 echo "设置防火墙通过100.118" admin
海云镜像转换脚本
#/bin/bash # 转换镜像 function zhjingxiang() { jxname="$jx" qemu-img convert -f vmdk -O raw $jxname.vmdk $jxname.raw if [ $? -eq 0 ]; then echo "$jxname.vmdk 镜像转换成功" else echo "$jxname.vmdk 镜像转换失败" exit 0; fi } # 查询虚拟机对应 硬盘uuid function chaxhd() { hduuid=`cinder list --all | grep $xnuuid | awk '{print $2 ,$10}'` echo " $hduuid " } #替换指定的硬盘号 function rhd() { rbd ls volumes | grep $ruuid rbd rm volumes/volumes-$ruuid echo "删除硬盘文件成功" rbd import $jxname.raw volumes/volumes-$ruuid echo "导入硬盘文件成功" } read -p "请输入需要转换的镜像名 注意不带格式:" jx zhjingxiang source /etc/kolla/openrc read -p "请输入需要查询的虚拟机uuid:" xnuuid chaxhd read -p "请输入需要替换的硬盘uuid:" ruuid rhd echo "正在删除转换后的$jxname.raw 镜像 请稍等......" rm $jxname.raw