本文共 5335 字,大约阅读时间需要 17 分钟。
#一键安装lamp环境
#!/bin/bash#centos 6.5 lamp install scripts#apache 2.4.x版本,mysql5.5.x以上版本,php5.5.x以上版本. /etc/init.d/functionsfunction check_ok(){ if [ $? -eq 0 ]thencontinueelseecho "please check error"exit 1fi}function yum_update(){ echo "===update yum repos ,it will take serval mintinuse===" yum install wget -ypath=/etc/yum.repos.d[ -d "$path" ] || mkdir -p $path/bakmv $path/CentOS-* $path/bak/wget -O /etc/yum.repos.d/CentOS-Base.repo &>/dev/nullif [ -f "$path/epel.repo" ]thenrm -rf $path/eprl.repofi wget -O /etc/yum.repos.d/epel.repo &>/dev/nullyum clean all &>/dev/nullyum makecache &>/dev/nullcheck_okaction "yum repos update is ok" /bin/true}function yum_depend(){ yum install wget gcc gcc-c++ make re2c curl curl-devel libxml2 libxml2-devel libjpeg libjpeg-devel libpng libpng-devel libmcrypt libmcrypt-devel zlib zlib-devel openssl openssl-devel freetype freetype-devel gd gd-devel perl perl-devel ncurses ncurses-devel bison bison-devel libtool gettext gettext-devel cmake bzip2 bzip2-devel pcre pcre-devel -yaction "yum depend is all installed" /bin/true}function install_mysql(){ echo "mysql5.6.35 will be installing please wait mintinues "cd /usr/local/srcgroupadd mysqluseradd -s /sbin/nologin -g mysql -M mysqlmysqltar="mysql-5.6.35.tar.gz"namedir="mysql-5.6.35"[ -f "$mysqltar" ] && continue || wget [ -d "$namedir" ] && continue || tar -zxvf mysql-5.6.35.tar.gzcd $namedirinstalldir="/usr/local/mysql"[ -d "$installdir" ] && continue || mkdir -p $installdirpwdcmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DMYSQL_USER=mysql -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci check_okmake && make installcheck_ok}
function mysqlset(){ echo "PATH=/usr/local/mysql/bin:$PATH">>/etc/profilesource /etc/profilechown -R mysql:mysql /usr/local/mysql/check_okcd /usr/local/mysql/scripts/./mysql_install_db --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ --user=mysqlchenk_ok[ -f "/etc/my.cnf" ] && rm -f /etc/my.cnf cp -f /usr/local/src/mysql-5.6.35/support-files/my-default.cnf /etc/my.cnfsed -i '/^[mysqld]$/a\user = mysql \nbasedir = /usr/local/mysql\ndatadir = /usr/local/mysql/data\nsocket = /tmp/mysql.sock' /etc/my.cnf cp -f /usr/local/src/mysql-5.6.35/support-files/mysql.server /etc/init.d/mysqldchmod +x /etc/init.d/mysqldsed -i 's#^datadir=#datadir=/usr/local/mysql/data#' /etc/init.d/mysqldsed -i 's#^basedir=#basedir=/usr/local/mysql#' /etc/init.d/mysqldchkconfig --add mysqldchkconfig mysqld oncheck_ok }function install_apache(){ echo "apache2.4.25 will be installed,please wait minitunes"yum -y install expat-develcheck_okpath="/usr/local/src/"cd $pathapachetar="httpd-2.4.29.tar.gz"aprtar="apr-1.6.3.tar.gz"aprutiltar="apr-util-1.6.1.tar.gz"pcretar="pcre-8.41.tar.gz"[ ! -f "$apachetar" ] && wget || continuecheck_ok[ ! -f "$aprtar" ] && wget || continuecheck_ok[ ! -f "$aprutiltar" ] && wget || continuecheck_ok[ ! -f "$pcretar" ] && wget --no-check-certificate || continuecheck_oktar -zxvf httpd-2.4.29.tar.gztar -zxvf apr-1.6.3.tar.gztar -zxvf apr-util-1.6.1.tar.gztar -zxvf pcre-8.41.tar.gzcheck_okcd $path/apr-1.6.3./configure --prefix=/usr/local/apr make && make install check_okcd $path/apr-util-1.6.1./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/aprchenk_okmake && make install check_okcd $path/pcre-8.41./configure --prefix=/usr/local/pcrecheck_okmake && make installcheck_okcd $path/httpd-2.4.29./configure --prefix=/usr/local/apache2.4 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre --enable-so --enable-mods-shared=most --enable-rewritecheck_okmake && make installcheck_ok}
function apacheset(){ cp /usr/local/apache2.4/bin/apachectl /etc/init.d/httpdchmod +x /etc/init.d/httpdsed -i '2 i #chkconfig: 2345 10 90' /etc/init.d/httpdsed -i '3 i #description: Activates/Deactivates Apache Web Server' /etc/init.d/httpdcheck_okchkconfig httpd on}
function install_php(){ echo "php will be installed,please be wait"sleep 10yum -y install zlib-devel libpng-devel curl libmcrypt-devel freetype-devel libxml2-devel openssl-devel bzip2-devel libjpeg-devel curl-devel gdcheck_okcd /usr/local/srcphptar="php-5.6.30.tar.gz"[ ! -f "$phptar" ] && wget || continuetar -zxvf php-5.6.30.tar.gzmkdir -p /usr/local/php5cd /usr/local/src/php-5.6.30./configure --prefix=/usr/local/php5/ --with-apxs2=/usr/local/apache2.4/bin/apxs --with-config-file-path=/usr/local/php/etc/ --with-mysql=/usr/local/mysql/ --with-pdo-mysql=/usr/local/mysql/ --with-mysqli=/usr/local/mysql/bin/mysql_config --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-icon-dir --with-bz2 --with-openssl --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-sockets --enable-exif check_okmake && make install}
function main(){ yum_updateyum_dependinstall_mysql mysqlsetinstall_apacheinstall_phpapacheset }main转载于:https://blog.51cto.com/2179600/2095257