活着的死人 发表于 2015-1-14 20:17:32

带来一篇Cenots下面用Shell剧本一键装置LAMP情况

欢迎大家来到仓酷云论坛!LAMP指的Linux(操纵体系)、Apache(HTTP办事器),MySQL(数据库软件)和PHP构建的web办事器。该网站架构是今朝国际盛行和通用的Web架构,LAMP跨平台、高功能等上风,是良多企业和公司搭建WEB办事的首选平台。
1)体系情况先容
Centos5.864位
Apache:httpd-2.4.4.tar.gz
PHP:php-5.4.17.tar.gz
Mysql:mysql-5.6.12.tar.gz
2)装置剧本

#!/bin/bashPATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/binexportPATH#INFO函数界说输入字体色彩,echo-e暗示坚持字符串的特别寄义,$1暗示字体色彩编号,$2暗示守候步伐实行工夫,$3暗示echo输入内容。functionINFO(){echo-e"e[$1;49;1m:$333;thenecho""INFO35"0""Mustberootrorunthisscript."exit1fi#USAGE函数界说剧本用法,可重复挪用,basename实在就是剧本名,
暗示换行。functionUSAGE(){INFO35"0.1""Pleaseseethescriptoftheusage:"basename=$(basename"$0")INFO36"0""$(echo-e"Usage:

./$basename(apache|mysql|php)install
./$basenameapache(start|stop|restart)
./$basenamemysql(start|stop|restart)
")"}#YUM_INSTALL函数装置依附包,可重复挪用,$@暗示一切参数都分离被双引号引住"$1","$2",而$*暗示一切这些参数都被双引号引住"$1$2"functionYUM_INSTALL(){forain$@;doINFO321"Installdependonthe[$a]"yum-yinstall$a||exit1if[$a="libXpm-devel"];thenln-s/usr/lib/x86_64-linux-gnu/libXpm.so/usr/lib/libXpm.so#elif[$a="libsasl2-dev"];then#cp/usr/lib/x86_64-linux-gnu/libldap*/usr/lib/fidone}#INSTALL函数界说装置步伐,可一重复挪用,装置apache步伐的时分要先装置3个依附包,在装置mysql的时分要用cmake编译。$1暗示要装置的步伐,$2暗示yum装置对应的依附包,$3暗示步伐解压后的目次,$4暗示步伐源码包。functionINSTALL(){YUM_INSTALL"$2"&&cd$SOURCE_PATH[-d$3]&&rm-r$3;INFO314"Unpackthe$4installationpackage......"tarzxvf$4;cd$3;pwd;INFO324"Configurethe$1......"if[$1=apache];thencp-rf../apr-1.4.8srclib/aprcp-rf../apr-util-1.5.2srclib/apr-util./configure$5||exit1elif[$1=mysql];thencmake$5||exit1elif[$1=openssl];then./config$5||exit1elif[$1=libpng];thencpscripts/makefile.linuxmakefileelif[$1=jpegsrc.v6b.tar.gz];thencp/usr/share/libtool/config.guess./cp/usr/share/libtool/config.sub././configure$5||exit1mkdir-p/usr/local/env/jpeg/binmkdir-p/usr/local/env/jpeg/libmkdir-p/usr/local/env/jpeg/includemkdir-p/usr/local/env/jpeg/man/man1else./configure$5||exit1fiINFO363"Compile$1......"make||exit1&&INFO344"Install$1......";makeinstall&&INFO334"$1installationissuccessful......"if[$1=mysql];thenecho$INSTALL_PATH/mysql/lib/mysql>>/etc/ld.so.conf/sbin/ldconfig&&INFO334"Add$1libraryfiletold.so.conf......"fiif[$1=libiconv];thenecho"/usr/local/env/libiconv/lib">>/etc/ld.so.conf/sbin/ldconfig&&INFO334"Add$1libraryfiletold.so.conf......"fiif[$1=libxml2];thenecho"/usr/local/env/libxml2/lib">>/etc/ld.so.conf/sbin/ldconfig&&INFO334"Add$1libraryfiletold.so.conf......"fiif[$1=libmcrypt];thenecho"/usr/local/env/libmcrypt/lib">>/etc/ld.so.conf/sbin/ldconfig&&INFO334"Add$1libraryfiletold.so.conf......"fiif[$1=mhash];thenecho"/usr/local/lib">>/etc/ld.so.confecho"/usr/local/lib64">>/etc/ld.so.conf/sbin/ldconfig&&INFO334"Add$1libraryfiletold.so.conf......"fiif[$1=gettext];thenecho"/usr/local/env/gettext/lib">>/etc/ld.so.conf/sbin/ldconfig&&INFO334"Add$1libraryfiletold.so.conf......"fiif[$1=gd];thensed-i27avoid(*data);/usr/local/env/gd/include/gd_io.hecho"/usr/local/env/gd/lib">>/etc/ld.so.conf/sbin/ldconfig&&INFO334"Add$1libraryfiletold.so.conf......"fiif[$1=freetype];thenecho"/usr/local/env/freetype/lib">>/etc/ld.so.conf/sbin/ldconfig&&INFO334"Add$1libraryfiletold.so.conf......"fiif[$1=jpegsrc.v6b.tar.gz];thenecho"/usr/local/env/jpeg/lib">>/etc/ld.so.conf/sbin/ldconfig&&INFO334"Addjpeglibraryfiletold.so.conf......"fi}#SERVICE函数界说步伐启动,封闭,重启。functionSERVICE(){if[$1=apache-a$2=start];then$INSTALL_PATH/$1/bin/apachectl-kstart&&INFO33"2.5""Apachestartupsuccess......"exitelif[$1=apache-a$2=stop];then$INSTALL_PATH/$1/bin/apachectl-kstop&&INFO31"2.5""Apachehasstopped......"exitelif[$1=apache-a$2=restart];then$INSTALL_PATH/$1/bin/apachectl-kstop;sleep2INFO31"2.5""Apachehasstopped......"$INSTALL_PATH/$1/bin/apachectl-kstart&&INFO34"2.5""Apachehasrestarted......"exitelif[$1=mysql-a$2=start];then/bin/bash$INSTALL_PATH/$1/bin/mysqld_safe--defaults-file=$INSTALL_PATH/$1/my.cnf2>&1>/dev/null&INFO33"2.5""Mysqlstartupsuccess......"echo-e"$(netstat-ntpl|grep"/:::3306")"exitelif[$1=mysql-a$2=stop];thenkill$(netstat-ntpl|awk/:::3306/{print$NF}|awk-F/{print$1})&&INFO31"2.5""Mysqlhasstopped......"exitelif[$1=mysql-a$2=restart];thenkill$(netstat-ntpl|awk/:::3306/{print$NF}|awk-F/{print$1})&&INFO31"3""Mysqlhasstopped......"/bin/bash$INSTALL_PATH/$1/bin/mysqld_safe--defaults-file=$INSTALL_PATH/$1/my.cnf2>&1>/dev/null&INFO34"2.5""Mysqlhasrestarted......"exitfi}#CONFIG_MYSQL函数用来界说mysql的设置。functionCONFIG_MYSQL(){INFO323"Configurethemysql......"groupsmysql||groupaddmysql&&idmysql||useradd-gmysqlmysqlcd$INSTALL_PATH/mysql;pwd./scripts/mysql_install_db--user=mysql--basedir=$INSTALL_PATH/mysql/--datadir=$INSTALL_PATH/mysql/data/--defaults-file=$INSTALL_PATH/mysql/my.cnfecho"";sleep3cp$(dirname$SOURCE_PATH)/conf/my.cnf./INFO352"Mysqlconfigurationiscomplete......"}#CONFIG_HTTPD函数用来设置apache。functionCONFIG_HTTPD(){INFO323"Configuretheapache......"echo-e"<?php
phpinfo();
?>">$INSTALL_PATH/apache/htdocs/phpinfo.phpsed-is/^\AddTypeapplication/x-gzip.gz.tgz$/&
\AddTypeapplication/x-httpd-php.php/$INSTALL_PATH/apache/conf/httpd.confsed-is/^#ServerNamewww.ckuyun.com:80$/&
ServerName127.0.0.1:80/$INSTALL_PATH/apache/conf/httpd.confINFO352"Apacheconfigurationiscomplete......"}#CONFIG_PHP函数用来设置php。functionCONFIG_PHP(){INFO323"Configurethephp......"cp$SOURCE_PATH/$1/php.ini-development$INSTALL_PATH/php5/etc/php.iniINFO352"Phpconfigurationiscomplete......"}#INSTALL_BRANCH函数界说步伐装置,${TAR_NAME[@]}是shell剧本中数组写法,即取全体元素,即TAR_NAME内里的一切包,SERVER_NAME暗示包的称号,COMPILE_DIR暗示包名+版本后,即解压后的目次名。functionINSTALL_BRANCH(){foriin${TAR_NAME[@]};doSERVER_NAME=$(echo$i|awk-F"-"{print$1})COMPILE_DIR=$(echo$i|awk-F".tar.gz"{print$1})if[$1=$SERVER_NAME-a$1=apr];thenINSTALLapr"""$COMPILE_DIR""$i""--prefix=/usr/local/env/apr"elif[$1=$SERVER_NAME-a$1=apr-util];thenINSTALLapr-util"""$COMPILE_DIR""$i""--prefix=/usr/local/env/apr-util--with-apr=/usr/local/env/apr"elif[$1=$SERVER_NAME-a$1=pcre];thenINSTALLpcre"""$COMPILE_DIR""$i""--prefix=/usr/local/env/pcre"elif[$1=$SERVER_NAME-a$1=httpd];thenINSTALLapache"$HTTP_YUM""$COMPILE_DIR""$i""$HTTP_PARAMETERS"CONFIG_HTTPDelif[$1=$SERVER_NAME-a$1=mysql];thenINSTALLmysql"$MYSQL_YUM""$COMPILE_DIR""$i""$MYSQL_PARAMETERS"CONFIG_MYSQLelif[$1=$SERVER_NAME-a$1=libiconv];thenINSTALLlibiconv"""$COMPILE_DIR""$i""--prefix=/usr/local/env/libiconv"elif[$1=$SERVER_NAME-a$1=libxml2];thenINSTALLlibxml2"""$COMPILE_DIR""$i""--prefix=/usr/local/env/libxml2--with-iconv=/usr/local/env/libiconv"elif[$1=$SERVER_NAME-a$1=curl];thenINSTALLcurl"""$COMPILE_DIR""$i""--prefix=/usr/local/env/curl--enable-utf8"elif[$1=$SERVER_NAME-a$1=libmcrypt];thenINSTALLlibmcrypt"""$COMPILE_DIR""$i""--prefix=/usr/local/env/libmcrypt"elif[$1=$SERVER_NAME-a$1=mhash];thenINSTALLmhash"""$COMPILE_DIR""$i"""elif[$1=$SERVER_NAME-a$1=mcrypt];thenINSTALLmcrypt"""$COMPILE_DIR""$i""--prefix=/usr/local/env/mcrypt--with-libmcrypt-prefix=/usr/local/env/libmcrypt--with-libiconv-prefix=/usr/local/env/libiconv"elif[$1=$SERVER_NAME-a$1=gettext];thenINSTALLgettext"""$COMPILE_DIR""$i""--prefix=/usr/local/env/gettext--with-libiconv-prefix=/usr/local/env/libiconv--with-libxml2-prefix=/usr/local/env/libxml2"elif[$1=$SERVER_NAME-a$1=freetype];thenINSTALLfreetype"""$COMPILE_DIR""$i""--prefix=/usr/local/env/freetype"elif[$1=$SERVER_NAME-a$1=jpegsrc.v6b.tar.gz];thenCOMPILE_DIR="jpeg-6b"INSTALLjpegsrc.v6b.tar.gz"""$COMPILE_DIR""$i""--prefix=/usr/local/env/jpeg--enable-shared--enable-static"elif[$1=$SERVER_NAME-a$1=libpng];thenINSTALLlibpng"""$COMPILE_DIR""$i"""elif[$1=$SERVER_NAME-a$1=gd];thenINSTALLgd"""$COMPILE_DIR""$i""--prefix=/usr/local/env/gd--with-png=/usr--with-freetype=/usr/local/env/freetype--with-jpeg=/usr/local/env/jpeg--with-fontconfig=/usr--with-xpm=/usr"elif[$1=$SERVER_NAME-a$1=openssl];thenINSTALLopenssl"""$COMPILE_DIR""$i""-fPIC--prefix=/usr/local/env/opensslshared"elif[$1=$SERVER_NAME-a$1=php];thenINSTALLphp5"$PHP5_YUM""$COMPILE_DIR""$i""$PHP5_PARAMETERS"CONFIG_PHP"$COMPILE_DIR"breakelsecontinuefidone}#MOD_CASE函数用KASE界说选择装置步伐。functionMOD_CASE(){if[[$1=~apache|mysql|php]]&&[[$2=~install|start|stop|restart]];thenINFO32"1.5""Inputthecorrect,accordingtotheoptiontoperformrelatedoperations......"echo""if[$2=install];thencase"$1$2"in"apacheinstall")INFO35"2.5""Startto$1the$2......"INSTALL_BRANCHaprINSTALL_BRANCHapr-utilINSTALL_BRANCHpcreINSTALL_BRANCHhttpd;;"mysqlinstall")INFO35"2.5""Startto$1the$2......"INSTALL_BRANCHmysql;;"phpinstall")INFO35"2.5""Startto$1the$2......"exportLD_LIBRARY_PATH=/lib/:/usr/lib/:/usr/local/lib:/usr/local/lamp/mysql/libINSTALL_BRANCHlibiconvINSTALL_BRANCHlibxml2INSTALL_BRANCHcurlINSTALL_BRANCHlibmcryptINSTALL_BRANCHmhashINSTALL_BRANCHmcryptINSTALL_BRANCHgettextINSTALL_BRANCHfreetypeINSTALL_BRANCHjpegsrc.v6b.tar.gzINSTALL_BRANCHlibpngINSTALL_BRANCHgdINSTALL_BRANCHopenssl#INSTALL_BRANCHhttpd&&INSTALL_BRANCHmysql&&INSTALL_BRANCHphpINSTALL_BRANCHphp;;esacelseSERVICE$1$2fielseINFO311"Inputerror,pleasetryagain!"INPUTfi}#LAMP步伐装置的目次INSTALL_PATH="/usr/local/lamp"#源码包寄存目次SOURCE_PATH="$(cd$(dirname$0);pwd)/install_tar"#源码包列表TAR_NAME=(httpd-2.4.4.tar.gzmysql-5.6.12.tar.gzphp-5.4.17.tar.gzapr-1.4.8.tar.gzapr-util-1.5.2.tar.gzpcre-8.10.tar.gzfreetype-2.4.0.tar.gzjpegsrc.v6b.tar.gzlibxml2-2.7.2.tar.gzmhash-0.9.9.9.tar.gzmcrypt-2.6.8.tar.gzgd-2.0.35.tar.gzlibiconv-1.14.tar.gzgettext-0.18.tar.gzlibmcrypt-2.5.8.tar.gzopenssl-0.9.8p.tar.gzcurl-7.32.0.tar.gzlibpng-1.2.33.tar.gz)#Apache,Mysql,PHPyum装置依附包HTTP_YUM="build-essentiallibapr1libapr1-devlibaprutil1libaprutil1-devgettextgettext-devel"MYSQL_YUM="cmakelibncurses5libncurses5-devbison"PHP5_YUM="libxml2libxml2-developenssllibjpeg-develbzip2libXpm-devellibmcrypt-devel"#Apache编译参数HTTP_PARAMETERS="--prefix=$INSTALL_PATH/apache--enable-module=so--enable-module=rewrite--enable-shard=rewrite--enable-shared=max--with-apr=/usr/local/env/apr--with-apr-util=/usr/local/env/apr-util--with-pcre=/usr/local/env/pcre--with-included-apr"#mysql编译参数MYSQL_PARAMETERS="-DCMAKE_INSTALL_PREFIX=$INSTALL_PATH/mysql-DYSQL_TCP_PORT=3306-DMYSQL_DATADIR=$INSTALL_PATH/mysql/data-DMYSQL_UNIX_ADDR=$INSTALL_PAHT/mysql/mysql.sock-DWITH_MYISAM_STORAGE_ENGINE=1-DWITH_INNOBASE_STORAGE_ENGINE=1-DDEFAULT_CHARSET=utf8-DDEFAULT_COLLATION=utf8_general_ci-DEXTRA_CHARSETS=all-DWITH_DEBUG=0"#PHP编译参数PHP5_PARAMETERS="--prefix=$INSTALL_PATH/php5--with-config-file-path=$INSTALL_PATH/php5/etc--with-mysql=$INSTALL_PATH/mysql--with-apxs2=$INSTALL_PATH/apache/bin/apxs--with-mysqli=$INSTALL_PATH/mysql/bin/mysql_config--with-iconv=/usr/local/env/libiconv--with-jpeg-dir=/usr/local/env/jpeg--with-png-dir=/usr--with-libxml-dir=/usr/local/env/libxml2--with-pdo-mysql--with-zlib--with-curl=/usr/local/env/curl--with-curlwrappers--with-mcrypt=/usr/local/env/libmcrypt--with-gd=/usr/local/env/gd--with-openssl=/usr/local/env/openssl--with-mhash=/usr--with-xmlrpc--with-xpm-dir--with-freetype-dir=/usr/local/env/freetype--with-zlib-dir--with-ldap--with-ldap-sasl--with-pcre-regex--with-gettext=/usr/local/env/gettext--with-ncurses--enable-shared--enable-xml--enable-safe-mode--enable-track-vars--enable-magic-quotes--enable-bcmath--enable-sysvsem--enable-sysshm--enable-inline-optimization--enable-mbregex--enable-mbstring--enable-gd-native-ttf--enable-pcntl--enable-sockets--enable-zip--enable-soap--enable-discard-path--enable-force-cgi-redirect--enable-pdo--enable-calendar--enable-exif--enable-zend-multibyte"#--disable-rpath#剧本挪用匡助步伐if[$#=2]thenINFO33"1.5""pleasewait......"echo""MOD_CASE"$1""$2"elseUSAGEexit1fi

3)剧本的用法

#下载装置剧本和源码包wgethttps://sourceforge.net/projects/opensourcefile/files/Install_Centos_LAMP_v.0.1.zip/download--no-check-certificateunzipInstall_Centos_LAMP_v.0.1.zipchmod+xInstall_Centos_LAMP_v.0.1.sh#检察剧本的用法,可经由过程该剧本装置apache,mysql,php,启动,封闭和重启apache和mysql。./Install_Centos_LAMP_v.0.1.sh:Pleaseseethescriptoftheusage::Usage:./Install_Centos_LAMP_v.0.1.sh(apache|mysql|php)install./Install_Centos_LAMP_v.0.1.shapache(start|stop|restart)./Install_Centos_LAMP_v.0.1.shmysql(start|stop|restart)

本剧本使用了Shell编程内里的函数,数组,流程把持,变量,字体的加亮等功效,但愿对进修WEB和Shell编程的同砚有所匡助,最初十分感激我的同砚宝宝的撑持。
本文出自“俭朴的追梦者”博客,请务必保存此出处http://sfzhang88.blog.51cto.com/4995876/1281640
如果您觉得本篇CentOSLinux教程讲得好,请记得点击右边漂浮的分享程序,把好文章分享给你的小伙伴们!

精灵巫婆 发表于 2015-1-24 15:39:45

Linux只是个内核!这点很重要,你必须理解这一点。只有一个内核是不能构成一个操作系统的。

蒙在股里 发表于 2015-2-2 11:00:30

熟读Linux系统有关知识,如系统目录树,有关内容可购书阅读或搜索论坛。

金色的骷髅 发表于 2015-2-7 19:29:01

掌握硬件配置,如显卡,声卡,网卡等,硬件只要不是太老或太新一般都能被支持,作为一名Linux系统管理员建议多阅读有关硬件配置文章,对各种不支持或支持不太好的硬件有深刻的了解。

分手快乐 发表于 2015-2-23 13:46:41

编程学习及开发,Linux是免费,开源的操作系统,并且可开发工具相当多,如果您支持自由软件,一定要同广大热爱自由软件人士一同为其不懈努力。

灵魂腐蚀 发表于 2015-3-7 11:10:31

以前觉得Linux就跟dos一样,全是用命令窗口,相对于窗口界面来说多麻烦呀。

谁可相欹 发表于 2015-3-15 06:46:30

下面看看一个让人无法回答的问题:“救命各位高手,向你们请教一些问题:如何在Linux下配制HTTP、FTP、Samba、DNS、DHCP、Sendmail服务器,谢谢”这样的问题。

不帅 发表于 2015-3-21 22:48:29

熟悉系统的基本操作,Linux的图形界面直观,操作简便,多加上机练习就可熟悉操作,在Linux下学习办公软件等常用软件。
页: [1]
查看完整版本: 带来一篇Cenots下面用Shell剧本一键装置LAMP情况