仓酷云

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 1061|回复: 8
打印 上一主题 下一主题

[shell编程] 来一发Shell剧本一键装置LAMP情况

[复制链接]
蒙在股里 该用户已被删除
跳转到指定楼层
楼主
发表于 2015-1-14 20:18:53 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
欢迎大家来到仓酷云论坛!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)装置剧本
  1. #!/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:$3\033[39;49;0m"sleep"$2"echo""}#非root用户不克不及实行该剧本if["$UID"!=0];thenecho""INFO35"0""Mustberootrorunthisscript."exit1fi#USAGE函数界说剧本用法,可重复挪用,basename实在就是剧本名,
  2. 暗示换行。functionUSAGE(){INFO35"0.1""Pleaseseethescriptoftheusage:"basename=$(basename"$0")INFO36"0""$(echo-e"Usage:
  3. ./$basename(apache|mysql|php)install
  4. ./$basenameapache(start|stop|restart)
  5. ./$basenamemysql(start|stop|restart)
  6. ")"}#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
  7. phpinfo();
  8. ?>">$INSTALL_PATH/apache/htdocs/phpinfo.phpsed-is/^\AddTypeapplication/x-gzip.gz.tgz$/&
  9. \AddTypeapplication/x-httpd-php.php/$INSTALL_PATH/apache/conf/httpd.confsed-is/^#ServerNamewww.ckuyun.com:80$/&
  10. 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"-[0-9]"{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)剧本的用法
  1. #下载装置剧本和源码包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-15 21:04:29 来自手机 | 只看该作者

来一发Shell剧本一键装置LAMP情况

永中office2004增强版安装只需要默认安装即可使用并操作大多与win系统雷同,打印机的配置和管理,记录光盘等。
再现理想 该用户已被删除
板凳
发表于 2015-1-23 07:04:02 | 只看该作者
未来的学习之路将是以指数增加的方式增长的。从网管员来说,命令行实际上就是规则,它总是有效的,同时也是灵活的。
深爱那片海 该用户已被删除
地板
发表于 2015-1-31 18:27:20 | 只看该作者
笔者五分钟后就给出了解决方法: “首先备份原文件到其他目录,然后删掉/usr/local/unispim/unispimsp.ksc,编辑 /usr/local/unispim/unispimsp.ini,最后重启动计算机
只想知道 该用户已被删除
5#
发表于 2015-2-7 00:40:28 | 只看该作者
未来的学习之路将是以指数增加的方式增长的。从网管员来说,命令行实际上就是规则,它总是有效的,同时也是灵活的。
活着的死人 该用户已被删除
6#
发表于 2015-2-19 09:40:47 | 只看该作者
随着IT从业人员越来越多,理论上会有更多的人使用Linux,可以肯定,Linux在以后这多时间不会消失。
老尸 该用户已被删除
7#
发表于 2015-3-6 15:17:36 | 只看该作者
有疑问前,知识学习前,先用搜索。
山那边是海 该用户已被删除
8#
发表于 2015-3-13 04:09:39 | 只看该作者
众所周知,目前windows操作系统是主流,在以后相当长的时间内不会有太大的改变,其方便友好的图形界面吸引了众多的用户。
蒙在股里 该用户已被删除
9#
 楼主| 发表于 2015-3-13 04:09:39 | 只看该作者
其次,Linux简单易学,因为我们初学者只是学的基础部分,Linux的结构体系非常清晰,再加上老师循序渐进的教学以及耐心的讲解,使我们理解起来很快,短期内就基本掌握了操作和运行模式。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|仓酷云 鄂ICP备14007578号-2

GMT+8, 2024-12-23 04:27

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表