Linux---centos6编译安装nginx1.8.1(附:安装脚本)

标签: nginxcentos

 3351人阅读 评论(0) 收藏 举报

centos6编译安装nginx1.8.1_linux nginx 分类:

Linux(28) centos6编译安装nginx1.8.1_linux nginx_02

目录(?)[+]

环境

系统环境:CentOS release 6.7 (Final)

需求

centos6.7编译安装nginx1.8.1

准备

安装依赖

yum install -y  gcc gcc-c++ autoconf automake zlib zlib-devel openssl openssl-devel pcre pcre-devel1

下载安装包

cd /opt/software1
#download nginxwget -c http://nginx.org/download/nginx-1.8.1.tar.gz#download pcrewget -c https://sourceforge.net/projects/pcre/files/pcre/8.35/pcre-8.35.tar.gz#download zlibwget -c http://zlib.net/zlib-1.2.8.tar.gz#download opensslwget -c http://www.openssl.org/source/openssl-1.0.1i.tar.gz123456789101112

解压包

tar zxvf nginx-1.8.1.tar.gztar zxvf pcre-8.35.tar.gztar zxvf zlib-1.2.8.tar.gztar zxvf openssl-1.0.1i.tar.gz1234567

添加用户

groupadd -r nginx

useradd -r -g nginx nginx123

编译安装

cd /opt/software/nginx-1.8.11
./configure \
--prefix=/opt/nginx \--user=nginx \--group=nginx \--with-http_ssl_module \--with-http_gzip_static_module \--with-http_stub_status_module \--with-http_realip_module \--pid-path=/var/run/nginx.pid \--with-pcre=/opt/software/pcre-8.35 \--with-zlib=/opt/software/zlib-1.2.8 \--with-openssl=/opt/software/openssl-1.0.1imake

make install && echo OK1234567891011121314151617

启动nginx

正确性检查

#每次修改nginx配置文件后都要进行检查/opt/nginx/sbin/nginx -t123

centos6编译安装nginx1.8.1_linux nginx_03

启动nginx

/opt/nginx/sbin/nginx1

reload nginx

/opt/nginx/sbin/nginx -s reload1

一键安装脚本

将以上步骤整合到一个脚本中来编译安装nginx

vim nginx1.8.sh1
#!/bin/bash#install nginx-1.8.1#安装目录INSTALL_DIR=/opt/
SRC_DIR=/opt/software

[ ! -d ${INSTALL_DIR} ] && mkdir -p ${INSTALL_DIR}[ ! -d ${SRC_DIR} ] && mkdir -p ${SRC_DIR}# Check if user is rootif [ $(id -u) != "0" ]; then
    echo "Error: You must be root to run this script!!"
    exit 1fi#安装依赖包for Package in wget gcc gcc-c++ autoconf automake zlib zlib-devel openssl openssl-devel pcre pcre-develdo
    yum -y install $PackagedoneInstall_Nginx()
{#更新版本信息NGINX="nginx-1.8.1"PCRE="pcre-8.35"ZLIB="zlib-1.2.8"OPENSSL="openssl-1.0.1i"NGINXFEATURES="--prefix=${INSTALL_DIR}nginx \
--user=nginx \
--group=nginx \
--with-http_ssl_module \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--with-http_realip_module \
--pid-path=/var/run/nginx.pid \
--with-pcre=${SRC_DIR}/${PCRE} \
--with-zlib=${SRC_DIR}/${ZLIB} \
--with-openssl=${SRC_DIR}/${OPENSSL}"cd ${SRC_DIR}#下载所需安装包echo 'Downloading NGINX'if [ ! -f ${NGINX}.tar.gz ]then
  wget -c http://nginx.org/download/${NGINX}.tar.gzelse
  echo 'Skipping: NGINX already downloaded'fiecho 'Downloading PCRE'if [ ! -f ${PCRE}.tar.gz ]then
  wget -c https://sourceforge.net/projects/pcre/files/pcre/8.35/${PCRE}.tar.gzelse
  echo 'Skipping: PCRE already downloaded'fiecho 'Downloading ZLIB'if [ ! -f ${ZLIB}.tar.gz ]then
  wget -c http://zlib.net/${ZLIB}.tar.gzelse
  echo 'Skipping: ZLIB already downloaded'fiecho 'Downloading OPENSSL'if [ ! -f ${OPENSSL}.tar.gz ]then
  wget -c http://www.openssl.org/source/${OPENSSL}.tar.gzelse
  echo 'Skipping: OPENSSL already downloaded'fiecho '----------Unpacking downloaded archives. This process may take serveral minutes---------'echo "Extracting ${NGINX}..."tar xzf ${NGINX}.tar.gzecho 'Done.'echo "Extracting ${PCRE}..."tar xzf ${PCRE}.tar.gzecho 'Done.'echo "Extracting ${ZLIB}..."tar xzf ${ZLIB}.tar.gzecho 'Done.'echo "Extracting ${OPENSSL}..."tar xzf ${OPENSSL}.tar.gzecho 'Done.'#添加用户groupadd -r nginx
useradd -r -g nginx nginx#编译echo '###################'echo 'Compile NGINX'echo '###################'cd ${SRC_DIR}/${NGINX}./configure ${NGINXFEATURES}make
make installcd ../

mkdir -p ${INSTALL_DIR}/nginx/conf/vhosts

}

Install_Nginx123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115

安装方式: 
可将需下载的安装包一起上传至/opt/software后加快安装进度

在/opt/software中执行安装脚本 
centos6编译安装nginx1.8.1_linux nginx_04

注意:如果将脚本复制到linux下,可能存在格式问题,通过 :set ff=unix 解决