Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2549338
  • 博文数量: 271
  • 博客积分: 6659
  • 博客等级: 准将
  • 技术积分: 3141
  • 用 户 组: 普通用户
  • 注册时间: 2009-11-17 10:24
文章分类

全部博文(271)

文章存档

2016年(2)

2015年(12)

2014年(7)

2013年(19)

2012年(22)

2011年(81)

2010年(128)

分类: 系统运维

2011-10-01 18:49:44

  1. ###################################auto_lamp.sh##########################################

  2. #!/bin/bash
  3. # -*- coding: utf-8 -*-
  4. #-------------------------------------------------------------------------------
  5. # Name: auto_lamp.sh
  6. # Purpose:
  7. #
  8. # Author: hjjie2006.cublog.cn
  9. # Mail: hjjie2006@126.com
  10. # Created: 01/10/2011
  11. # Copyright: (c) hjjie 2011
  12. #
  13. #-------------------------------------------------------------------------------
  14. # -*- coding: utf-8 -*-
  15. #设定所需的安装包
  16. #安装前请准备以下源码包 对于GD库的安装则调用另一个脚本 因此将gdsetup.sh与包放同一目录当中
  17. MYSQL_PKG='mysql-5.1.36.tar.gz'
  18. HTTPD_PKG='httpd-2.2.11.tar.gz'
  19. PHP_PKG='php-5.2.10.tar.gz'

  20. ##下面这部分是GD库所需的源码包
  21. ##ZLIB_PKG='zlib-1.2.3.tar.gz'
  22. ##PNG_PKG='libpng-1.2.26.tar.gz'
  23. ##FREETYPE_PKG='freetype-2.3.5.tar.gz'
  24. ##JPEG_PKG='jpegsrc.v6b.tar.gz'
  25. ##FRONTCONF_PKG='fontconfig-2.4.2.tar.gz'
  26. ##GD_PKG='gd-2.0.35.tar.gz'
  27. ###对于GD安装时报错时安装
  28. ##GETTEXT_PKG='gettext-0.17.tar.gz'
  29. ##LIBXML='libxml2-2.6.31.tar.gz'

  30. ##提供的http 地址 用于下载源码包
  31. ##HTTP_DOWNLOAD=192.168.166.173/install
  32. #-------------------------------------------------------------------------------
  33. #源码包存放在当前脚本所在位置
  34. PKG_PATH=$(pwd)
  35. #GD库安装脚本
  36. GDLIB_SETUP=$PKG_PATH/gdsetup.sh

  37. #defined Installation path
  38. #mysql Installation path
  39. MYSQL_PATH=/usr/local/mysql
  40. #mysql data Installation path
  41. MYSQL_DATADIR=${MYSQL_PATH}/var
  42. #apache Installation path
  43. HTTPD_PATH=/usr/local/apache2
  44. #gdlib Installation path
  45. GDLIB_PATH=/usr/local/libgd #此处如果时需要将GD库安装脚本也一并修改
  46. #php Installation path
  47. PHP_PATH=/usr/local/php #如果GD库中各相关库路径有改动 需要将php编译参数中也一并修改
  48. #mysql 运行用户
  49. MYSQL_USER=mysql
  50. MYSQL_GROUP=mysql
  51. #-------------------------------------------------------------------------------

  52. #去除tar.gz
  53. MYSQL_PKG_=$(echo $MYSQL_PKG |sed 's/.tar.gz//')
  54. HTTPD_PKG_=$(echo $HTTPD_PKG |sed 's/.tar.gz//')
  55. PHP_PKG_=$(echo $PHP_PKG |sed 's/.tar.gz//')

  56. cat << EOF
  57. #############################################
  58.   1.$MYSQL_PKG_ install
  59.   2.$HTTPD_PKG_ install
  60.   3.GD-lib install
  61.   4.$PHP_PKG_ install
  62.   5.LAMP Environment install
  63. #############################################
  64. EOF

  65. #Color select
  66. result_output(){


  67.     if [ $1 = failed ];then #红色 失败 #[FAILED]
  68.         if [ -z "$2" ];then
  69.             echo -e "[$1]\033[32;31;1m [[FAILED]] \033[39;49;0m"
  70.         else
  71.             echo -e "[$1]\033[32;31;1m [[$2]] \033[39;49;0m"
  72.         fi
  73.     elif [ $1 = ok ];then #绿色 成功 #[ OK ]
  74.         if [ -z "$2" ];then
  75.             echo -e "[$1]\033[32;49;1m [[OK]] \033[39;49;0m"
  76.         else
  77.             echo -e "[$1]\033[32;49;1m [[$2]] \033[39;49;0m"
  78.         fi
  79.     elif [ $1 = warn ];then #蓝色背景 红色前景 用于警告 [warn]
  80.         if [ -z "$2" ];then
  81.             echo -e "[$1]\033[44;31;1m [[WARNING]] \033[0m"
  82.         else
  83.             echo -e "[$1]\033[44;31;1m [[$2]] \033[0m"
  84.         fi
  85.     fi
  86. }

  87. #退出状态检查
  88. exec_check(){
  89.     if [ $? != 0 ];then
  90.         result_output failed
  91.         exit 1
  92.     else
  93.         result_output ok
  94.         sleep 1
  95.     fi
  96. }

  97. #检查相关RPM是否安装 remove
  98. rpm_exist_check(){
  99. rpm_is_exist=$(rpm -qa | grep $rpm_info)
  100.     if [ ! -z "$rpm_is_exist" ];then
  101.         yum -y remove mysql-server
  102.     fi
  103. }

  104. #检查文件是否存在/不存在进行下载
  105. file_exist_check(){

  106.     if [ -f $file_name ];then
  107.         result_output ok "$file_name is already exist"
  108.     else
  109.         result_output failed "$file_name is not exist"
  110.         result_output warn "Please Download $file_name ..."
  111.         exit 1
  112.     fi
  113. }

  114. #检查是否已经安装
  115. installpath_exist_check(){
  116.     if [ -d $install_path ];then
  117.         result_output warn "$install_path already exists!!!!"
  118.         if [ "$select_name" == "LAMP environment" ];then
  119.         cat << EOF
  120. +++++++++++++++++++++++++++++++++++++++++++++++++++++++++

  121. [r/R] will be removed $install_path; and continue this
  122. [c/C] will be quit this install and continue Next-install !!
  123. Do not select everying,installation program will

  124. +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  125. EOF
  126.         else
  127.         cat << EOF
  128. +++++++++++++++++++++++++++++++++++++++++++++++++++++++++

  129. [r/R] will be removed $install_path; and continue this
  130. Do not select everying,installation program will

  131. +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  132. EOF
  133.         fi
  134.         read -p "Please enter your select:" s
  135.         if [ "$s" == "r" -o "$s" == "R" ];then
  136.             echo "Remove $install_path"
  137.             sleep 1
  138.             rm -rf $install_path
  139.         elif [ "$s" == "c" -o "$s" == "C" ];then
  140.             result_output ok "Conntinue next install ...."
  141.             echo
  142.             return_set=1 #if the return_set value is not null ; the install function whill break
  143.         else
  144.             echo "Do not select everying,installation program quit!\n"
  145.             exit 0
  146.         fi
  147.     fi
  148. }
  149. #Mysql安装
  150. mysql_install(){
  151.     install_path="$MYSQL_PATH"
  152.     installpath_exist_check
  153.     if [ ! -z $return_set ];then
  154.         return_set='' #设置变量 return_set='' 初始化为空
  155.         return 1 #break
  156.     fi
  157.     rpm_info="mysql-server"
  158.     rpm_exist_check
  159.     #用户检查/添加
  160.     group_mysql_exist=$(grep mysql /etc/passwd)
  161.     user_mysql_exist=$(cat /etc/passwd | grep mysql)
  162.     if [ -z "$group_mysql_exist" ];then
  163.         groupadd $MYSQL_USER
  164.         else
  165.         result_output warn "group $MYSQL_GROUP is already exist"
  166.     fi

  167.     if [ -z "$user_mysql_exist" ];then
  168.         useradd $MYSQL_USER -c "start mysqld's account" -d /dev/null -g $MYSQL_GROUP -s /sbin/nologin
  169.     else
  170.         result_output warn "user $MYSQL_USER is already exist"
  171.     fi

  172.     file_name=$MYSQL_PKG
  173.     file_exist_check

  174.     tar zxvf $PKG_PATH/$MYSQL_PKG
  175.     cd $PKG_PATH/$MYSQL_PKG_

  176.     cd $PKG_PATH/$MYSQL_PKG_
  177.     exec_check


  178.     ./configure \
  179.     --prefix=$MYSQL_PATH \
  180.     --enable-thread-safe-client \
  181.     --with-charset=utf8 \
  182.     --with-extra-charsets=all \
  183.     --enable-assembler
  184.     exec_check

  185.     make && make install
  186.     exec_check

  187.     rm -f /etc/my.cnf
  188.     cp support-files/my-medium.cnf /etc/my.cnf
  189.     $MYSQL_PATH/bin/mysql_install_db --user=$MYSQL_USER
  190.     chown -R root:$MYSQL_GROUP $MYSQL_PATH
  191.     chown -R $MYSQL_USER:$MYSQL_GROU $MYSQL_DATADIR
  192.     result_output ok "$MYSQL_PKG is complete install"
  193. }

  194. #apache 安装
  195. apache_install(){

  196.     install_path="$HTTPD_PATH"
  197.     installpath_exist_check
  198.     if [ ! -z $return_set ];then
  199.         return_set=''
  200.         return 1
  201.     fi

  202.     rpm_info="http"
  203.     rpm_exist_check

  204.     file_name=$HTTPD_PKG
  205.     file_exist_check

  206.     tar zxvf $HTTPD_PKG
  207.     cd $PKG_PATH/$HTTPD_PKG_


  208.     ./configure --prefix=$HTTPD_PATH \
  209.     --enable-so \
  210.     --enable-rewrite

  211.     exec_check
  212.     make && make install
  213.     exec_check

  214.     result_output ok "$HTTPD_PKG_ is complete install"
  215. }

  216. #GD 库安装
  217. gdlib_install(){

  218.     exec_check(){
  219.         if [ $? != 0 ];then
  220.             result_output failed "Num:$num 命令:$cmd 执行结果:FAILED"
  221.             exit 1
  222.         else
  223.             result_output ok "Num:$num 命令:$cmd 执行结果:OK "
  224.             sleep 2
  225.         fi
  226.     }
  227.     install_path="$GDLIB_PATH"
  228.     installpath_exist_check
  229.     if [ ! -z $return_set ];then
  230.         return_set=''
  231.         return 1
  232.     fi
  233.     #安装GD库时产生的临时文件 - 记录执行的单条命令
  234.     GDLIB_CMD=${PKG_PATH}/gdlib_cmd
  235.     #安装GD库时中间如果报错然后去再次执行时 就从报错的那断
  236.     GDLIB_LABLE=${PKG_PATH}/gdlib_lable
  237.     #对执行到的命令行数进行记录
  238.     GDLIB_NUM=${PKG_PATH}/gdlib_num
  239.     #记录执行过程中最近一次的cd目录
  240.     GDLIB_PWD=${PKG_PATH}/gdlib_pwd
  241.     #将GD安装脚本清理注释
  242.     GDLIB_SETUP_TEMP=${PKG_PATH}/gdlib_setup_temp
  243.     grep -v '^$' $GDLIB_SETUP | grep -v '^#' > $GDLIB_SETUP_TEMP

  244.     IFS=$'\n'
  245.     error_info=''
  246.     num=0
  247.     if [ -s $GDLIB_LABLE ];then
  248.         GDLIB_SETUP=$GDLIB_LABLE
  249.         num=$(expr $(cat $GDLIB_NUM) - 1)
  250.         cd $(cat $GDLIB_PWD)
  251.     fi
  252.     for cmd in $(grep -v '^$' $GDLIB_SETUP | grep -v '^#');do
  253.         sleep 0.5

  254.         echo "$cmd" > $GDLIB_CMD
  255.         num=$(expr $num + 1)
  256.         echo $num > $GDLIB_NUM
  257.         #echo -n "$num"
  258.         sed -n "$num",'$p' $GDLIB_SETUP_TEMP > $GDLIB_LABLE
  259.         #exec_check
  260.         if grep 'cd' $GDLIB_CMD >/dev/null;then
  261.             source $GDLIB_CMD
  262.             tem_dir=$(pwd)
  263.             echo $tem_dir > $GDLIB_PWD
  264.             #echo "tem_dir==$tem_dir"
  265.             cd $tem_dir
  266.             exec_check
  267.             continue
  268.         elif grep 'tar' $GDLIB_CMD >/dev/null;then
  269.             cd $PKG_PATH
  270.         fi
  271.         sh $GDLIB_CMD
  272.         exec_check
  273.     done
  274.     rm -rf $GDLIB_LABLE
  275.     rm -rf $GDLIB_NUM
  276.     rm -rf $GDLIB_CMD
  277.     rm -rf $GDLIB_SETUP_TEMP
  278.     rm -rf $GDLIB_PWD
  279.     cmd=''
  280.     result_output ok "GD Install Successful!!!"
  281.     IFS=$' \t\n'
  282. }

  283. #PHP安装
  284. php_install(){
  285.     install_path="$PHP_PATH"
  286.     installpath_exist_check
  287.     if [ ! -z $return_set ];then
  288.         return_set=''
  289.         return 1
  290.     fi
  291.     error_info=''
  292.     if ! $GDLIB_PATH/bin/gdlib-config --version >/dev/null;then
  293.         result_output failed "GD_LIB error or not installed"
  294.         exit 1
  295.     fi
  296.     if ! $MYSQL_PATH/bin/mysql -V >/dev/null;then
  297.         result_output failed "$MYSQL_PKG_ error or not installed"
  298.         exit 1
  299.     fi
  300.     if ! $HTTPD_PATH/bin/apachectl -v >/dev/null;then
  301.         result_output failed "$HTTPD_PKG_ error or not installed"
  302.         exit 1
  303.     fi

  304.     install_path="$PHP_PATH"
  305.     installpath_exist_check

  306.     tar -xzvf $PKG_PATCH/$PHP_PKG
  307.     cd $PKG_PATH/$PHP_PKG_
  308.     ./configure --prefix=$PHP_PATH \
  309.     --with-apxs2=$HTTPD_PATH/bin/apxs \
  310.     --with-mysql=$MYSQL_PATH \
  311.     --with-gd=/usr/local/libgd \
  312.     --enable-gd-native-ttf \
  313.     --with-ttf \
  314.     --enable-ftp \
  315.     --enable-gd-jis-conv \
  316.     --with-freetype-dir=/usr/local/freetype \
  317.     --with-jpeg-dir=/usr/local/libjpeg \
  318.     --with-png-dir=/usr \
  319.     --with-zlib-dir=/usr/local/zlib \
  320.     --enable-xml \
  321.     --enable-mbstring \
  322.     --enable-sockets
  323.     exec_check
  324.     make && make install
  325.     exec_check
  326.     cp php.ini-dist /usr/local/php/lib/php.ini
  327.     exec_check
  328. }
  329. #LAMP
  330. lamp_install(){
  331.     #如果已安装则跳过 继续安装下面部分
  332.     mysql_install
  333.     apache_install
  334.     gdlib_install
  335.     php_install
  336. }

  337. case_select(){
  338.     read -p "Are you sure install the $select_name ?[y/Y]" s
  339.     if [ "$s" == "y" -o "$s" == "Y" ];then
  340.             $select_install
  341.     else
  342.             echo "Do not select [y/Y],installation program quit!\n"
  343.             exit 1
  344.     fi
  345.     }
  346. read -p "Please enter the installation program number:" n

  347. case $n in
  348.     1)
  349.         select_name=$MYSQL_PKG_
  350.         select_install=mysql_install
  351.         case_select
  352.         ;;
  353.     2)
  354.         select_name=$HTTPD_PKG_
  355.         select_install=apache_install
  356.         case_select
  357.         ;;
  358.     3)
  359.         select_name=gdlib
  360.         select_install=gdlib_install
  361.         case_select
  362.         ;;
  363.     4)
  364.         select_name=$PHP_PKG_
  365.         select_install=php_install
  366.         case_select
  367.         ;;
  368.     5)
  369.         select_name="LAMP environment"
  370.         select_install=lamp_install
  371.         case_select
  372.         ;;
  373.     *)
  374.         echo "Do not select [y/Y],installation program quit!\n"
  375.         exit 1
  376. esac



  377. ####这里是另一个脚本##这里是另一个脚本###gdsetup.sh###这里是另一个脚本#####这里是另一个脚本###
    1. #!/bin/bash
    2. # -*- coding: utf-8 -*-
    3. #-------------------------------------------------------------------------------
    4. # Name: gdsetup.sh
    5. # Purpose:
    6. # Author: hjjie.cublog.cn
    7. # Mail: hjjie2006@126.com
    8. #
    9. # Created: 28/09/2011
    10. # Copyright: (c) Jerome 2011
    11. #
    12. #-------------------------------------------------------------------------------
    13. #(1).安装zlib
    14. tar -xzvf zlib-1.2.3.tar.gz
    15. cd zlib-1.2.3
    16. ./configure --prefix=/usr/local/zlib
    17. make && make install

    18. #(2).安装libpng
    19. tar zxvf libpng-1.2.26.tar.gz
    20. cd libpng-1.2.26/scripts/
    21. mv makefile.linux ../makefile
    22. cd ..
    23. make && make install
    24. #注意,这里的makefile不是用./configure生成,而是直接从scripts/里拷一个

    25. #3).安装freetype
    26. tar -xzvf freetype-2.3.5.tar.gz
    27. cd freetype-2.3.5
    28. ./configure --prefix=/usr/local/freetype
    29. make && make install

    30. #4).安装Jpeg
    31. tar -zxvf jpegsrc.v6b.tar.gz
    32. cd jpeg-6b/
    33. mkdir -p /usr/local/libjpeg
    34. mkdir -p /usr/local/libjpeg/include
    35. mkdir -p /usr/local/libjpeg/bin
    36. mkdir -p /usr/local/libjpeg/lib
    37. mkdir -p /usr/local/libjpeg/man
    38. mkdir -p /usr/local/libjpeg/man/man1
    39. ./configure --prefix=/usr/local/libjpeg --enable-shared --enable-static
    40. make && make install
    41. #注意,这里configure一定要带--enable-shared参数,不然,不会生成共享库

    42. #5).安装Fontconfig
    43. tar -zxvf fontconfig-2.4.2.tar.gz
    44. cd fontconfig-2.4.2
    45. ./configure --with-freetype-config=/usr/local/freetype/bin/freetype-config
    46. make && make install

    47. #6).安装gettext
    48. #cp /usr/lib/libattr.* /lib/
    49. tar -vxzf gettext-0.17.tar.gz
    50. cd gettext-0.17
    51. ./configure
    52. make && make install

    53. #7).安装GD
    54. tar -zxvf gd-2.0.35.tar.gz
    55. cd gd-2.0.35
    56. ./configure --prefix=/usr/local/libgd --with-png --with-freetype=/usr/local/freetype --with-jpeg=/usr/local/libjpeg --enable-m4_pattern_allow
    57. make && make install

    58. #8).编辑/etc/ld.so.conf,添加以下几行到此文件中
    59. if ! grep '/usr/local/zlib/lib' /etc/ld.so.conf >/dev/null; then echo '/usr/local/zlib/lib' >>/etc/ld.so.conf ;fi
    60. if ! grep '/usr/local/freetype/lib' /etc/ld.so.conf >/dev/null; then echo '/usr/local/freetype/lib' >>/etc/ld.so.conf ;fi
    61. if ! grep '/usr/local/libjpeg/lib' /etc/ld.so.conf >/dev/null; then echo '/usr/local/libjpeg/lib' >>/etc/ld.so.conf ;fi
    62. if ! grep '/usr/local/libgd/lib' /etc/ld.so.conf >/dev/null; then echo '/usr/local/libgd/lib' >>/etc/ld.so.conf ;fi
    63. ldconfig

    64. #9).安装libxml
    65. tar -xzvf libxml2-2.6.31.tar.gz
    66. cd libxml2-2.6.31
    67. ./configure
    68. make && make install
阅读(1839) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~