2.4-lanmp脚本思路

#!/bin/bash

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

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                             #N值则退出

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表到指定位置

iptables -F

service iptables save

##if the packge installed ,then omit.

myum() {

if ! rpm -qa|grep -q "^$1"   #grep -q用于if逻辑判断,安静模式,不打印任何标准输出,匹配返回0

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 | grep epel-release >/dev/null   为什么不匹配包,不提示而下4行提示?

then                                  需要加个2>&1才不提示?

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

##function of installing mysqld.

install_mysqld() {

case $mysql_v in

5.1)

cd /usr/local/src

[ -f mysql-5.1.40-linux-$ar-icc-glibc23.tar.gz ] || wget http://www.lishiming.net/data/attachment/forum/mysql-5.1.40-linux-$ar-icc-glibc23.tar.gz

tar zxvf mysql-5.1.40-linux-$ar-icc-glibc23.tar.gz

check_ok

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

mv mysql-5.1.40-linux-$ar-icc-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.16.tar.gz ] || wget  http://syslab.comsenz.com/downloads/linux/httpd-2.2.16.tar.gz

tar zxf  httpd-2.2.16.tar.gz && cd httpd-2.2.16

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

}

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

}

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

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

}

##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   #给mysql赋予版本值

read -p "Please chose the version of php. (5.4|5.6)" php_v       #给php赋予版本值

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

时间: 2024-12-31 13:52:49

2.4-lanmp脚本思路的相关文章

shell写脚本思路

Shell脚本编写思路:(需求分析) 1.LAMP源码一键整合 ======================= 1)安装apache.Mysql.PHP.LAMP整合: ------------------------ 安装apache 安装MYSQL 安装PHP ------------------------- 2)去官网下载相应的版本,解压.编译: 软件的版本信息 定义变量,变量名设置 安装的参数.安装的目录: ------------------------- 3)整合LAMP源码: M

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的脚本安装 #!

随机修改nginx端口脚本及思路

需求:随机修改nginx端口,一小时一次,然后发邮件通知 脚本思路,先在/root目录下建立个1.txt文件,随机填入4位数字 建个2.sh脚本,脚本内容如下: #!/bin/bash cd b=`echo $RANDOM |cut -c 1-4` echo $b >2.txt 上主脚本port_change.sh #!/bin/bash cd c=`cat 1.txt` d=`cat 2.txt` netstat -lnpt|awk '{print $4}' |awk -F: '{print 

思路:如何快速写一个全面的数据库 增备+全备+删除,自动化的脚本?

1.数据作用: 数据对我们来说是非常非常的重要,如果你是管理数据员.运维人员的,数据丢失了,找不回来,也就意味着,你的职业生涯就结束了,为了避免数据丢失,我们也做了很多的维护.备份,比如做主从复制.做全备.增备等等.这个可以参考我的另一篇文章Mysql主从复制. 我这里就不多说,今天我们要怎么写一个比较好的数据备份自动化脚本,让我们更好的管理数据库. 2.mysql备份脚本思路 首先要有一个思路,我的要求是每个的周一到周五做增量备份,周六做全备,对前两天的增备的日志删除,对两个星期前的全备也进行

一键安装MySQL 主从复制SHELL脚本

脚本思路: 在从库上远程备份主库数据,再在从库上进行数据恢复,同时启动从库. 环境: CentOS6.5 已安装MySQL多实例,端口为3306 ,3307. 现通过自动安装主从脚本将两实例做主从复制. #!/bin/bash . /etc/rc.d/init.d/functions if [ $# -ne 0 ];then    echo "Usage:sh `basename $0`"    exit 1 fi #MASTER VARIABLES MASTER_USER=root

Bat脚本处理ftp超强案例解说

原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://369369.blog.51cto.com/319630/842341 Bat脚本处理ftp超强案例解说 前言:    公司有几百台windows服务器,每次程序更新,如果是一台台拷数据,只怕安排十个人,一天都不一定做得完,所以就必须研究个全自动更新方案来,于是就 想到了FTP,做个主FTP站,在几百台客户机上启动BAT脚本,每30秒检测一次,如果主站有更新程序,就自动下载更新,

Linux脚本

这周是最烧脑的一周,每天都沉迷在如何编写脚本中,我相信脚本这块让大家都很头疼,包括以后的工作肯定也离不开脚本.那么我们接下来针对脚本这块给大家做个详细的分析. 一.if语句 单分支:if 判断条件;then 条件为真的分支代码 fi 双分支:if 判断条件; then 条件为真的分支代码 else 条件为假的分支代码 fi 多分支:if 判断条件1; then 条件为真的分支代码 elif 判断条件2; then 条件为真的分支代码 elif 判断条件3; then 条件为真的分支代码 else

Centos 6.5全新安装firefox45.2浏览器脚本

在Centos 6.5x86_64系统中自带的是firefox 17版,版本太低,由于腾讯云实验室需要在firefox浏览器45版或45版以上的版本来支持,否则无法进入腾讯云实验室环境.而很多朋友想在Centos 6.5上安装新版本,却无法安装成功.在此给大家分享一键安装脚本.经过测试,此脚本能正常使用. 此脚本是在centos 6.5x86_64位版系统上下载并全新安装一个firefox45.0.2版到/usr/local/firefox目录,并在当前用户家目录创建firefox软件图标, #

线上使用zabbix报警脚本(含图片)

分享一个线上使用的自定义zabbix报警脚本,脚本思路大致如下: 1.使用爬虫获取报警图片(前提是要获得报警的item) 2.将图片与邮件内容整合 3.发送邮件 4.日志记录 脚本内容如下: #!/usr/bin/python #coding:utf-8 import sys,time,re,os,glob import smtplib from email.mime.text import MIMEText from email.mime.image import MIMEImage from