centos shell编程5  LANMP一键安装脚本 lamp  sed  lnmp  变量和字符串比较不能用-eq  cat > /usr/local/apache2/htdocs/index.php <<EOF重定向 shell的变量和函数命名不能有横杠  平台可以用arch命令,获取是i686还是x86_64  curl 下载   第三十九节课

上半节课

lamp
sed

下半节课
lnmp
变量和字符串比较不能用-eq
cat > /usr/local/apache2/htdocs/index.php <<EOF重定向
shell的变量和函数命名不能有横杠
平台可以用arch命令,获取是i686还是x86_64
curl 下载

centos6 ,不区分32位,64位, 要求机器可以上外网。 支持lamp 和 lnmp, mysql支持5.1和5.6两个版本,php支持5.3和5.6两个版本,apache2.2,nginx1.8.

#!/bin/bash
echo "It will install lamp or lnmp."
sleep
##check last command is OK or not.
check_ok() {
if [ $? != ]
then
echo "Error, Check the error log."
exit
fi
}
##get the archive of the system,i686 or x86_64.
ar=`arch`
##close seliux
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
selinux_s=`getenforce`
if [ $selinux_s == "Enforcing" -o $selinux_s == "enforcing" ]
then
setenforce
fi
##close iptables
iptables-save > /etc/sysconfig/iptables_`date +%s`
iptables -F
service iptables save ##if the packge installed ,then omit.
myum() {
if ! rpm -qa|grep -q "^$1"
then
yum install -y $
check_ok
else
echo $ already installed.
fi
} ## install some packges.
for p in gcc wget perl perl-devel libaio libaio-devel pcre-devel zlib-devel
do
myum $p
done ##install epel.
if rpm -qa epel-release >/dev/null
then
rpm -e epel-release
fi
if ls /etc/yum.repos.d/epel-.repo* >/dev/null >&
then
rm -f /etc/yum.repos.d/epel-.repo*
fi
wget -P /etc/yum.repos.d/ http://mirrors.aliyun.com/repo/epel-6.repo ##function of installing mysqld.
install_mysqld() {
echo "Chose 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.-linux-$ar-glibc23.tar.gz ] || wget http://mirrors.sohu.com/mysql/MySQL-5.1/mysql-5.1.72-linux-$ar-glibc23.tar.gz
tar zxf mysql-5.1.-linux-$ar-glibc23.tar.gz
check_ok
[ -d /usr/local/mysql ] && /bin/mv /usr/local/mysql /usr/local/mysql_`date +%s`
mv mysql-5.1.-linux-$ar-glibc23 /usr/local/mysql
check_ok
if ! grep '^mysql:' /etc/passwd
then
useradd -M mysql -s /sbin/nologin
check_ok
fi
myum compat-libstdc++-
[ -d /data/mysql ] && /bin/mv /data/mysql /data/mysql_`date +%s`
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-huge.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 /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on
service mysqld start
check_ok
break
;;
5.6)
cd /usr/local/src
[ -f mysql-5.6.-linux-glibc2.-$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.-linux-glibc2.-$ar.tar.gz
check_ok
[ -d /usr/local/mysql ] && /bin/mv /usr/local/mysql /usr/local/mysql_bak
mv mysql-5.6.-linux-glibc2.-$ar /usr/local/mysql
if ! grep '^mysql:' /etc/passwd
then
useradd -M mysql -s /sbin/nologin
fi
myum compat-libstdc++-
[ -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 /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
;;
esac
done
} ##function of install httpd.
install_httpd() {
echo "Install apache version 2.2."
cd /usr/local/src
[ -f httpd-2.2..tar.gz ] || wget http://syslab.comsenz.com/downloads/linux/httpd-2.2.16.tar.gz
tar zxf httpd-2.2..tar.gz && cd httpd-2.2.
check_ok
./configure \
--prefix=/usr/local/apache2 \
--with-included-apr \
--enable-so \
--enable-deflate=shared \
--enable-expires=shared \
--enable-rewrite=shared \
--with-pcre
check_ok
make && make install
check_ok
} ##function of install lamp's php.
install_php() {
echo -e "Install php.\nPlease chose the version of php."
select php_v in 5.4 5.6
do
case $php_v in
5.4)
cd /usr/local/src/
[ -f php-5.4..tar.bz2 ] || wget 'http://cn2.php.net/get/php-5.4.45.tar.bz2/from/this/mirror' -O php-5.4..tar.bz2
tar jxf php-5.4..tar.bz2 && cd php-5.4. for p in openssl-devel bzip2-devel \
libxml2-devel curl-devel libpng-devel \
libjpeg-devel freetype-devel libmcrypt-devel\
libtool-ltdl-devel perl-devel
do
myum $p
done check_ok
./configure \
--prefix=/usr/local/php \
--with-apxs2=/usr/local/apache2/bin/apxs \
--with-config-file-path=/usr/local/php/etc \
--with-mysql=/usr/local/mysql \
--with-libxml-dir \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-freetype-dir \
--with-iconv-dir \
--with-zlib-dir \
--with-bz2 \
--with-openssl \
--with-mcrypt \
--enable-soap \
--enable-gd-native-ttf \
--enable-mbstring \
--enable-sockets \
--enable-exif \
--disable-ipv6
check_ok
make && make install
check_ok
[ -f /usr/local/php/etc/php.ini ] || /bin/cp php.ini-production /usr/local/php/etc/php.ini
break
;;
5.6)
cd /usr/local/src/
[ -f php-5.6..tar.gz ] || wget http://mirrors.sohu.com/php/php-5.6.6.tar.gz
tar zxf php-5.6..tar.gz && cd php-5.6.
for p in openssl-devel bzip2-devel \
libxml2-devel curl-devel libpng-devel \
libjpeg-devel freetype-devel libmcrypt-devel\
libtool-ltdl-devel perl-devel
do
myum $p
done ./configure \
--prefix=/usr/local/php \
--with-apxs2=/usr/local/apache2/bin/apxs \
--with-config-file-path=/usr/local/php/etc \
--with-mysql=/usr/local/mysql \
--with-libxml-dir \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-freetype-dir \
--with-iconv-dir \
--with-zlib-dir \
--with-bz2 \
--with-openssl \
--with-mcrypt \
--enable-soap \
--enable-gd-native-ttf \
--enable-mbstring \
--enable-sockets \
--enable-exif \
--disable-ipv6
check_ok
make && make install
check_ok
[ -f /usr/local/php/etc/php.ini ] || /bin/cp php.ini-production /usr/local/php/etc/php.ini
break
;; *)
echo "only 1(5.4) or 2(5.6)"
;;
esac
done
} ##function of apache and php configue.
join_apa_php() {
sed -i '/AddType .*.gz .tgz$/a\AddType application\/x-httpd-php .php' /usr/local/apache2/conf/httpd.conf
check_ok
sed -i 's/DirectoryIndex index.html/DirectoryIndex index.php index.html index.htm/' /usr/local/apache2/conf/httpd.conf
check_ok
cat > /usr/local/apache2/htdocs/index.php <<EOF
<?php
phpinfo();
?>
EOF if /usr/local/php/bin/php -i |grep -iq 'date.timezone => no value'
then
sed -i '/;date.timezone =$/a\date.timezone = "Asia\/Chongqing"' /usr/local/php/etc/php.ini
fi /usr/local/apache2/bin/apachectl restart
check_ok
} ##function of check service is running or not, example nginx, httpd, php-fpm.
check_service() {
if [ "$1" == "phpfpm" ]
then
s="php-fpm"
else
s=$
fi
n=`ps aux |grep "$s"|wc -l`
if [ $n -gt ]
then
echo "$1 service is already started."
else
if [ -f /etc/init.d/$ ]
then
/etc/init.d/$ start
check_ok
else
install_$
fi
fi
} ##function of install lamp
lamp() {
check_service mysqld
check_service httpd
install_php
join_apa_php
echo "LAMP done,Please use 'http://your ip/index.php' to access."
} ##function of install nginx
install_nginx() {
cd /usr/local/src
[ -f nginx-1.8..tar.gz ] || wget http://nginx.org/download/nginx-1.8.0.tar.gz
tar zxf nginx-1.8..tar.gz
cd nginx-1.8.
myum pcre-devel
./configure --prefix=/usr/local/nginx
check_ok
make && make install
check_ok
if [ -f /etc/init.d/nginx ]
then
/bin/mv /etc/init.d/nginx /etc/init.d/nginx_`date +%s`
fi
curl http://www.apelearn.com/study_v2/.nginx_init -o /etc/init.d/nginx
check_ok
chmod /etc/init.d/nginx
chkconfig --add nginx
chkconfig nginx on
curl http://www.apelearn.com/study_v2/.nginx_conf -o /usr/local/nginx/conf/nginx.conf
check_ok
service nginx start
check_ok
echo -e "<?php\n phpinfo();\n?>" > /usr/local/nginx/html/index.php
check_ok
} ##function of install php-fpm
install_phpfpm() {
echo -e "Install php.\nPlease chose the version of php."
select php_v in 5.4 5.6
do
case $php_v in
5.4)
cd /usr/local/src/
[ -f php-5.4..tar.bz2 ] || wget 'http://cn2.php.net/get/php-5.4.45.tar.bz2/from/this/mirror' -O php-5.4..tar.bz2
tar jxf php-5.4..tar.bz2 && cd php-5.4.
for p in openssl-devel bzip2-devel \
libxml2-devel curl-devel libpng-devel \
libjpeg-devel freetype-devel libmcrypt-devel\
libtool-ltdl-devel perl-devel
do
myum $p
done
if ! grep -q '^php-fpm:' /etc/passwd
then
useradd -M -s /sbin/nologin php-fpm
check_ok
fi
./configure \
--prefix=/usr/local/php-fpm \
--with-config-file-path=/usr/local/php-fpm/etc \
--enable-fpm \
--with-fpm-user=php-fpm \
--with-fpm-group=php-fpm \
--with-mysql=/usr/local/mysql \
--with-mysql-sock=/tmp/mysql.sock \
--with-libxml-dir \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-freetype-dir \
--with-iconv-dir \
--with-zlib-dir \
--with-mcrypt \
--enable-soap \
--enable-gd-native-ttf \
--enable-ftp \
--enable-mbstring \
--enable-exif \
--enable-zend-multibyte \
--disable-ipv6 \
--with-pear \
--with-curl \
--with-openssl
check_ok
make && make install
check_ok
[ -f /usr/local/php-fpm/etc/php.ini ] || /bin/cp php.ini-production /usr/local/php-fpm/etc/php.ini
if /usr/local/php-fpm/bin/php -i |grep -iq 'date.timezone => no value'
then
sed -i '/;date.timezone =$/a\date.timezone = "Asia\/Chongqing"' /usr/local/php-fpm/etc/php.ini
check_ok
fi
[ -f /usr/local/php-fpm/etc/php-fpm.conf ] || curl http://www.apelearn.com/study_v2/.phpfpm_conf -o /usr/local/php-fpm/etc/php-fpm.conf
[ -f /etc/init.d/phpfpm ] || /bin/cp sapi/fpm/init.d.php-fpm /etc/init.d/phpfpm
chmod /etc/init.d/phpfpm
chkconfig phpfpm on
service phpfpm start
check_ok
break
;;
5.6)
cd /usr/local/src/
[ -f php-5.6..tar.gz ] || wget http://mirrors.sohu.com/php/php-5.6.6.tar.gz tar zxf php-5.6..tar.gz && cd php-5.6.
for p in openssl-devel bzip2-devel \
libxml2-devel curl-devel libpng-devel \
libjpeg-devel freetype-devel libmcrypt-devel\
libtool-ltdl-devel perl-devel
do
myum $p
done if ! grep -q '^php-fpm:' /etc/passwd
then
useradd -M -s /sbin/nologin php-fpm
fi
check_ok
./configure \
--prefix=/usr/local/php-fpm \
--with-config-file-path=/usr/local/php-fpm/etc \
--enable-fpm \
--with-fpm-user=php-fpm \
--with-fpm-group=php-fpm \
--with-mysql=/usr/local/mysql \
--with-mysql-sock=/tmp/mysql.sock \
--with-libxml-dir \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-freetype-dir \
--with-iconv-dir \
--with-zlib-dir \
--with-mcrypt \
--enable-soap \
--enable-gd-native-ttf \
--enable-ftp \
--enable-mbstring \
--enable-exif \
--disable-ipv6 \
--with-pear \
--with-curl \
--with-openssl
check_ok
make && make install
check_ok
[ -f /usr/local/php-fpm/etc/php.ini ] || /bin/cp php.ini-production /usr/local/php-fpm/etc/php.ini
if /usr/local/php-fpm/bin/php -i |grep -iq 'date.timezone => no value'
then
sed -i '/;date.timezone =$/a\date.timezone = "Asia\/Chongqing"' /usr/local/php-fpm/etc/php.ini
check_ok
fi
[ -f /usr/local/php-fpm/etc/php-fpm.conf ] || curl http://www.apelearn.com/study_v2/.phpfpm_conf -o /usr/local/php-fpm/etc/php-fpm.conf
check_ok
[ -f /etc/init.d/phpfpm ] || /bin/cp sapi/fpm/init.d.php-fpm /etc/init.d/phpfpm
chmod /etc/init.d/phpfpm
chkconfig phpfpm on
service phpfpm start
check_ok
break
;; *)
echo 'only 1(5.4) or 2(5.6)'
;;
esac
done
} ##function of install lnmp
lnmp() {
check_service mysqld
check_service nginx
check_service phpfpm
echo "The lnmp done, Please use 'http://your ip/index.php' to access."
} read -p "Please chose which type env you install, (lamp|lnmp)? " t
case $t in
lamp)
lamp
;;
lnmp)
lnmp
;;
*)
echo "Only 'lamp' or 'lnmp' your can input."
;;
esac

第一个知识点

sed -i '/^\[mysqld\]$/a\datadir = /data/mysql' /etc/my.cnf   (http://www.cnblogs.com/MYSQLZOUQI/p/5164877.html  lanmp一键安装脚本)

第二个知识点

变量和字符串比较不能用-eq ,数字比较才能用-eq,要用==

if [ "$1"=="phpfpm" ]

上面mysql的安装无论5.1或5.6的shell代码都是一样的,只是下载的包不同

第三个知识点

#完全重定向

cat > /usr/local/apache2/htdocs/index.php <<EOF

<?php

phpinfo();

?>

EOF

第四个知识点

shell的变量和函数命名不能有横杠

只能是大小写字母 下划线 数字

if [ "$1" == "phpfpm" ]

第五个知识点

平台可以用arch命令,获取是i686还是x86_64

[root@steven ~]# arch

x86_64

第六个知识点

curl http://www.apelearn.com/study_v2/.nginx_init  -o /etc/init.d/nginx

curl 文件已存在会直接覆盖

-O大o下载文件,不需要指定名字: curl -O  http://study.lishiming.net/index.html

-o小o下载文件,需要自定义名字: curl -o /tmp/index2.html http://study.lishiming.net/index.html

wget 文件已存在会直接覆盖

下载文件,不需要指定名字:  wget http://www.minjieren.com/wordpress-3.1-zh_CN.zip

大写的O下载并以不同的文件名保存:  wget -O wordpress.zip  http://www.minjieren.com/download.aspx?id=1080

第七个知识点

#为了跟check_service保持一致,这里是phpfpm

[ -f /etc/init.d/phpfpm ] || /bin/cp sapi/fpm/init.d.php-fpm /etc/init.d/phpfpm

chmod 755 /etc/init.d/phpfpm

centos shell编程5  LANMP一键安装脚本 lamp  sed  lnmp  变量和字符串比较不能用-eq  cat > /usr/local/apache2/htdocs/index.php <<EOF重定向 shell的变量和函数命名不能有横杠  平台可以用arch命令,获取是i686还是x86_64  curl 下载   第三十九节课

f

centos shell编程5 LANMP一键安装脚本 lamp sed lnmp 变量和字符串比较不能用-eq cat > /usr/local/apache2/htdocs/index.php <<EOF重定向 shell的变量和函数命名不能有横杠 平台可以用arch命令,获取是i686还是x86_64 curl 下载 第三十九节课的更多相关文章

  1. centos shell脚本编程1 正则 shell脚本结构 read命令 date命令的用法 shell中的逻辑判断 if 判断文件、目录属性 shell数组简单用法 &dollar;&lpar; &rpar; 和&dollar;&lbrace; &rcub; 和&dollar;&lpar;&lpar; &rpar;&rpar; 与 sh -n sh -x sh -v 第三十五节课

    centos   shell脚本编程1 正则  shell脚本结构  read命令  date命令的用法  shell中的逻辑判断  if 判断文件.目录属性  shell数组简单用法 $( ) 和$ ...

  2. centos shell脚本编程2 if 判断 case判断 shell脚本中的循环 for while shell中的函数 break continue test 命令 第三十六节课

    centos  shell脚本编程2 if 判断  case判断   shell脚本中的循环  for   while   shell中的函数  break  continue  test 命令   ...

  3. centos MySQL主从配置 ntsysv chkconfig setup命令 配置MySQL 主从 子shell MySQL备份 kill命令 pid文件 discuz&excl;论坛数据库读写分离 双主搭建 mysql&period;history 第二十九节课

    centos  MySQL主从配置 ntsysv   chkconfig  setup命令  配置MySQL 主从 子shell  MySQL备份  kill命令  pid文件  discuz!论坛数 ...

  4. centos LAMP第一部分-环境搭建 Linux软件删除方式&comma;mysql安装&comma;apache&comma;PHP&comma;apache和php结合&comma;phpinfo页面&comma;ldd命令 第十九节课

    centos LAMP第一部分-环境搭建  Linux软件删除方式,mysql安装,apache,PHP,apache和php结合,phpinfo页面,ldd命令 第十九节课 打命令之后可以输入: e ...

  5. centos Linux系统日常管理2 tcpdump&comma;tshark&comma;selinux&comma;strings命令&comma; iptables &comma;crontab&comma;TCP&comma;UDP&comma;ICMP&comma;FTP网络知识 第十五节课

    centos  Linux系统日常管理2  tcpdump,tshark,selinux,strings命令, iptables ,crontab,TCP,UDP,ICMP,FTP网络知识 第十五节课 ...

  6. LNMP、LAMP、LANMP一键安装脚本(定期更新)&lbrack;转&rsqb;

    这个脚本是使用shell编写,为了快速在生产环境上部署LNMP/LAMP/LANMP(Linux.Nginx/Tengine.MySQL/MariaDB/Percona.PHP),适用于CentOS/ ...

  7. Centos 6&period;4 搭建LANMP一键安装版

    lanmp一键安装包是wdlinux官网2010年开始推出的lamp,lnmp,lnamp(apache,nginx,php,mysql,zend,eAccelerator,pureftpd)应用环境 ...

  8. &lpar;转&rpar;CentOS&sol;Debian&sol;Ubuntu系统 TCP-BBR 一键安装脚本

    本脚本适用环境 系统支持:CentOS 6+,Debian 7+,Ubuntu 12+ 虚拟技术:OpenVZ 以外的(KVM.Xen.VMware等) 内存要求:≥128M 日期 :2017 年 0 ...

  9. 使用 shell 脚本实现 LANMP 一键安装

    使用 shell 脚本来实现 LANMP 系统的一键安装.使用的操作系统是 CentOS 6 ,不区分 32 位和 64 位,要求机器可以连通互联网.支持 LAMP 和 LNMP ,MySQL 支持 ...

随机推荐

  1. java程序打包成jar 配置文件信息路径

    一个普通的java project,里面引用了config.properties配置文件,将项目打成Runnable jar,然后将config.properties放到打包后的jar路径下,执行该j ...

  2. 将 Wing IDE 与 Maya 结合使用&lpar;摘自Maya用户指南&rpar;

    1. 将 wingdbstub.py 从 Wing IDE 安装目录复制到 Maya Python 脚本路径. 2. 确保已在“Wing IDE > 编辑 > 首选项 > 调试器”中 ...

  3. Java中的事务——JDBC事务和JTA事务

    Java中的事务——JDBC事务和JTA事务 转载:http://www.hollischuang.com/archives/1658 之前的事务介绍基本都是数据库层面的事务,本文来介绍一下J2EE中 ...

  4. &lbrack;MySQL&rsqb;--&amp&semi;gt&semi;询5 几天之内解决在新年发行一个同事的生日过程

    前言:        遇到朋友提问,例如以下:SELECT * FROM ali_users WHERE  DATEDIFF(CAST(CONCAT(DATE_FORMAT(NOW(),'%y'),D ...

  5. 关于Arduino 步进电机Stepper库的一些想法

    官方提供了一些库,使Arduino入门起来更加快速,我们连原理都不用懂,就能通过函数控制终端.但是,这样也带来了很多的缺陷,比如,库函数的功能有限,有些无法实现.然后还有库函数因为要考虑其他的情况,你 ...

  6. Java学习笔记 抽象类 接口 多态

    instanceof 对象名 instanceof 类名 该对象是否属于该类 Animal animal = new Dog(); if(animal instanceof Dog){ Dog d = ...

  7. Oracle使用——oracle复制表

    复制表结构和数据 create table table_name_new as select * from table_name_old; 复制表结构 ; 复制表数据(全量插入数据) 两个表结构相同 ...

  8. Access查询时间段 &period;

    access数据库cmd // SendTime是在Access数据库中是文本类型 StringBuilder sb = new StringBuilder(); sb.Append("SE ...

  9. ubuntu 配置拼音输入法步骤

    今天配置了一下 ubuntu 拼音,要求使用ubuntu 内置拼音.大致步骤我记录一下: 配置拼音,使用 ibus pinyin,网上有很多帖子大致步骤: 1)安装 中文语言 2)安装ibus 3)  ...

  10. 17-使用公共 Registry

    Docker Hub 是 Docker 公司维护的公共 Registry.用户可以将自己的镜像保存到 Docker Hub 免费的 repository 中.如果不希望别人访问自己的镜像,也可以购买私 ...