!/bin/bash
#this script is source packages installed lnmp for redhat or centos .xmal
yum -y install wget
#"============download the source package=============="
wget http://cloud.github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz
wget http://nginx.org/download/nginx-1.3.8.tar.gz
wget http://www.cmake.org/files/v2.8/cmake-2.8.6.tar.gz
wget http://ftp.gnu.org/gnu/bison/bison-2.5.1.tar.gz
wget http://cdn.mysql.com/Downloads/MySQL-5.5/mysql-5.5.30.tar.gz
wget http://ncu.dl.sourceforge.net/project/qdbm/qdbm/1.8.77/qdbm-1.8.77.tar.gz
wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
wget http://fossies.org/linux/www/gd-2.0.35.tar.gz
wget http://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.bz2/download
wget http://sourceforge.net/projects/mhash/files/mhash/0.9.9.9/mhash-0.9.9.9.tar.bz2/download
wget http://sourceforge.net/projects/mcrypt/files/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz/download
wget http://cronolog.org/download/cronolog-1.6.2.tar.gz
wget http://cn2.php.net/distributions/php-5.4.14.tar.gz
wget http://ncu.dl.sourceforge.net/project/pcre/pcre/8.11/pcre-8.11.tar.gz
#"=============download all======================"
printf "========install the compile tool=============\n"
yum -y install gcc gcc-c++ openssl-devel ncurses ncurses-devel zlib-devel bzip2 bzip2-devel curl-devel libjpeg-devel libxml2* libpng* freetype* libxslt*
#yum -y groupinstall "Development" "Development Tools" #or use this command instead of the above
#tar the source package 解压源代码包到指定的目录
tar zxvf pcre-8.11.tar.gz -C /usr/local/src/
tar zxvf libevent-2.0.-stable.tar.gz -C /usr/local/src/
tar zxvf nginx-1.3..tar.gz -C /usr/local/src/
tar zxvf cmake-2.8..tar.gz -C /usr/local/src/
tar zxvf bison-2.5..tar.gz -C /usr/local/src/
tar zxvf mysql-5.5..tar.gz -C /usr/local/src/
tar zxvf libiconv-1.14.tar.gz -C /usr/local/src/
tar zxvf qdbm-1.8..tar.gz -C /usr/local/src/
tar zxvf gd-2.0..tar.gz -C /usr/local/src/
tar zxvf mcrypt-2.6..tar.gz -C /usr/local/src/
tar zxvf cronolog-1.6..tar.gz -C /usr/local/src/
tar zxvf php-5.4..tar.gz -C /usr/local/src/
tar jxvf libmcrypt-2.5..tar.bz2 -C /usr/local/src/
tar jxvf mhash-0.9.9.9.tar.bz2 -C /usr/local/src/
#Compile the unpack the source code package 编译解压的源代码包
echo"===========nginx Relevant source package is installed========== "
echo "##### pcre install#####"
cd /usr/local/src/pcre-8.11/
./configure --prefix=/usr/local/pcre && make && make install
printf "====pcre is ok====\n"
echo "#####libevent install######"
cd /usr/local/src/libevent-2.0.-stable/
./configure --prefix=/usr/local/libevent && make && make install
printf "====libevent is ok====\n"
echo "####nginx install######"
groupadd -r nginx
useradd -r -g nginx -s /bin/false -M nginx
cd /usr/local/src/nginx-1.3./
###before you configure,you can see "./configure –help" see carefully "–with-pcre=DIR set path to PCRE library sources"在编译之前可以先help看看
./configure --prefix=/usr/local/nginx --with-pcre=/usr/local/src/pcre-8.11/ --sbin-path=/usr/local/nginx/sbin/nginx --pid-path=/usr/local/nginx/logs/nginx.pid \
--with-http_gzip_static_module --with-http_ssl_module --with-http_flv_module --with-http_stub_status_module --user=nginx --group=nginx \
--http-proxy-temp-path=/var/tmp/nginx/proxy/ --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ --lock-path=/var/lock/nginx.lock --http-client-body-temp-path=/var/tmp/nginx/client/ \
&& make && make install
printf "======nginx is ok!!======\n"
mkdir -pv /var/tmp/nginx/
#write startup nginx files by yourself 自己手动写nginx的启动脚本
cat >> /etc/init.d/nginx << EOF
#!/bin/bash
# nginx Startup script for the Nginx HTTP Server
# it is v.0.0. version.
# chkconfig: –
# description: Nginx is a high-performance web and proxy server.
# It has a lot of features, but it’s not for everyone.
# processname: nginx
# pidfile: /var/run/nginx.pid
# config: /usr/local/nginx/conf/nginx.conf
nginxd=/usr/local/nginx/sbin/nginx
nginx_config=/usr/local/nginx/conf/nginx.conf
nginx_pid=/usr/local/nginx/logs/nginx.pid
RETVAL=
prog="nginx"
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit
[ -x $nginxd ] || exit
# Start nginx daemons functions.
start() {
if [ -e $nginx_pid ];then
echo "nginx already running…."
exit
fi
echo -n $"Starting $prog: "
daemon $nginxd -c ${nginx_config}
RETVAL=$?
echo
[ $RETVAL = ] && touch /var/lock/subsys/nginx
return $RETVAL
}
# Stop nginx daemons functions.
stop() {
echo -n $"Stopping $prog: "
killproc $nginxd
RETVAL=$?
echo
[ $RETVAL = ] && rm -f /var/lock/subsys/nginx /usr/local/nginx/logs/nginx.pid
}
reload() {
echo -n $"Reloading $prog: "
#kill -HUP `cat ${nginx_pid}`
killproc $nginxd -HUP
RETVAL=$?
echo
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
stop
start
;;
status)
status $prog
RETVAL=$?
;;
*)
echo "Usage: $prog {start|stop|restart|reload|status|help}"
exit
esac
exit $RETVAL
EOF
chmod +x /etc/init.d/nginx
chkconfig --add nginx
chkconfig --level nginx on
service nginx restart
echo"===========mysql Relevant source package is installed========== "
useradd -M -s /sbin/nologin mysql
echo "##### cmake install#####"
cd /usr/local/src/cmake-2.8.
./bootstrap && gmake && gmake install
printf "====cmake is ok====\n"
echo "##### bison install#####"
cd /usr/local/src/bison-2.5./
./configure && make && make install
printf "====bison is ok====\n"
echo "##### mysql install#####"
cd /usr/local/src/mysql-5.5./
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EXTRA_CHARSETS:STRING=utf8,gbk -DWITH_MYISAM_STORAGE_ENGINE= -DWITH_INNOBASE_STORAGE_ENGINE= -DWITH_READLINE= -DENABLED_LOCAL_INFILE= \
-DMYSQL_DATADIR=/var/mysql/data && make && make install
printf "====mysql is ok====\n"
#set up the mysql configuration file and initialize the database 建立mysql的配置文件和初始化数据库
#cp usr/local/mysql/support-files/my-huge.cnf /etc/my.cnf ##if you memory is greater than 2G,please choose this 内存大于2G就copy这个配置文件
cp /usr/local/mysql/support-files/my-medium.cnf /etc/my.cnf
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
/usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/var/mysql/data
/usr/local/mysql/bin/mysqld_safe --user=mysql
chmod -R /usr/local/mysql
chown -R mysql:mysql /usr/local/mysql
chown -R mysql:mysql /var/mysql/data
chkconfig --add mysqld
chkconfig --level mysqld on
service mysqld restart
read -p "please set up password for mysql:" pwd
/usr/local/mysql/bin/mysqladmin -u root password $pwd
export PATH=$PATH:/usr/local/mysql/bin/
echo "PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
ln -s /usr/local/mysql/bin/* /usr/local/bin/
ln -s /usr/local/mysql/lib/* /usr/lib
ln -s /usr/local/mysql/include/mysql/* /usr/include/
echo"===========php Relevant source package is installed========== "
echo "####libiconv install####"
cd /usr/local/src/libiconv-1.14/
./configure --prefix=/usr/local/libiconv && make && make install
printf "====libiconv is ok====\n"
echo "####qdbm install#####"
cd /usr/local/src/qdbm-1.8.77/
./configure --prefix=/usr/local/qdbm --enable-devel --enable-zlib --enable-iconv && make && make install
printf "====qdbm is ok====\n"
echo "####gd install####"
cd /usr/local/src/gd-2.0.35/
./configure --prefix=/usr/local/gd2 --with-jpeg --with-png --with-zlib --with-freetype && make && make install
printf "====gd is ok====\n"
sed -i '/\*gd_free/a\void (*data);' /usr/local/gd2/include/gd_io.h
echo "/usr/local/gd2/lib" >> /etc/ld.so.conf
ldconfig
echo "####libmcrypt and libltdl install####"
cd /usr/local/src/libmcrypt-2.5.8/
./configure --prefix=/usr/local/libmcrypt && make && make install
ldconfig
cd /usr/local/src/libmcrypt-2.5.8/libltdl
./configure --prefix=/usr/local/libltdl --enable-ltdl-install && make && make install
ln -sf /usr/local/lib/libmcrypt.* /usr/lib
ln -sf /usr/local/bin/libmcrypt-config /usr/bin
printf "====libmcrypt and libltdl is ok====\n"
echo "####mhash install####"
cd /usr/local/src/mhash-0.9.9.9/
./configure --prefix=/usr/local/mhash && make && make install
ln -sf /usr/local/lib/libmhash.* /usr/lib/
printf "====mhash is ok====\n"
echo "####mcrypt install####"
cd /usr/local/src/mcrypt-2.6.8/
/sbin/ldconfig
./configure --prefix=/usr/local/mcrypt && make && make install
printf "====mcrypt is ok====\n"
echo "####cronolog install####"
cd /usr/local/src/cronolog-1.6.2
./configure --prefix=/usr/local/cronolog && make && make install
printf "====cronolog is ok====\n"
echo "####php install#####"
ln -sf /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib
ln -sf /usr/local/qdbm/lib/libqdbm.so* /usr/lib
cd /usr/local/src/php-5.4.14
./configure --prefix=/usr/local/php5 --with-config-file-path=/usr/local/php5/etc --with-mysql=/usr/local/mysql \
--with-iconv=/usr/local/libiconv --with-gd=/usr/local/gd2 --with-iconv-dir=/usr/local --with-pdo-mysql=/usr/local/mysql \
--with-libxml-dir=/usr --with-qdbm=/usr/local/qdbm --with-mime-magic=/usr/share/file/magic --with-jpeg-dir --with-png-dir --with-freetype-dir \
--with-bz2 --with-zlib --without-pear --with-xmlrpc --with-zlib-dir --with-curl --with-curlwrappers --with-mcrypt=/usr/local/libmcrypt --with-mhash \
--with-ttf --with-xsl --with-gettext --with-pear --with-openssl --enable-discard-path --enable-gd-native-ttf \
--enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-mbregex --enable-xml \
--enable-soap --enable-calendar --enable-wddx --enable-dba --enable-gd-native-ttf--enable-calendar --enable-safe-mode \
--enable-ftp --enable-fpm --enable-zip --enable-mbstring --enable-bcmath --enable-sockets --enable-exif --enable-magic-quotes --disable-rpath --disable-debug \
&& make && make install
printf "====php is ok====\n"
ln -s /usr/local/php5/bin/* /usr/local/bin/
ln -s /usr/local/php5/sbin/* /usr/local/sbin/
cp /usr/local/src/php-5.4.14/php.ini-production /usr/local/php5/php.ini
#Configure nginx support php 配置nginx支持php环境
cp /usr/local/php5/etc/php-fpm.conf.default /usr/local/php5/etc/php-fpm.conf
sed -i '/run/s/;//g' /usr/local/php5/etc/php-fpm.conf
sed -i '/^ /d' /usr/local/php5/etc/php-fpm.conf
sed -i 's/nobody/nginx/g' /usr/local/php5/etc/php-fpm.conf
sed -i '/start/s/2/20/' /usr/local/php5/etc/php-fpm.conf
sed -i '/min/s/1/5/' /usr/local/php5/etc/php-fpm.conf
sed -i '/max_spare/s/3/25/' /usr/local/php5/etc/php-fpm.conf
sed -i '/max_children/s/5/35/' /usr/local/php5/etc/php-fpm.conf
/usr/local/sbin/php-fpm #启动php-fpm进程
#test nginx mysql php work tegether
sed -i '/\<user\>/a user nginx;' /usr/local/nginx/conf/nginx.conf #把user改为nginx用户
sed -i '/\<index\>/s/index.html index.htm/index.html index.htm index.php/g' /usr/local/nginx/conf/nginx.conf #添加支持index.php
#这下面的六句自己手动的添加到nginx的配置文件里面去/usr/local/nginx/conf/nginx.conf
# location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# include fastcgi.conf;
# }
cat >> /usr/local/nginx/html/test.php << EOF
<?php
$link=mysql_connect('localhost','root','123456');
if($link) echo "<h1>lian jie mysql cheng gong!!</h1>";
mysql_close();
?>
EOF
service nginx restart
#done all you can test lnmp http://ip(test nginx) or http://ip/test.php(test nginx with mysql php)
##############=========nginx and php-fpm Startup script##################
##############========= #!/bin/bash
##############========= # nginx and php-fpm Startup script for the Nginx HTTP Server
##############========= # chkconfig: – 85 15
##############========= nginxd=/usr/local/nginx/sbin/nginx
##############========= nginx_config=/usr/local/nginx/conf/nginx.conf
##############========= nginx_pid=/usr/local/nginx/logs/nginx.pid
##############========= php_fpm=/usr/local/sbin/php-fpm
##############========= php_fpm_config=/usr/local/php5/etc/php-fpm.conf
##############========= php_fpm_pid=/usr/local/php5/var/run/php-fpm.pid
##############========= RETVAL=0
##############========= prog="nginx"
##############========= prog1="php-fpm"
##############========= # Source function library.
##############========= . /etc/rc.d/init.d/functions
##############========= # Source networking configuration.
##############========= . /etc/sysconfig/network
##############========= # Check that networking is up.
##############========= [ ${NETWORKING} = "no" ] && exit 0
##############========= [ -x $nginxd ] || exit 0
##############========= # Start nginx daemons functions.
##############========= start() {
##############========= if [ -e $nginx_pid ];then
##############========= echo "nginx already running…."
##############========= exit 1
##############========= fi
##############========= echo -n $"Starting $prog: "
##############========= RETVAL=$?
##############========= echo
##############========= [ $RETVAL = 0 ] && touch /var/lock/subsys/nginx
##############========= return $RETVAL
##############========= }
##############========= # Stop nginx daemons functions.
##############========= stop() {
##############========= echo -n $"Stopping $prog: "
##############========= killproc $nginxd
##############========= RETVAL=$?
##############========= echo
##############========= [ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /usr/local/nginx/logs/nginx.pid
##############========= }
##############========= reload() {
##############========= echo -n $"Reloading $prog: "
##############========= #kill -HUP `cat ${nginx_pid}`
##############========= killproc $nginxd -HUP
##############========= RETVAL=$?
##############========= echo
##############========= }
##############========= # See how we were called.
##############========= case "$1" in
##############========= start)
##############========= start
##############========= $php_fpm -c $php_fpm_config
##############========= echo "starting $prog1:[ok]"
##############========= ;;
##############========= stop)
##############========= stop
##############========= echo $"Stopping $prog1:[ok]"
##############========= killproc $php_fpm
##############========= RETVAL=$?
##############========= ;;
##############========= reload)
##############========= reload
##############========= ;;
##############========= restart)
##############========= stop
##############========= echo $"Stopping $prog1:[ok] "
##############========= killproc $php_fpm
##############========= RETVAL=$?
##############========= start
##############========= $php_fpm -c $php_fpm_config
##############========= echo "starting $prog1:[ok]"
##############========= ;;
##############========= status)
##############========= status $prog
##############========= RETVAL=$?
##############========= ;;
##############========= *)
##############========= echo "Usage: $prog {start|stop|restart|reload|status|help}"
##############========= exit 1
##############========= esac
##############========= exit $RETVAL
#把这个改成启动脚本的方法:1.先在linux上面vim /etc/init.d/nginx
# 2.把以这个开头的且包括##############=========都copy到linux的/etc/init.d/nginx文件中
# 3.用sed命令去掉##############=========这些,然后剩下来的就是nginx和php-fpm的启动脚本了
# 4.用sed这样改 sed -i 's/##############========= //g' /etc/init.d/nginx 直接copy这句,因为要注意#=这个的个数
# 5.sed命令执行后,可以vim看一下,前面的那些已经去掉,然后加权限 chmod +x /etc/init.d/nginx
# 6.然后就可以用 service nginx {start|stop|restart}命令了,执行这个命令时php-fpm也跟着start stop restart
copy所有的内容到linux新建的文件中,然后给文件赋予权限,然后执行,自动执行,漫长的过程,
自己运行这个脚本是木有出错的

shell脚本之lnmp的搭建的更多相关文章

  1. shell 脚本实战笔记(5)--搭建资源的镜像服务器

    背景: 由于访问国外站点资源, 有时特别慢. 偶尔一次下载, 肯定还能忍受, 对于多次使用或者小团队内部使用, 搭建一个镜像站点, 无疑是个明智的决定. 这边以搭建CDH5的yum源镜像, 作为例子, ...

  2. Shell脚本一键安装LNMP环境

    https://sourceforge.net/projects/opensourcefile/files/ Nginx是一款高性能的HTTP和反向代理服务器.Nginx在反向代理,Rewrite规则 ...

  3. 一个自动安装LNMP的简洁Shell脚本

    此脚本在生产服务器上使用了一年多,本脚本崇尚简单唯美,只需要一个脚本就可以在任何一台有网络的服务器上自动配置LNMP.本脚本会在脚本执行目录下,建packages目录用于存放LNMP所需要的软件.大家 ...

  4. 利用shell脚本去备份幸运28源码搭建下载所指定的数据库

    #! /bin/bash幸运28源码搭建下载Q[115288oo99]logintool=/home/yx/server/mysql/mysql/bin/mysqldumptool=/home/yx/ ...

  5. 使用redis4.0.1和redis-cluster搭建集群并编写重启shell脚本

    1.删除机器上原有的redis2.8 关闭redis-server killall -9 redis-server 查找redis文件所在目录 which redis 删除相关文件 rm -rf re ...

  6. LNMP平台搭建---Nginx安装篇

    在上一篇博文<LNMP平台搭建---Linux系统安装篇>中,我们安装了CentOS版本的Linux操作系统,现在,我们来安装一个Web服务器,大标题写着LNMP,其中的N就是Nginx, ...

  7. 阿里云(ECS)Centos服务器LNMP环境搭建

    阿里云( ECS ) Centos7 服务器 LNMP 环境搭建 前言 第一次接触阿里云是大四的时候,当时在校外公司做兼职,关于智能家居项目的,话说当时俺就只有一个月左右的 php 后台开发经验(还是 ...

  8. 常用shell脚本

    [脚本1]打印形状打印等腰三角形.直角三角形.倒直角三角形.菱形 #!/bin/bash # 等腰三角形 read -p "Please input the length: " n ...

  9. 【转】干货分享-100个shell脚本

    本文用于记录学习和日常中使用过的shell脚本 [脚本1]打印形状 打印等腰三角形.直角三角形.倒直角三角形.菱形 #!/bin/bash # 等腰三角形 read -p "Please i ...

随机推荐

  1. Java Web项目里开发获取上个页面连接地址的问题

    近期做的项目有个问题,就是需要获取上个页面连接地址,我用的IE浏览器,在用location.href连接到新地址的时候,在新地址页面用document.referrer的方法获取不到原地址,我测试了下 ...

  2. POJ 3243 Clever Y(离散对数-拓展小步大步算法)

    Description Little Y finds there is a very interesting formula in mathematics: XY mod Z = K Given X, ...

  3. 事务——sql server中的事务应用举例

    sql中事务只针对一个update,delete,insert语句,如果一段程序中有超过一个这样的语句,就需要每个都判断是否出错,否则就会出现若干我们不希望的情形出现,举例如下(表结构见最后): 1, ...

  4. paper 93:OpenCV学习笔记大集锦

    整理了我所了解的有关OpenCV的学习笔记.原理分析.使用例程等相关的博文.排序不分先后,随机整理的.如果有好的资源,也欢迎介绍和分享. 1:OpenCV学习笔记 作者:CSDN数量:55篇博文网址: ...

  5. sql server 查询性能最差的sql语句

    SELECT TOP 10 TEXT AS 'SQL Statement' ,last_execution_time AS 'Last Execution Time' ,(total_logical_ ...

  6. FRM-92101解决办法

    /u02/UAT/inst/apps/UAT_newerp3/logs/ora/10.1.3/opmn/forms_default_group_1/ http://blog.csdn.net/orth ...

  7. 在desk于webi中资料查询不一致

    1,首先检查是否勾选重复列,重复列造成 2,缓存

  8. session_start()一些问题

    session问题集锦 对于PHP的session功能,始终找不到合适的答案,尤其是一些错误,还有一些没有错误的结果,最可怕的就是后者,一直为许多的初学者为难.就连有些老手,有时都被搞得莫名其妙.本文 ...

  9. hadoop之输入输出格式

    <STRONG>jobConf.setInputFormat(MyInputFormat. class ); InputFormat:</STRONG> TextInputFo ...

  10. OpenStack主机列表接口

    如之前讨论,openstack提供一套接口给运维管理平台,运维管理平台通过获取到的IP地址对主机进行监控. 接口名  请求地址  请求方法  请求cookie  请求头  返回值  返回值使用  登录 ...