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

来源:互联网 发布:淘宝子账号如何登陆 编辑:程序博客网 时间:2024/05/22 03:09

环境

系统环境: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-devel

下载安装包

cd /opt/software
#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.gz

解压包

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

添加用户

groupadd -r nginxuseradd -r -g nginx nginx

编译安装

cd /opt/software/nginx-1.8.1
./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.1imakemake install && echo OK

启动nginx

正确性检查

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

这里写图片描述

启动nginx

/opt/nginx/sbin/nginx

reload nginx

/opt/nginx/sbin/nginx -s reload

一键安装脚本

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

vim nginx1.8.sh
#!/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 nginxuseradd -r -g nginx nginx#编译echo '###################'echo 'Compile NGINX'echo '###################'cd ${SRC_DIR}/${NGINX}./configure ${NGINXFEATURES}makemake installcd ../mkdir -p ${INSTALL_DIR}/nginx/conf/vhosts}Install_Nginx

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

在/opt/software中执行安装脚本
这里写图片描述

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

0 0
原创粉丝点击