标签:shell lamo
首先是在linux的环境下,搭建顺序为mysql——>apache——>php
准备工作,再搭建之前先安装一些必要的文件包:
####定义一个函数myum,如果rpm包已经提示安装过,则不再尝试yum install 为了节省 ###时间 myum(){ if ! rpm -qa |grep -q "^$1";then yum install -y $1 check_ok else echo "$1 has been installed" fi } #先前需要经安装的一些包 for p in wget gcc perl perl-devel libaio libaio-devel pcre-devel zlib-devel do myum $p done yum install -y epel-release /安装epel源
首先搭建mysql
#!/bin/bash check_ok(){ if [ $? != 0 ];then echo "ERROR ,please check it now " exit 1 fi } ######################### #安装mysql ar=`arch` /获取系统的版本号,以便选择合适的mysql版本 install_mysql(){ echo "choose the version of mysql" select mysql_v in 5.1 5.6 do case $mysql_v in 5.1) cd /usr/local/src [ -f mysql-5.1.72-linux-$ar-glibc23.tar.gz ]||wget http://mirrors.sohu.com/mysql/MySQL-5.1/mysql-5.1.72-linux-$ar-glibc23.tar.gz check_ok tar zxf mysql-5.1.72-linux-$ar-glibc23.tar.gz check_ok mv mysql-5.1.72-linux-$ar-glibc23 /usr/local/mysql check_ok ##创建mysql账户 if ! grep -q "^mysql" /etc/passwd ;then /创建mysql账户前,先检查系统是否存在该账户,若存在则删除再创建! useradd mysql check_ok else userdel -r mysql useradd mysql -s /sbin/nologin check_ok fi ##### yum install -y compat-libstdc++-33 cd /usr/local/mysql if [ -d /data/mysql ];then rm -rf /data/mysql mkdir /data/mysql else mkdir /data/mysql fi chown -R mysql:mysql /data/mysql ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql check_ok /bin/cp support-files/my-large.cnf /etc/my.cnf sed -i ‘/^\[mysqld\]$/a\datadir = /data/mysql‘ /etc/my.cnf check_ok /bin/cp support-files/mysql.server /etc/init.d/mysqld sed -i ‘s#^datadir=#datadir=/data/mysql#‘ /etc/init.d/mysqld check_ok chmod 755 /etc/init.d/mysqld service mysqld start check_ok break ;; 5.6) cd /usr/local/src [ -f mysql-5.6.26-linux-glibc2.5-$ar.tar.gz ] || wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.26-linux-glibc2.5-$ar.tar.gz tar zxf mysql-5.6.26-linux-glibc2.5-$ar.tar.gz check_ok [ -d /usr/local/mysql ] && /bin/mv /usr/local/mysql /usr/local/mysql_bak mv mysql-5.6.26-linux-glibc2.5-$ar /usr/local/mysql if ! grep ‘^mysql:‘ /etc/passwd then useradd -M mysql -s /sbin/nologin fi yum install -y compat-libstdc++-33 [ -d /data/mysql ] && /bin/mv /data/mysql /data/mysql_bak mkdir -p /data/mysql chown -R mysql:mysql /data/mysql cd /usr/local/mysql ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql check_ok /bin/cp support-files/my-default.cnf /etc/my.cnf check_ok sed -i ‘/^\[mysqld\]$/a\datadir = /data/mysql‘ /etc/my.cnf /bin/cp support-files/mysql.server /etc/init.d/mysqld sed -i ‘s#^datadir=#datadir=/data/mysql#‘ /etc/init.d/mysqld chmod 755 /etc/init.d/mysqld chkconfig --add mysqld chkconfig mysqld on service mysqld start check_ok break ;; *) echo "only 1(5.1) or 2(5.6)" exit 1 ;; esac done } install_mysql
然后搭建apache
1 #!/bin/bash 2 check_ok(){ 3 if [ $? != 0 ];then 4 echo "ERROR ,please check it now " 5 exit 1 6 fi 7 } 8 ######################### 9 #安装apache 10 install_httpd(){ 11 #yum install -y zlib-devel 12 #yum install -y pcre pcre-devel apr apr-devel 13 check_ok 14 cd /usr/local/src 15 [ -f httpd-2.2.31.tar.gz ] || wget http://mirrors.cnnic.cn/apache/httpd/httpd-2.2.31.ta r.gz 16 17 check_ok 18 tar zxvf httpd-2.2.31.tar.gz 19 check_ok 20 cd httpd-2.2.31 21 ./configure 22 --prefix=/usr/local/apache2 23 --with-included-apr 24 --enable-so 25 --enable-deflate=shared 26 --enable-expires=shared 27 --enable-rewrite=shared 28 --with-pcre 29 check_ok 30 make 31 check_ok 32 make install 33 check_ok 34 } 35 install_httpd
搭建php
1 #!/bin/bash 2 check_ok(){ 3 if [ $? != 0 ];then 4 echo "please check it now" 5 exit 1 6 fi 7 } 8 ############# 9 #安装php 10 install_php(){ 11 echo -e "Install php. \nPlease choose the version of php" 12 select php_v in 5.4 5.6 13 do 14 case $php_v in 15 5.4) 16 cd /usr/local/src 17 [ -f php-5.4.45.tar.bz2 ] || wget ‘http://cn2.php.net/get/php-5.4.45.tar.bz2/from/this/mirror‘ -O php-5.4.45.tar.bz2 18 check_ok 19 tar jxvf php-5.4.45.tar.bz2 20 check_ok 21 cd php-5.4.45 22 for p in openssl-devel bzip2-devel 23 libxml2-devel curl-devel libpng-devel 24 libjpeg-devel freetype-devel libmcrypt-devel 25 libtool-ltdl-devel perl-devel 26 do 27 yum install -y $p 28 done 29 check_ok 30 ./configure 31 --prefix=/usr/local/php 32 --with-apxs2=/usr/local/apache2/bin/apxs 33 --with-config-file-path=/usr/local/php/etc 34 --with-mysql=/usr/local/mysql 35 --with-libxml-dir 36 --with-gd 37 --with-jpeg-dir 38 --with-png-dir 39 --with-freetype-dir 40 --with-iconv-dir 41 --with-zlib-dir 42 --with-bz2 43 --with-openssl 44 --with-mcrypt 45 --enable-soap 46 --enable-gd-native-ttf 47 --enable-mbstring 48 --enable-sockets 49 --enable-exif 50 --disable-ipv6 51 check_ok 52 make && make install 53 check_ok 54 if [ -f /usr/local/php/etc/php.ini ];then 55 rm -f /usr/local/php/etc/php.ini 56 cp php.ini-production /usr/local/php/etc/php.ini 57 else 58 cp php.ini-production /usr/local/php/etc/php.ini 59 60 fi 61 break 62 ;; 63 64 5.6) 65 cd /usr/local/src 66 [ -f php-5.6.6.tar.gz ] || wget http://mirrors.sohu.com/php/php-5.6.6.tar.gz 67 check_ok 68 tar zxvf php-5.6.6.tar.gz 69 check_ok 70 cd php-5.6.6 71 for p in openssl-devel bzip2-devel 72 libxml2-devel curl-devel libpng-devel 73 libjpeg-devel freetype-devel libmcrypt-devel 74 libtool-ltdl-devel perl-devel 75 do 76 yum install -y $p 77 done 78 check_ok 79 ./configure 80 --prefix=/usr/local/php 81 --with-apxs2=/usr/local/apache2/bin/apxs 82 --with-config-file-path=/usr/local/php/etc 83 --with-mysql=/usr/local/mysql 84 --with-libxml-dir 85 --with-gd 86 --with-jpeg-dir 87 --with-png-dir 88 --with-freetype-dir 89 --with-iconv-dir 90 --with-zlib-dir 91 --with-bz2 92 --with-openssl 93 --with-mcrypt 94 --enable-soap 95 --enable-gd-native-ttf 96 --enable-mbstring 97 --enable-sockets 98 --enable-exif 99 --disable-ipv6 100 check_ok 101 make && make install 102 check_ok 103 if [ -f /usr/local/php/etc/php.ini ];then 104 rm -f /usr/local/php/etc/php.ini 105 cp php.ini-production /usr/local/php/etc/php.ini 106 else 107 cp php.ini-production /usr/local/php/etc/php.ini 108 109 fi 110 break 111 ;; 112 113 *) 114 echo "only 1(5.4) or 2(5.6)" 115 ;; 116 esac 117 done 118 } 119 install_php
把php和apache结合在一起
1 #!/bin/bash 2 check_ok(){ 3 if [ $? != 0 ];then 4 echo "ERROR ,please check it now " 5 exit 1 6 fi 7 } 8 ############ 9 join_apa_php() { 10 sed -i ‘/AddType .*.gz .tgz$/a\AddType application\/x-httpd-php .php‘ /usr/local/apache2/conf/htt pd.conf 11 check_ok 12 sed -i ‘s/#ServerName www.example.com:80/ServerName localhost:80/‘ /usr/local/apache2/conf/httpd. conf 13 check_ok 14 sed -i ‘s/DirectoryIndex index.html/DirectoryIndex index.php index.html index.htm/‘ /usr/local/ap ache2/conf/httpd.conf 15 check_ok 16 cat > /usr/local/apache2/htdocs/index.php <<EOF 17 <?php 18 phpinfo(); 19 ?> 20 EOF 21 22 if /usr/local/php/bin/php -i |grep -iq ‘date.timezone => no value‘ 23 then 24 sed -i ‘/;date.timezone =$/a\date.timezone = "Asia\/Chongqing"‘ /usr/local/php/etc/php.ini 25 fi 26 } 27 join_apa_php
也可以把以上的四个shell脚本混合在一起,组成一个脚本,但是要注意细节问题!
本文出自 “自定义” 博客,请务必保留此出处http://zidingyi.blog.51cto.com/10735263/1725418
标签:shell lamo
原文地址:http://zidingyi.blog.51cto.com/10735263/1725418