快连VPN:速度和安全性最佳的VPN服务
巡檢意義
巡檢腳本
vim /root/dean.sh
#! /bin/bash# Author:Dean# Web:https://www.bunian.cn# 微信公衆號:不念博客#color notesNC='33[0m'GREEN='33[0;32m'RED='33[0;31m'YELLOW='33[0;33m'cyan='33[0;36m'yellow='33[0;33m'#Sectioning .........echo -e "${YELLOW}---------------------------------------------------------------------------------------------------------------${NC}"echo "Server details:"echo -e "${YELLOW}---------------------------------------------------------------------------------------------------------------${NC}"#fetching basic specs from the server(user,ip,os)user=`whoami`echo -e "${cyan}User:${NC} $user"hostname=`hostname`echo -e "${cyan}hostname:${NC} $hostname"ip=`hostname -I`echo -e "${cyan}IP address:${NC} $ip"os=`cat /etc/os-release | grep 'NAME|VERSION' | grep -v 'VERSION_ID' | grep -v 'PRETTY_NAME' | grep NAME`echo -e "${cyan}OS:${NC} $os"#Sectioning.....echo -e "${YELLOW}---------------------------------------------------------------------------------------------------------------${NC}"echo "Service status:"echo -e "${YELLOW}---------------------------------------------------------------------------------------------------------------${NC}"sleep 1#checking tomcat statusecho -e "${yellow}1) Tomcat${NC}"#grepping tomcat status from ps auxpp=`ps aux | grep tomcat | grep "[D]java.util"`if [[ $pp =~ "-Xms512M" ]];then echo -e " Status: ${GREEN}UP${NC}"else echo -e " Status: ${RED}DOWN${NC}"fiecho ""#function to check apache is running or not!function apache(){echo -e "${yellow}2) Apache-httpd${NC}"#grepping apache status from ps auxhttpd=`ps aux | grep httpd | grep apache`if [[ $httpd =~ "apache" ]];then echo -e " Status: ${GREEN}UP${NC}"else echo -e " Status: ${RED}DOWN${NC}"fi}#function to check elastic is running or notfunction elastic(){echo -e "${yellow}3) Elasticsearch${NC}"#grepping elasticsearch status from ps auxelastic=`ps aux | grep elasticsearch`if [[ $elastic =~ "elastic+" ]];thenecho -e " Status: ${GREEN}UP${NC}"else echo -e "Status: ${RED}DOWN${NC}"fi#function to check mysql is running or not}function mysql(){echo -e "${yellow}4) Mysql${NC}"#grepping mysql status from ps auxmysql=`ps aux | grep mysqld`if [[ $mysql =~ "mysqld" ]];then echo -e " Status: ${GREEN}UP${NC}"else echo -e " Status: ${RED}DOWN${NC}"fi}function docker(){echo -e "${yellow}5) Docker${NC}"#grepping docker status from ps auxdocker=`systemctl status docker | grep dead`if [[ $docker =~ "dead" ]];then echo -e " Status: ${GREEN}UP${NC}"else echo -e " Status: ${RED}DOWN${NC}"fi}#calling functionsapacheecho ""elasticecho ""mysqlecho ""dockerecho ""#Sectioning............#Fetching mem and cpu informationsecho -e "${YELLOW}---------------------------------------------------------------------------------------------------------------${NC}"echo "Memory Details:"echo -e "${YELLOW}---------------------------------------------------------------------------------------------------------------${NC}"sleep 1#view mem infofree -h#get uptime detailsuptime=$(uptime | awk '{print $3,$4}' | cut -f1 -d,)echo -e "${cyan}System Uptime:${NC} :$uptime"#Fetching the load averageloadaverage=$(top -n 1 -b | grep "load average:" | awk '{print $10 $11 $12}')echo -e "${cyan}Load average:${NC}: $loadaverage"echo -e "${cyan}The top 10 services with high resource usage are listed below.${NC}"#Get top services with high resource utilizationps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem | head#sectioning...........#Fetching server space details!echo -e "${YELLOW}---------------------------------------------------------------------------------------------------------------${NC}"echo "Server space Details:"echo -e "${YELLOW}---------------------------------------------------------------------------------------------------------------${NC}"#View disk space detailsdf -hecho "----------------------------------------------------------------------------------------------------------------"登錄後複製
我們可以將該腳本轉換爲全局命令,將文件移動到 sbin 目錄,並賦予執行權限。
mv /root/dean.sh /usr/sbinchmod +x /usr/sbin/dean.sh登錄後複製
添加至別名裏
vim /root/.bashrcalias dean='sh /usr/sbin/dean.sh'登錄後複製
生效
source .bashrc登錄後複製
現在您可以在 shell 的任何位置調用該腳本。
dean登錄後複製
執行效果
優勢
- 只需一個命令就可以輕鬆訪問完整的服務器信息,並且還可以在出現問題時安排警報通知。
- 編輯腳本並添加服務非常簡單。
- 顯示有關正在運行的進程、磁盤空間、宕機時間、內存詳細信息、高進程列表等的詳細信息。
以上就是實戰:運維必備Linux巡檢腳本的詳細內容,更多請關注本站其它相關文章!