前瞻:
用於多站點操做,基於ansible批量化操做
前提須要安裝ansible且在nginx.conf中添加以下參數
include /usr/local/nginx/conf/denyIP;
在conf下建立denyIP,將屏蔽ip寫入denyIP便可屏蔽
touch denyIP
由於使用的ansible因此每一個zhandian(1-6)實際上在ansible/hosts中都是包含了多個站點的nginx
#!/bin/bash read -p "請輸入須要屏蔽的IP: " forbidip cat << EOF ---------------------------------------- |***************站點列表***************| ---------------------------------------- `echo -e "\033[35m 1)zhandian-1\033[0m"` `echo -e "\033[35m 2)zhandian-2\033[0m"` `echo -e "\033[35m 3)zhandian-3\033[0m"` `echo -e "\033[35m 4)zhandian-4\033[0m"` `echo -e "\033[35m 5)zhandian-5\033[0m"` `echo -e "\033[35m 6)zhandian-6\033[0m"` EOF read -p "請輸入須要執行的站點編號:" cmd case $cmd in 1) sudo /usr/bin/ansible zhandian-1 -m shell -a "sudo sed -i '\$a\deny ${forbidip};' /usr/local/nginx/conf/denyIP" && sudo ansible zhandian-1 -m shell -a "sudo systemctl restart nginx";; 2) sudo /usr/bin/ansible zhandian-2 -m shell -a "sudo sed -i '\$a\deny ${forbidip};' /usr/local/nginx/conf/denyIP" && sudo ansible zhandian-2 -m shell -a "sudo systemctl restart nginx";; 3) sudo /usr/bin/ansible zhandian-3 -m shell -a "sudo sed -i '\$a\deny ${forbidip};' /usr/local/nginx/conf/denyIP" && sudo ansible zhandian-3 -m shell -a "sudo systemctl restart nginx";; 4) sudo /usr/bin/ansible zhandian-4 -m shell -a "sudo sed -i '\$a\deny ${forbidip};' /usr/local/nginx/conf/denyIP" && sudo ansible zhandian-4 -m shell -a "sudo systemctl restart nginx";; 5) sudo /usr/bin/ansible zhandian-5 -m shell -a "sudo sed -i '\$a\deny ${forbidip};' /usr/local/nginx/conf/denyIP" && sudo ansible zhandian-5 -m shell -a "sudo systemctl restart nginx";; 6) sudo /usr/bin/ansible zhandian-6 -m shell -a "sudo sed -i '\$a\deny ${forbidip};' /usr/local/nginx/conf/denyIP" && sudo ansible zhandian-6 -m shell -a "sudo systemctl restart nginx";; *) echo "errpr:please in input (1,2,3,4,5,6)";; esac