• linux shell每天一阅 -- 安装nginx以及apache


    当然这个博客原代码是转载大神的。。。

    自动安装Nginx脚本,采用case方式,选择方式,也可以根据实际需求改成自己想要的脚本mynginx.sh

    1. #!/bin/sh  
    2.   
    3. ###nginx install shell  
    4. ###wugk 2012-07-14  
    5. ###PATH DEFINE  
    6.   
    7. SOFT_PATH=/data/soft/  
    8. NGINX_FILE=nginx-1.2.0.tar.gz  
    9. DOWN_PATH=http://nginx.org/download/  
    10.   
    11. if[ $UID -ne 0 ];then  
    12. echo This script must use administrator or root user ,please exit!  
    13. sleep 2  
    14. exit 0  
    15. fi  
    16.   
    17. if[ ! -d $SOFT_PATH ];then  
    18. mkdir -p $SOFT_PATH  
    19. fi  
    20.   
    21. download ()  
    22. {  
    23. cd $SOFT_PATH ;wget $DOWN_PATH/$NGINX_FILE  
    24. }  
    25.   
    26. install ()  
    27. {  
    28. yum install pcre-devel -y  
    29. cd $SOFT_PATH ;tar xzf $NGINX_FILE ;cd nginx-1.2.0/ &&./configure –prefix=/usr/local/nginx/ –with-http_stub_status_module –with-http_ssl_module  
    30. [ $? -eq 0 ]&&make &&make install   #[ ]条件判断用的可以
    31. }  
    32.   
    33. start ()  
    34. {  
    35. lsof -i :80[ $? -ne 0 ]&&/usr/local/nginx/sbin/nginx   #lsof -i :80 //显示所有打开80端口的进程
    36. }  
    37.   
    38. stop ()  
    39. {  
    40. ps -ef |grep nginx |grep -v grep |awk ‘{print $2}’|xargs kill -9  #本文最nice的一个就是用了xargs这个命令,将上一个命令的输出作为下一个命令的参数
    41. }  
    42.   
    43. exit ()  
    44. {  
    45. echo $? ;exit  
    46. }  
    47.   
    48. ###case menu #####  
    49.   
    50. case $1 in  
    51. download )  
    52. download  
    53. ;;  
    54.   
    55. install )  
    56. install  
    57. ;;  
    58.   
    59. start )  
    60. start  
    61. ;;  
    62. stop )  
    63. stop  
    64. ;;  
    65.   
    66. * )  
    67.   
    68. echo “USAGE:$0 {download or install or start or stop}”  
    69. exit  
    70. esac 

    脚本执行:

    ./mynginx.sh download

    ./mynginx.sh install

    ./mynginx.sh start

    ./mynginx.sh stop

    下文为apache shell脚本: 1 #!/bin/sh 2

     3 #by z.jason 2017-05-02
     4 #using install apache
     5 
     6 
     7 if [ $UID -ne 0 ]; then
     8 echo " you must are root or administrator,please exit ! "
     9 sleep 2
    10 exit 0
    11 fi
    12 
    13 yum_download ()
    14 {
    15 wget http://mirrors.163.com/.help/CentOS6-Base-163.repo # update yum
    16 }
    17 
    18 install ()
    19 {
    20 yum -y install httpd
    21 }
    22 
    23 start ()
    24 {
    25 lsof -i :80
    26 
    27 if [ $? -ne 0 ];then
    28 
    29    service httpd start
    30 
    31 else
    32 
    33    echo "apache is running !"
    34 
    35 fi
    36 #当然可以一句写成 lsof -i :80;[ $? -ne 0 ]&&service httpd start||echo "apache is running ! "就是如果lsof没有输出就会返回1,也就是失败的意思。
    37 } 38 39 stop () 40 { 41 42 ps -ef |grep httpd |grep -v grep |awk ‘{print $2}’|xargs kill -9 43 #service httpd stop 44 } 45 46 restart () 47 { 48 servcie httpd restart 49 } 50 51 case $1 in 52 yum_download ) 53 yum_download 54 ;; 55 56 install ) 57 install 58 ;; 59 60 start ) 61 start 62 ;; 63 64 stop ) 65 stop 66 ;; 67 68 restart ) 69 restart 70 ;; 71 72 * ) 73 echo "please input yum_download or install or start or stop or restart" 74 esac

    脚本执行:

    ./myapache.sh yum_download

    ./myapache.sh install

    ./myapache.sh start

    ./myapache.sh stop

     其实两个代码的区别还是有的,前者使用源码安装,而后者使用yum安装,个人比较喜欢用yum,因为yum简单而且不用去处理软件的依赖关系。

  • 相关阅读:
    【JVM】程序计数器(四)
    【JVM】运行时数据区概述及线程(三)
    【JVM】类加载子系统(二)
    MyException--org.apache.ibatis.exceptions.PersistenceException: ### Error building SqlSession. ###
    计算机常用指令大全
    HTML的设计与应用
    想得太多,又做的太少
    互联网数据库分库分表现状及一点思考
    python中的函数与文件操作
    python中的流程控制语句
  • 原文地址:https://www.cnblogs.com/zengjieboke/p/6792603.html
Copyright © 2020-2023  润新知