25 Jun

一个自动安装编译LAMP环境的脚本

分类:电脑技术 » linux shell   出处:formating         | |
上午群里formating兄弟发来一个脚本,稍微改动了一下,放在这里跟大家一起分享,也算是借花献佛了。
下载文件 (已下载 37 次)

setup
#!/bin/bash
#
rpm -e gnome-user-share-0.10-6.el5.i386
rpm -e httpd-2.2.3-6.el5.centos.1
tar -zxvf soft.tar.gz
cd soft
chmod +x setup.sh
./setup.sh



setup.sh
#!/bin/bash
#
#apache2.2.9+mysql5+php5.2.6

mkdir /web
groupadd mysql
useradd -g mysql mysql
tar -zxvf httpd-2.2.9.tar.gz
cd httpd-2.2.9
./configure --prefix=/web/apache --with-ssl --enable-ssl --enable-so --enable-rewrite --disable-cgid --disable-cgi
make
make install
cp /web/apache/bin/apachectl /etc/init.d/httpd
chmod 755 /etc/init.d/httpd
chkconfig --add httpd
chkconfig httpd on
####apache install over######
cd ..
tar -zxvf mysql-5.0.51b.tar.gz
cd mysql-5.0.51b
./configure --prefix=/web/mysql --with-comment=Source --with-server-suffix=-enterprise-gpl --with-mysql-user=mysql --without-debug --with-socket-path=/web/mysql/var/mysql.sock --with-big-tables --with-charset=gbk --with-collation=gbk_chinese_ci --with-extra-charsets=all --with-pthread --enable-static --enable-thread-safe-client --with-client-ldflags=-all-static --with-mysqld-ldflags=-all-static --enable-assembler --without-innodb --without-ndb-debug --without-isam --enable-local-infile --with-readline --with-raid
make
make install
cd /web/mysql
chown -R mysql .
chgrp -R mysql .
bin/mysql_install_db --user=mysql
chown -R root .
chown -R mysql var
cp share/mysql/my-medium.cnf /etc/my.cnf
cp share/mysql/mysql.server /etc/init.d/mysqld
chmod 755 /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig --level 3 mysqld on
####MYSQL install over modify password for root#####
cd /root/soft
tar -zxvf gd-2.0.33.tar.gz
cd gd-2.0.33
./configure --prefix=/web/gd
make
make install
###GD install over###
cd ..
tar -zxvf php-5.2.6.tar.gz
cd php-5.2.6
./configure --prefix=/web/php --with-apxs2=/web/apache/bin/apxs --with-zlib-dir --with-bz2 --with-libxml-dir --with-gd=/web/gd --enable-gd-native-ttf --enable-gd-jis-conv --with-freetype-dir --with-jpeg-dir --with-png-dir --with-ttf --enable-mbstring --with-mysql=/web/mysql --with-config-file-path=/etc --with-iconv --disable-ipv6 --enable-static --enable-zend-multibyte --enable-inline-optimization --enable-zend-multibyte --enable-sockets --enable-soap --with-gettext --enable-ftp
make
make install
sed 's/^short_open_tag = Off$/short_open_tag = On/g' php.ini-recommended > /etc/php.ini
echo 'export PATH=$PATH:/web/mysql/bin' >> /etc/profile
source /etc/profile

################ add by thatday ################
echo -n "DO U WANT MODIFY THE WEB PATH  ?(Yes|No) :"
read ANSWER
case $ANSWER in
y*|Y*)
  echo -e "Now, please modify the webroot of apache..."
  echo -n "Type path of webroot:"
  read WEBPATH
  mkdir -p $WEBPATH
  #fuckpath = `echo $WEBPATH | tr '/' '&' | sed 's/&/\\\//g'`
  fuckpath = `echo $WEBPATH | sed 's/\//\\\//g'`
  sed -e 's/DocumentRoot \"\/web\/apache\/htdocs\"/DocumentRoot \"$fuckpath\"/g' /web/apache/conf/httpd.conf > /tmp/tmp_httpd.conf
  mv -f /tmp/tmp_httpd.conf /web/apache/conf/httpd.conf
  ;;
*)
  echo "Ok, nothing has modified, let's goto next step! "
  ;;
esac

sed 's/DirectoryIndex index.html/DirectoryIndex index.php default.php index.html/' /web/apache/conf/httpd.conf > /tmp/step1.txt
sed 's/\(AddType application\/x-gzip .gz .tgz\)$/\1\n    AddType application\/x-httpd-php .php/' /tmp/step1.txt > /tmp/step2.txt
cp /tmp/step2.txt /web/apache/conf/httpd.conf
rm -f /tmp/step1.txt /tmp/step2.txt
####php install over#####

cat<<END_OF_FILEi>$WEBPATH/index.php
<?php
  phpinfo();
?>
END_OF_FILE

service httpd start

HTTPD_PROCESS_COUNT="`netstat -tnl | grep :80  | wc -l`"

if [ $HTTPD_PROCESS_COUNT -gt 0 ]
then
   echo httpd is running
else
   echo httpd is NOT running
fi

service mysqld start

MYSQL_PROCESS_COUNT="` ps -ef | grep /web/mysql/libexec/mysqld | grep -v grep | wc -l `"
if [ $MYSQL_PROCESS_COUNT -gt 0 ]
then
service mysqld start

MYSQL_PROCESS_COUNT="` ps -ef | grep /web/mysql/libexec/mysqld | grep -v grep | wc -l `"
if [ $MYSQL_PROCESS_COUNT -gt 0 ]
then
   echo mysqld is running
  
   ################ add by thatday ################
   echo -e "Now, please modify the root password of mysql..."
   echo -n "Type root password of mysql:"
   read PASSWORD
   mysqladmin -u root password '$PASSWORD'
   echo -e "OK, your root password of mysql is: $PASSWORD"
  
else
   echo mysqld is NOT running
fi



脚本比较简单,有什么问题请大家说说。

sed挺有意思,想起CU网中人兄弟的签名,更是妙不可言:

echo '十人|日一|十十o' | sed 's/.../&\n/g'

还有一道题,把hellohellohello变成每行一个hello:

echo 'hellohellohello' |sed 's/hello/hello@/g'|tr '@' '\n'

简化点直接用sed

echo 'hellohellohello' | sed 's/...../&\n/g'
334 次阅读
0 条评论
0 条引用
不指定 作者:thatday   时间:12:10   
发表评论
  昵称 [注册]
  密码 (游客无需密码)
  网址
  电邮
高级编辑