nginx.php等服务管理练习脚本

->nginx的启动状态

root@jumpserver- day02]# cat nginx_web.sh
#!/bin/bash
source /etc/init.d/functions nginx_status() {
if [ $? -eq ];then
action "nginx is $1 OK!" /bin/true
else
action "nginx is $1 failed!" /bin/false
fi
} case $ in
start)
nginx &>/dev/null
nginx_status $
;;
stop)
nginx -s stop &>/dev/null
nginx_status $
;;
reload)
nginx -s reload &>/dev/null
nginx_status $
;;
*)
echo "USAGE:$0{start|stop|reload}"
esac

->安装nginx->查看状态

echo "===============================System Repo============================="
Repos=$(yum repolist |grep nginx|wc -l)
if [ $Repos -eq ];then echo "没有发现Nginx的yum仓库...尝试中" cat >/etc/yum.repos.d/nginx.repo <<-EOF #使用cat方法导入
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/x86_64/
gpgcheck=
enabled=
EOF yum makecache &>/dev/null #清空缓存 Repos2=$(yum repolist |grep nginx|wc -l) #再次yum尝试安装 if [ $Repos2 -eq ];then
echo "yum仓库已经安装完成...."
else
echo "请检查你的网络环境...."
exit
fi
else echo "已存在Nginx的Repos仓库文件..." fi echo "===============================System Nginx Install=======================" Rpm_Nginx=$(rpm -qa nginx | wc -l) if [ $Rpm_Nginx -gt ];then
echo "Nginx 已经安装....."
else
echo "尝试安装Nginx...."
yum install nginx -y &>/dev/null
fi echo "=======================System Nginx Status ======================" Nginx_Status=$(systemctl status nginx|grep running|wc -l)
if [ $Nginx_Status -eq ];then echo "Nginx已经启动" else
echo "Nginx尝试启动" pkill httpd &>/dev/null
pkill nginx &>/dev/null systemctl start nginx &>/dev/null if [ $? -eq ];then
Nginx_Status2=$(systemctl status nginx|grep Active|awk '{print $2 $3}')
echo "nginx启动完成, 当前的状态是: $Nginx_Status2"
else
echo "启动失败, 请手动排查......"
fi
fi

->nginx状态管理

[root@jumpserver- scripts]# cat nginx_status.sh
#!/bin/bash echo "-----------------------"
echo "1:开启"
echo "2:停止"
echo "3:重载"
echo "4:重启"
echo "5:状态"
echo "-----------------------" read -p "请输入您要执行的命令:" command case $command in
)
status_start=$(systemctl status nginx | egrep "running" |wc -l)
if [ $status_start -eq ];then echo "nginx已经启动,不需要执行启动操作"
else
systemctl start nginx &>/dev/null
echo "nginx已经启动"
fi
;;
)
systemctl stop nginx &>/dev/null
echo "nginx已经停止"
;;
)
status_start=$(systemctl status nginx | egrep "running" |wc -l)
if [ $status_start -eq ];then
systemctl reload nginx &>/dev/null
echo "nginx已经重载"
fi
;;
)
systemctl restart nginx &>/dev/null
echo "nginx已经重启"
;;
)
systemctl status nginx
;;
*)
echo "请您选择正确的命令"
exit
esac

->nginx状态监控脚本(zabbix)

[root@web03 day01]# cat nginx_status.sh
#!/bin/bash
############################################################
# $Name: nginx_status.sh
# $Version: v1.
# $Function: Nginx Status
# $Author:
# $organization:
# $Create Date: --
# $Description: Monitor Nginx Service Status
############################################################ NGINX_COMMAND=$
NGINX_PORT= nginx_active(){
/usr/bin/curl -s "http://127.0.0.1:"$NGINX_PORT"/nginx_status/" |awk '/Active/ {print $NF}'
} nginx_reading(){
/usr/bin/curl -s "http://127.0.0.1:"$NGINX_PORT"/nginx_status/" |awk '/Reading/ {print $2}'
} nginx_writing(){
/usr/bin/curl -s "http://127.0.0.1:"$NGINX_PORT"/nginx_status/" |awk '/Writing/ {print $4}'
} nginx_waiting(){
/usr/bin/curl -s "http://127.0.0.1:"$NGINX_PORT"/nginx_status/" |awk '/Waiting/ {print $6}'
} nginx_accepts(){
/usr/bin/curl -s "http://127.0.0.1:"$NGINX_PORT"/nginx_status/" |awk 'NR==3 {print $1}'
} nginx_handled(){
/usr/bin/curl -s "http://127.0.0.1:"$NGINX_PORT"/nginx_status/" |awk 'NR==3 {print $2}'
} nginx_requests(){
/usr/bin/curl -s "http://127.0.0.1:"$NGINX_PORT"/nginx_status/" |awk 'NR==3 {print $3}'
} case $NGINX_COMMAND in
active)
nginx_active;
;;
reading)
nginx_reading;
;;
writing)
nginx_writing;
;;
waiting)
nginx_waiting;
;;
accepts)
nginx_accepts;
;;
handled)
nginx_handled;
;;
requests)
nginx_requests;
;;
*)
echo $"USAGE:$0 {active|reading|writing|waiting|accepts|handled|requests}"
esac

->简单参考版
[root@web03 scripts]# cat nginx_status.sh
#!/bin/bash port= while true
do if [ $# -eq ];then
case $ in
active)
curl -s 127.0.0.1${port}/status | awk '/Active/{print $NF}'
break
;;
accepts)
curl -s 127.0.0.1${port}/status | awk 'NR==3{print $1}'
break
;;
handled)
curl -s 127.0.0.1${port}/status | awk 'NR==3{print $2}'
break
;;
request)
curl -s 127.0.0.1${port}/status | awk 'NR==3{print $3}'
break
;;
*)
echo "USAGE $0 {active|accepts|requests|handled}"
exit
esac
else
echo "参数只能为1个,请参考{active|accepts|requests|handled}"
break
fi
done

->根据系统版本安装yum源

[root@jumpserver- scripts]# cat repo.sh
#!/bin/bash os_name=$(cat /etc/redhat-release )
os_version=$(cat /etc/redhat-release |awk -F " " '{print $4}'| awk -F "." '{print $1}') if [ $os_version -eq ];then echo "这是$os_name的系统,请安装centos7的yum源"
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo &>/dev/null
echo "$os_name:yum源安装完成" elif [ $os_version -eq ];then echo "这是$os_name系统,请安装centos6的yum源"
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo &>/dev/null
echo "$os_name:yum源安装完成" elif [ $os_version -eq ];then echo "这是$os_name系统,请安装centos6的yum源"
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-5.repo &>/dev/null
echo "$os_name:yum源安装完成" else
echo "请检查系统的版本" fi

->选择php版本安装

[root@jumpserver- scripts]# cat php.sh
#!/bin/bash echo '1=(php-5.0)'
echo '2=(php-6.0)'
echo '3=(php-7.0)' read -p "请输入要安装的版本:" num if [ $num -eq ];then echo "正在安装php5.0" elif [ $num -eq ];then echo "正在安装php6.0" elif [ $num -eq ];then echo "正在安装7.0"
else
echo "请选择安装版本"
fi

shell服务管理->的更多相关文章

  1. 烂泥:学习tomcat之通过shell批量管理多个tomcat

    本文由ilanniweb提供友情赞助,首发于烂泥行天下 想要获得更多的文章,可以关注我的微信ilanniweb 公司的业务是使用tomcat做web容器,为了更有效的利用服务器的性能,我们一般部署多个 ...

  2. [MySQL Reference Manual] 5 MySQL 服务管理

    5. MySQL 服务管理 5. MySQL 服务管理 5.1 The Mysql Server 5.2 Mysql 服务日志 5.2.1 选择General query log和slow query ...

  3. 如何写SysV服务管理脚本

    本文目录: 1.1 SysV脚本的特性1.2 SysV脚本要具备的能力1.3 start函数分析1.4 stop函数分析1.5 reload函数分析1.6 status.restart.force-r ...

  4. centOS7服务管理与启动流程

    centOS7服务管理与启动流程 centOS7启动流程 systemd简介 unit对象 unit类型 特性 service unit文件格式 service unit file文件通常由三部分组成 ...

  5. Linux之服务管理

    一.计划任务 1) Crontab简介 1.Crontab是一个用于设置周期性被执行任务的工具: 2.被周期性执行的任务我们称为Cron Job: 3.周期性执行的任务列表我们称为Cron Table ...

  6. (二)Linux实操之——网络配置、进程管理、服务管理、组管理、YUM

    接上段   (一)Linux实操之——权限.任务调度.磁盘分区 4.网络配置 4.1 NAT模式的网络配置 目前我们采用的网络配置是NAT模式. windows下cmd通过 ipconfig 命令可以 ...

  7. centos linux系统日常管理3 服务管理ntsysv,chkconfig,系统日志rsyslog,last ,lastb ,exec,xargs,dmesg,screen,nohup,curl,ping ,telnet,traceroute ,dig ,nc,nmap,host,nethogs 第十六节课

    centos linux系统日常管理3  服务管理ntsysv,chkconfig,系统日志rsyslog,last ,lastb ,exec,xargs,dmesg,screen,nohup,cur ...

  8. Linux学习笔记(3)linux服务管理与启停

    一.LINUX 系统服务管理 1.RHEL/OEL 6.X及之前 service命令用于对系统服务进行管理,比如启动(start).停止(stop).重启(restart).查看状态(status)等 ...

  9. Linux软件安装——服务管理的命令

    Linux软件安装——服务管理的命令 摘要:本文主要学习了Linux系统中服务管理的命令. service命令 service命令用于对系统服务进行管理,比如启动(start).停止(stop).重启 ...

随机推荐

  1. MT【137】多少个?

    数列\(\{a_n\}\)共11项,\(a_1=0,a_{11}=4\),且\(|a_{k+1}-a_{k}|=2,k=1,2,\cdots,10\) 求满足条件的不同的数列的个数______ 解答: ...

  2. SDOI2017硬币游戏

    题面链接 洛咕 sol 神题,幸好我不是SD的QAQ. 假设你们都会\(O(n^3m^3)\)的高斯消元,具体来说就是建出\(Trie\)图然后套游走的板子. 然后我们发现可以把不能匹配任何串的概率压 ...

  3. 洛谷 P1053 逛公园 解题报告

    P3953 逛公园 问题描述 策策同学特别喜欢逛公园. 公园可以看成一张\(N\)个点\(M\)条边构成的有向图,且没有自环和重边.其中1号点是公园的入口,\(N\)号点是公园的出口,每条边有一个非负 ...

  4. 单点登录(十一)-----遇到问题-----cas启用mongodb验证方式报错--Unable to locate Spring NamespaceHandler for XML schema na

    cas启用mongodb验证方式报错--Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.sp ...

  5. JVM 垃圾回收机制和常见算法

    垃圾回收机制:释放那些不再持有引用的对象的内存. 如何判断对象是否需要回收? 引用计数:对象,内存,磁盘空间等被引用次数保存起来,次数为0时将其进行释放. 对象引用遍历:对象应用遍历从一组对象开始,沿 ...

  6. listview android:cacheColorHint,android:listSelector属性作用(转)

    ListView是常用的显示控件,默认背景是和系统窗口一样的透明色,如果给ListView加上背景图片,或者背景颜色时,滚动时listView会黑掉, 原因是,滚动时,列表里面的view重绘时,用的依 ...

  7. Android学习笔记——关于onConfigurationChanged(转)

    从事Android开发,免不了会在应用里嵌入一些广告SDK,在嵌入了众多SDK后,发现几乎每个要求在AndroidManifest.xml申明Activity的广告SDK都会要求加上注明这么一句属性: ...

  8. python之旅:模块与包

    一.模块介绍 前言:引用廖雪峰大神的,说的很好!!! 在计算机程序的开发过程中,随着程序代码越写越多,在一个文件里代码就会越来越长,越来越不容易维护. 为了编写可维护的代码,我们把很多函数分组,分别放 ...

  9. 【位运算】判断一个数是否为2的n次方

    import java.util.Scanner; /** * 功能:用位运算,判断一个数是否为2的n次方. * 思路:用1做移位操作,然后判断移位后的值是否与给定的数相同. */ public cl ...

  10. 论C语言中二级指针和二维数组之间的区别

    刚开始学习C语言的时候,觉得一个数组可以定义一个一级指针去访问,想当然的就觉得可以定义一个二级指针去访问二维数组.很显然这是错误的. 我们来看看C语言的数组在内存中的存储方式. 实际上C语言中的数组, ...