使用 shell 脚本来实现 LANMP 系统的一键安装。使用的操作系统是 CentOS 6 ,不区分 32 位和 64 位,要求机器可以连通互联网。支持 LAMP 和 LNMP ,MySQL 支持 5.1 和 5.6 两个版本, php 支持 5.3 和 5.6 两个版本, apache 2.2 ,nginx 1.8。
代码如下:
#!/bin/bash
echo "It will install lamp or lnmp."
sleep 1 # get the archive of the system: i686 or x86_64.
ar=`arch` # check last command is OK or Not.
function check_ok()
{
if [ $? != 0 ];then
echo "Error, Check the error log."
exit 1
fi
} # close seliux
function close_selinux()
{
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
selinux_s=`getenforce`
if [ $selinux_s == "Enforcing" -o $selinux_s == "enforcing" ];then
setenforce 0
fi
} # close iptables
function clear_iptables()
{
iptables-save > /etc/sysconfig/iptables_`date +%s`
iptables -F
service iptables save
} # if the packge installed ,then omit.
function myum() {
if ! rpm -qa|grep -q "^$1" ;then
yum install -y $1
check_ok
else
echo $1 already installed.
fi
} ## install some packges.
function install_pre_packages
{
for p in gcc wget perl perl-devel libaio libaio-devel pcre-devel zlib-devel ;do
myum $p
done
}
install_pre_packages # install epel repo.
function install_epel()
{
if rpm -qa epel-release >/dev/null ;then
rpm -e epel-release
fi
if ls /etc/yum.repos.d/epel-6.repo* >/dev/null 2>&1 ;then
/bin/rm -f /etc/yum.repos.d/epel-6.repo*
fi
wget -P /etc/yum.repos.d/ http://mirrors.aliyun.com/repo/epel-6.repo
}
install_epel # function of installing mysqld.
function 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.72-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.72-linux-$ar-glibc23.tar.gz
check_ok
[ -d /usr/local/mysql ] && /bin/mv /usr/local/mysql /usr/local/mysql_`date +%s`
/bin/mv mysql-5.1.72-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++-33
[ -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 755 /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.35-linux-glibc2.5-$ar.tar.gz ] || wget \
http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.35-linux-glibc2.5-$ar.tar.gz
tar zxf mysql-5.6.35-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.35-linux-glibc2.5-$ar /usr/local/mysql
if ! grep '^mysql:' /etc/passwd
then
useradd -M mysql -s /sbin/nologin
fi
myum 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
} # function of install httpd.
function install_httpd() {
echo "Install apache version 2.2."
cd /usr/local/src
[ -f httpd-2.2.31.tar.gz ] || wget http://mirror.bit.edu.cn/apache/httpd/httpd-2.2.31.tar.gz
tar zxf httpd-2.2.31.tar.gz && cd httpd-2.2.31
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.
function 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.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
tar jxf php-5.4.45.tar.bz2 && cd php-5.4.45
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.6.tar.gz ] || wget http://mirrors.sohu.com/php/php-5.6.6.tar.gz
tar zxf php-5.6.6.tar.gz && cd php-5.6.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.
function 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
echo -e "<?php\n phpinfo();\n?>" > /usr/local/apache2/htdocs/index.php
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.
function check_service() {
if [ "$1" == "phpfpm" ];then
s="php-fpm"
else
s=$1
fi
n=`ps aux |grep "$s"|wc -l`
if [ $n -gt 1 ];then
echo "$1 service is already started."
else
if [ -f /etc/init.d/$1 ];then
/etc/init.d/$1 start
check_ok
else
install_$1
fi
fi
} # function of install lamp
function 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
function install_nginx()
{
cd /usr/local/src
[ -f nginx-1.8.0.tar.gz ] || wget http://mirrors.sohu.com/nginx/nginx-1.8.0.tar.gz
tar zxf nginx-1.8.0.tar.gz
cd nginx-1.8.0
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 755 /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
function 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.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
tar jxf php-5.4.45.tar.bz2 && cd php-5.4.45
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 755 /etc/init.d/phpfpm
chkconfig phpfpm on
service phpfpm start
check_ok
break
;;
5.6)
cd /usr/local/src/
[ -f php-5.6.6.tar.gz ] || wget http://mirrors.sohu.com/php/php-5.6.6.tar.gz
tar zxf php-5.6.6.tar.gz && cd php-5.6.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 755 /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
function 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
使用 shell 脚本实现 LANMP 一键安装的更多相关文章
-
centos shell编程5 LANMP一键安装脚本 lamp sed lnmp 变量和字符串比较不能用-eq cat >; /usr/local/apache2/htdocs/index.php <;<;EOF重定向 shell的变量和函数命名不能有横杠 平台可以用arch命令,获取是i686还是x86_64 curl 下载 第三十九节课
centos shell编程5 LANMP一键安装脚本 lamp sed lnmp 变量和字符串比较不能用-eq cat > /usr/local/apache2/htdocs/ind ...
-
Shell 脚本之 MySQL 一键安装及基本配置(几分钟搞定)
准备工作 MySQL 该版本下载地址: https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.30-linux-glibc2.12- ...
-
LNMP、LAMP、LANMP一键安装脚本(定期更新)[转]
这个脚本是使用shell编写,为了快速在生产环境上部署LNMP/LAMP/LANMP(Linux.Nginx/Tengine.MySQL/MariaDB/Percona.PHP),适用于CentOS/ ...
-
Centos 6.4 搭建LANMP一键安装版
lanmp一键安装包是wdlinux官网2010年开始推出的lamp,lnmp,lnamp(apache,nginx,php,mysql,zend,eAccelerator,pureftpd)应用环境 ...
-
shell脚本之nginx的安装
为了编写nginx自动部署的脚本而刚学习的shell脚本语言.写文章只是为了记录,有错误勿喷. 一.创建shell脚本程序 操作系统是Linux的 CentOS 7 版本. ...
-
shell脚本实现nfs服务安装配置,共享文件分发
##############################Deploy nfs######################## echo "start deploy nfs-server& ...
-
【Shell】使用shell打印菜单,一键安装Web应用
问题描述: [解答] [root@A04-Test- scripts]# more menu.sh #!/bin/bash echo "1.[install lamp]" echo ...
-
shell脚本 PHP+swoole的安装
#!bin/bash set -e # Check if user is root if [ $(id -u) != "0" ]; then echo "Error: p ...
-
Shell脚本一键安装LNMP环境
https://sourceforge.net/projects/opensourcefile/files/ Nginx是一款高性能的HTTP和反向代理服务器.Nginx在反向代理,Rewrite规则 ...
随机推荐
-
在Oracle中恢复被DROP掉的表
在Oracle中可能不小心会DROP掉一个表,如果没有定期做备份的话,将会带来很大的麻烦.如果有的情况下,每天的数据都很重要,而定期备份的周期又稍长,情况恐怕也不容乐观!以前只知道Windows有个回 ...
-
MYSQL复制
今天我们聊聊复制,复制对于mysql的重要性不言而喻,mysql集群的负载均衡,读写分离和高可用都是基于复制实现.下文主要从4个方面展开,mysql的异步复制,半同步复制和并行复制,最后会简单聊下第三 ...
-
EMS问题
如果EMS启动后在运行时报出 JMS error: "Not allowed to create destination这个错误,可能就是你启动方式的问题了 进入到EMS的安装目录的bin目 ...
-
iOS /* */多个嵌套解决
解决办法 #if 0 /* */ #endif
-
CVS的使用
基本术语 Repository 仓库 [rɪ'pɒzətrɪ] Module 模块 ['mɒdju:l] Import 导入 Checkout 导出 Commit 提交修改 [kə'mɪt] Upda ...
-
HTML DOM访问
访问 HTML 元素(节点) 访问 HTML 元素等同于访问节点 您能够以不同的方式来访问 HTML 元素: 通过使用 getElementById() 方法 通过使用 getElementsByTa ...
-
查看Oracle有哪些表或者视图
转自:http://www.2cto.com/database/201211/167577.html 1.查询当前用户下,有哪些表 Sql代码 SELECT * FROM user_tables ...
-
Red Gate系列之六 SQL Test 1.0.12.3 Edition SQL测试工具 完全破解+使用教程
原文:Red Gate系列之六 SQL Test 1.0.12.3 Edition SQL测试工具 完全破解+使用教程 Red Gate系列之六 SQL Test 1.0.12.3 Edition S ...
-
REST Adapter实现SAP PI中的增强XML/JSON格式转换
SAP标准的REST adapter有着XML/JSON转换的功能,它很有用,因为一方面SAP PI/PO内部以XML格式处理数据,而另一方面,在处理REST架构风格的时候,JSON才是事实上的格式. ...
-
IPV6与IPV4的区别
IPv4协议的地址长度是32位,IPv6协议的地址长度是128位. 1.表示方式 IPv4地址表示为点分十进制格式,32位的地址分成4个8位分组,每个8位以十进制数显式,中间用点号分隔. 而IPv6采 ...