lanmp的一键安装脚本

创建lanmp一键安装的脚本

思路:1.设置自动安装lamp和lnmp

2.lamp脚本的编译安装

(mysql版本 5.1 或者5.6 二个版本)

(apache 版本 2.2版本)

(php 版本 5.4版本 5.6版本)

3.lnmp脚本的编译安装

(mysql版本 5.1 或者5.6 二个版本)

(nginx 版本 1.6版本)

(php 版本 5.4版本 5.6版本)

修改权限 chmod a+x lanmp.sh

vim lanmp.sh



#设置lamp 或 lnmp的脚本安装

#!/bin/bash

echo "It will install lamp or lnmp."

sleep 1

##check last command is OK or not.

check_ok() {

if [ $? != 0 ]

then

echo "Error, Check the error log."

exit 1

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" ]

then

setenforce 0

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 $1

check_ok

else

echo $1 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-6.repo* >/dev/null 2>&1

then

rm -f /etc/yum.repos.d/epel-6.repo*

fi

wget -P /etc/yum.repos.d/ http://mirrors.aliyun.com/repo/epel-6.repo



#开始安装lamp

##function of installing mysqld.

install_mysqld() {

case $mysql_v in

5.1)

cd /usr/local/src

[ -f mysql-5.1.73-linux-$ar-glibc23.tar.gz ] || wget http://mirrors.sohu.com/mysql/MySQL-5.1/mysql-5.1.73-linux-i686-glibc23.tar.gz

tar zxvf mysql-5.1.73-linux-i686-glibc23.tar.gz

check_ok

[ -d /usr/local/mysql ] && /bin/mv /usr/local/mysql /usr/local/mysql_`date +%s`

mv mysql-5.1.73-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.26-linux-glibc2.5-$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.26-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.26-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

}

##function of install httpd.

install_httpd() {

echo "Install apache version 2.2."

cd /usr/local/src

[ -f httpd-2.2.31.tar.gz ] || wget  http://mirrors.cnnic.cn/apache/httpd/httpd-2.2.31.tar.gz

tar zxvf 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.

install_php() {

echo -e "Install php.\nPlease chose the version of php."

case $php_v in

5.4)

cd /usr/local/src/

[ -f mirror ] || wget http://cn2.php.net/get/php-5.4.45.tar.bz2/from/this/mirror

tar jxf mirror && 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

}

##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=$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

}



#开始安装lnmp

##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.6.3.tar.gz ] || wget http://nginx.org/download/nginx-1.6.3.tar.gz

tar zxf nginx-1.6.3.tar.gz && cd nginx-1.6.3

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

install_phpfpm() {

echo -e "Install php.\nPlease chose the version of php."

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.21.tar.gz ] || wget http://cn2.php.net/get/php-5.6.21.tar.bz2/from/this/mirror

tar zxf php-5.6.21.tar.gz &&   cd php-5.6.21

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

}

##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)

read -p "Please chose the version of mysql. (5.1|5.6)" mysql_v

read -p "Please chose the version of php. (5.4|5.6)" php_v

lamp

;;

lnmp)

read -p "Please chose the version of mysql. (5.1|5.6)" mysql_v

read -p "Please chose the version of php. (5.4|5.6)" php_v

lnmp

;;

*)

echo "Only ‘lamp‘ or ‘lnmp‘ your can input."

;;

esac

1.运行脚本

./lanmp.sh

2.选择要安装的架构 和版本

lamp

时间: 2024-10-17 21:36:44

lanmp的一键安装脚本的相关文章

CentOS 6、7下IPSEC/L2TP VPN一键安装脚本(openswan+xl2tpd)

CentOS 6.7下IPSEC/L2TP VPN一键安装脚本(openswan+xl2tpd) 概念性的东西这里不再赘述,网上有太多,一键安装脚本也有很多,但是很多不能用,能用的也仅仅只是在CentOS6下使用,CentOS7基本没看到这些安装脚本.于是花了一些时间来折腾测试,写这个脚本方便以后VPN的一键安装搭建.其中用的开源软件包是openswan和xl2tpd,,中间碰到过很多很多问题,如openswan和xl2tpd之间的兼容性问题. 请容许我这样做,脚本依赖<OneinStack>

CentOS 6、7下pptp vpn一键安装脚本

之前有折腾过<CentOS 6.7下IPSEC/L2TP VPN一键安装脚本>,不稳定.不支持IOS,因此换成pptp,并已经添加到<lnmp一键安装包>.这个脚本可以单独使用,直接复制或下载执行即可,不用依赖安装包的其它脚本. CentOS 6.7下pptp vpn一键安装脚本,安装如下: wget http://mirrors.linuxeye.com/scripts/vpn_centos.sh chmod +x ./vpn_centos.sh ./vpn_centos.sh

Ubuntu Or Debian L2TP VPN 一键安装脚本

#!/bin/bash if [ $(id -u) != "0" ]; then printf "Error: You must be root to run this tool!\n" exit 1 fi clear printf " #################################################### # # # This is a Shell-Based tool of l2tp installation # #

Centos7搭建pptp VPN一键安装脚本

Centos7搭建pptp一键安装脚本 废话不多说,先上脚本地址:Centos7一键pptp 使用: wget https://raw.githubusercontent.com/DanylZhang/VPS/master/CentOS7-pptp-host1plus.sh chmod +x ./CentOS7-pptp-host1plus.sh ./CentOS7-pptp-host1plus.sh -u your_username -p your_password 1 2 3 可在-u.-p

L2TP/IPSec一键安装脚本

本脚本适用环境:系统支持:CentOS6+,Debian7+,Ubuntu12+内存要求:≥128M更新日期:2017 年 05 月 28 日 关于本脚本:名词解释如下L2TP(Layer 2 Tunneling Protocol)IPSec(Internet Protocol Security)IKEv2 (Internet Key Exchange v2)能实现 IPsec 的目前总体上有 openswan,libreswan,strongswan 这3种.libreswan 是基于 ope

centos shell编程5LANMP一键安装脚本 第三十九节课

centos shell编程5LANMP一键安装脚本  第三十九节课 上半节课 下半节课 f

PXE一键安装脚本

PXE(preboot execute environment,预启动执行环境)是由Intel公司开发的最新技术,工作于Client/Server的网络模式,支持工作站通过网络从远端服务器下载映像,并由此支持通过网络启动操作系统,在启动过程中,终端要求服务器分配IP地址,再用TFTP(trivial file transfer protocol)或MTFTP(multicast trivial file transfer protocol)协议下载一个启动软件包到本机内存中执行,由这个启动软件包

mysql oracle静默 一键安装脚本

pre-read; 为了达到一键搞定的目的!现Ruiy简单做如下几小条规定   如果你想这么一键来搞定请君莫要违背约束!1. 下载 `二进制` mysql软件介质版本不限,二进制包务必,源码及rpm包格式,此处玩不转;eg:    wget http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.17-linux-glibc2.5-x86_64.tar.gz 2. 将下载下来的二进制mysql安装介质放到/opt/yoodo/installs/目录,

ss-panel(ss-R)前后端一键安装脚本(转)

ss-panel(ss-R)前后端一键安装脚本 前几天分享了ss-panel前后端的搭建教程,现在为了练习自己的技术,写了个一键安装脚本! 请注意,本脚本仅仅适用于centos7.* 最新更新:2016/11/5 本脚本包括以下功能: 使用rpm方式搭建LNMP,比市场上的LNMP一键安装包更高效,同时减轻了CPU负担,安装的时间段而且不会安装太多依赖 安装是依赖最新的SS-panel的源码,以及最新ss-rm的代码 本脚本集成了对LNMP以及ss的前端和后端,但是部分依然需要手动操作,请看详细