本脚本实例要求如下:
源码安装lamp环境,要求在字符终端下执行脚本(ls -l /usr/src显示不同)
所需tar包都已复制到/usr/src目录下
#!/bin/bash
rpm -q httpd &> /dev/null
if [ $? -eq 0 ];then
yum -y remove httpd &> /dev/null
fi
ls -l /usr/local/ | grep httpd &> /dev/null
if [ $? -ne 0 ];then
httpball=`ls /usr/src/httpd*.gz`
tar zxf $httpball -C /usr/src &> /dev/null
dir=`ls -l /usr/src | grep ^d | grep httpd | awk '{print $9}'`
cd /usr/src/$dir
./configure --prefix=/usr/local/httpd --enable-so --enable-rewrite --enable-charset-lite --enable-cgi && make && make install
ln -s /usr/local/httpd/bin/* /usr/local/bin
cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd
sed -i '1a #chkconfig: 35 85 15 \
#description: httpd server' /etc/init.d/httpd
chkconfig --add httpd
chkconfig httpd on
service httpd start
fi
rpm -q mysql-server &> /dev/null
if [ $? -eq 0 ];then
yum -y mysql-server mysql &> /dev/null
fi
ls -l /usr/local | grep mysql &> /dev/null
if [ $? -ne 0 ];then
grep mysql /etc/passwd &> /dev/null
if [ $? -ne 0 ]; then
useradd -M -u 49 -s /sbin/nologin mysql
fi
mysqlball=`ls /usr/src/mysql*.gz`
tar zxf $mysqlball -C /usr/src &> /dev/null
dir=`ls -l /usr/src | grep ^d | grep mysql | awk '{print $9}'`
cd /usr/src/$dir
./configure --prefix=/usr/local/mysql --with-charset=utf8 --with-collation=utf8_general_ci --with-extra-charset=gbk,gb2312 && make && make install