FTP服务器 SQL serverWEB服务器 windos server Exchange ISA server 域服务器 其他服务器 服务器虚拟化技术 网站技术 Linux操作系统 服务器硬件技术 服务器阵列技术
返回首页
当前位置: 主页 > 服务器技术 > WEB服务器 >

CentOS6.x下通过shell脚本交互安装Web服务

时间:2014-06-23 12:32来源:未知 作者:admin 点击:
CentOS6.x下通过shell脚本交互安装Web服务 PS:写脚本的初衷,是为了方便自己更有效率的去工作,同时锻炼自己写脚本的能力,当然还希望能够给大家带来一些小的帮助,希望大家多多支持,评论评论,指出不足的地方。 一、测试环境 1 2 3 4 5 6 7 [root@hello ~]

 CentOS6.x下通过shell脚本交互安装Web服务

PS:写脚本的初衷,是为了方便自己更有效率的去工作,同时锻炼自己写脚本的能力,当然还希望能够给大家带来一些小的帮助,希望大家多多支持,评论评论,指出不足的地方。

服务器配置网

 

copyright by http://www.server-cn.com/

一、测试环境 服务器配置网

1
2
3
4
5
6
7
[root@hello ~]# uname -r
2.6.32-279.el6.x86_64
[root@hello ~]# cat /etc/issue
CentOS release 6.3 (Final)
Kernel \r on an \m
[root@hello ~]# dmidecode -s system-product-name
VMware Virtual Platform

copyright by http://www.server-cn.com/

服务器配置网

二、交互式安装Web服务脚本 服务器配置网

注:在编译安装apche之前,必须确保你当前的系统中安装了Additional Development、Development tools、Base软件包组,其中包含了apache所需的库文件与编译工具,zlib,gcc,automake,pcre等,不然安装可能无法完成。 服务器配置网

  copyright by http://www.server-cn.com/

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
[root@hello scripts]# cat auto_install_web.sh
#!/bin/bash
#blog http://cfwlxf.blog.51cto.com
#create date of 2013-10-30
#Load user environment variable
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
export PATH
#source system functions library.
. /etc/init.d/functions
#definition software download and install directoy
SOURCE_DIR=/download/source/
INSTALL_DIR=/application/
#Judge SOURCE_DIR INSTALL_DIR directoy if exits.
[ ! -d ${SOURCE_DIR} ] && mkdir ${SOURCE_DIR} -p
[ ! -d ${INSTALL_DIR} ] && mkdir ${INSTALL_DIR} -p && sleep 1 && printf "\033[32mDirectory $SOURCE_DIR $INSTALL_DIR by create.\033[0m"
#Download httpd software
printf "\033[33m
        ----------------------------------------------------------------------------
        |               Welcome to use apache auto install scripts                 |
        ----------------------------------------------------------------------------\033[0m\n"
printf "\033[36mDownload Web Server of sourece package,please input staring \'y/n\': \033[0m" STR
read STR
#Judge User input of string if by 'y'
if [ $STR = "y" ]
then
        printf "\033[32m
        ----------------------------------------------------------------------------
        |                          Apache Software List                            |
        ----------------------------------------------------------------------------
        |1.Download web server software of httpd.2.4.4 versions.                   |
        |2.Download web server software of httpd.2.2.25 versions.                  |
        |3.Download web server software of httpd.2.4.6 versions.                   |
        ----------------------------------------------------------------------------
        \033[0m\n\n"
        read -p "Please you input number'1-4', select httpd install of httpd versions: " VERSIONS
        case "$VERSIONS" in
                1)
                        cd ${SOURCE_DIR}
                        wget http://mirrors.hust.edu.cn/apache/httpd/httpd-2.4.4.tar.gz
                        ;;
                2)
                        cd ${SOURCE_DIR}
                        wget http://mirrors.hust.edu.cn/apache/httpd/httpd-2.2.25.tar.gz
                        ;;
                3)
                        cd ${SOURCE_DIR}
                        wget http://mirrors.hust.edu.cn/apache/httpd/httpd-2.4.6.tar.gz
                        ;;
                *)
                        sleep 1
                        printf "\033[31mError: Please input number \'1-4\',select httpd versions.\033[0m\n"
                        exit 0
        esac
else
        sleep 2
        printf "\033[31mError: You enter the error string,Please anew input.\033[0m\n"
        exit 0
fi
#Uncompress httpd software package
cd ${SOURCE_DIR}
HTTPD_SOFTWARE=$(find /download/source/ -type f | grep httpd |awk 'BEGIN{FS="/"}END{print $4}')
tar -xf ${HTTPD_SOFTWARE} && sleep 2 && printf "\033[35mUncompress software by successfully.\033[0m\n"
#Judge current directoy yes or on uncompress later of directory
HTTPD_UNCOMPRESS=$(find ./ -maxdepth 1 -type d | grep httpd)
cd ${HTTPD_UNCOMPRESS}
RETURN_PWD=$(pwd | cut -d '/' -f4)
ECHO_HTTPD=$(echo ${HTTPD_UNCOMPRESS}|awk 'BEGIN{FS="/"}END{print $2}')
#Judge whether the current directory if uncompress after of directory
if [ ${RETURN_PWD} = ${ECHO_HTTPD} ]
then
        sleep 1
        printf "\033[33mIf you need support \'--with-included-arp\',please download software after install,\'yes/no\': \033[0m" DOWNLOAD
        read DOWNLOAD
        if "$DOWNLOAD" "yes" ]
        then
                wget http://mirrors.hust.edu.cn/apache/apr/apr-1.4.6.tar.gz
                wget http://mirrors.hust.edu.cn/apache/apr/apr-util-1.4.1.tar.gz
                #Judge download apr apr-util file of exits.
                APR_FILE=$(find ./ -maxdepth 1 -type f |  sed -n '/apr-1/p' | grep -Po '(?<=./).*')
                APR_UTIL_FILE=$(find ./ -maxdepth 1 -type f |  sed -n '/apr-util/p' | grep -Po '(?<=./).*')
                [ -e $APR_FIEL $APR_UTIL_FILE ] && sleep 2 && printf "\033[35mDownload File $APR_FILE,$APR_UTIL_FILE already successfully.\033[0m\n"
                #Uncompress apr apr-util software package.
                APACHE_UNCOMPRESS_FILE=$(find /download/source/ -maxdepth 1 -type d| grep httpd)
                APACHE_UNCOMPRESS_SRCLIB_DIR=${APACHE_UNCOMPRESS_FILE}/srclib/
                tar -xf $APR_FILE -C $APACHE_UNCOMPRESS_SRCLIB_DIR && tar -xf $APR_UTIL_FILE -C $APACHE_UNCOMPRESS_SRCLIB_DIR && cd $APACHE_UNCOMPRESS_SRCLIB_DIR
                APR_UNCOMPRESS_FILE=$(find ./  -maxdepth 1 -type d | grep 'apr-1' | grep -Po '(?<=./).*')
                APR_UTIL_UNCOMPRESS_FILE=$(find ./  -maxdepth 1 -type d | grep 'apr-util' | grep -Po '(?<=./).*')
                mv -f $APR_UNCOMPRESS_FILE apr && mv -f $APR_UTIL_UNCOMPRESS_FILE apr-util && sleep 2 && action "Uncompress file apr aprutil is successfully." true
                #configure apache
                APACHE_UNCOMPRESS_FILE=$(find /download/source/ -maxdepth 1 -type d| grep httpd)
                cd $APACHE_UNCOMPRESS_FILE
                ./configure --prefix=/application/${ECHO_HTTPD} --enable-substitute --enable-deflate --enable-expires --enable-ssl --enable-http --enable-rewrite --enable-so --with-mpm=worker --enable-mods-shared=mos --with-z --with-included-apr
        else
                #configure apache
                APACHE_UNCOMPRESS_FILE=$(find /download/source/ -maxdepth 1 -type d| grep httpd)
                cd $APACHE_UNCOMPRESS_FILE
                ./configure --prefix=/application/${ECHO_HTTPD} --enable-substitute --enable-deflate --enable-expires --enable-ssl --enable-http --enable-rewrite --enable-so --with-mpm=worker --enable-mods-shared=mos --with-z
        fi
else
        printf "\033[31mError: Your current of directory fault $ECHO_HTTPD.\033[0m\n"
                exit 0
fi
#Compile apache software package
RETVAL=0
make && [ $? = $RETVAL ] && make install
sleep 2 && printf  "\033[35mApache compile is successfully,please start apache server of 'yes/no\': \033[0m" START
read START
APACHE_BIN=$(find /application/ -maxdepth 1 -type d | grep httpd)
"$START" "yes" ] && ${APACHE_BIN}/bin/apachectl start > /dev/null 2>&1
#Judge elinsk sottware of already install.
SERVER_IP=$(ifconfig eth0  | grep 'inet addr:'| sed 's/.*r:\(.*\) B.*$/\1/g')
ELINKS_RPM=$(rpm -qa elinks| wc -l)
[ $ELINKS_RPM = 1 ] && elinks --dump http://$SERVER_IP/index.html
[ $ELINKS_RPM != 1 ] && yum install elinks && elinks --dump http://$SERVER_IP/index.html

  内容来自服务器配置网

#提示: 本文来自服务器配置网

脚本执行过程中,会提示用户选择apache的版本,若脚本中所提供的版本都不能满足公司需求的话,那么你可以把需要的版本链接添加至脚本,略做修改即可。如果对APR不了解的朋友,可以点击网址:http://baike.baidu.com/link?url=8NJ28ufytnW1h6opu-Z3q3sVaAN82__ePE9okiCUkwsP-WB6ymhYGFmitXL5gUPg3MUaWpTVgglBnAfrRqDAdK 详细了解,脚本可能还有很多不足的地方,欢迎大家评论。 http://www.server-cn.com/

三、实例演示

http://www.server-cn.com/

  http://www.server-cn.com/

CentOS6.x下通过shell脚本交互安装Web服务

  copyright by http://www.server-cn.com/

  服务器配置网

CentOS6.x下通过shell脚本交互安装Web服务

 

内容来自服务器配置网

 

http://www.server-cn.com/

CentOS6.x下通过shell脚本交互安装Web服务

#提示: 本文来自服务器配置网

脚本中所提供的apache版本,都已测试通过,有需求的运维朋友们可以按照自己的思维,略作修改后使用。我觉得大家刚好可以借照此脚本,去编写一个LAMP,LNMP环境交互式安装的脚本,或者自动安装的脚本,动动手提升你写脚本的能力,避免繁琐的操作,有效率,也能突出你自己的实力。

copyright by http://www.server-cn.com/

  服务器配置网

(责任编辑:admin)
顶一下
(0)
0%
踩一下
(0)
0%
------分隔线----------------------------
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
验证码:点击我更换图片
推荐内容