`
xinlanzero
  • 浏览: 245779 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

Install Nginx On Amazon EC2

 
阅读更多

This guide can be used in the case we need to run Nginx on Amazon due to a bug that affects the EPEL package repository and maybe some other repository.

That’s why I leave this “Step by Step” to compile and build the RPM for CentOS and RHEL. It is functional in Amazon EC2 instances.


The first thing you need to do is to install the “checkinstall” to generate the RPM.
If you’re going to do it on a 32bit system just do the following:

 

yum install checkinstall

To do that we have to have the RPMforge Repository in our system.


If we have a 64 bits system we are going to need to download the checkinstall 32bits RPM using the following link, and install it:

wget http://packages.sw.be/checkinstall/checkinstall-1.6.0-3.el5.rf.i386.rpm
rpm -Uvh checkinstall-1.6.0-3.el5.rf.i386.rpm

Then install the needed RPM packages to compile Nginx:

yum install rpm-devel rpm-build openssl-devel zlib-devel pcre pcre-devel gcc make

Now we have to download the Nginx code and generate the RPM:

mkdir -p /root/src
cd /root/src
wget http://nginx.org/download/nginx-0.8.54.tar.gz
tar xzf nginx-0.8.54.tar.gz
cd nginx-0.8.54

We are now ready to compile and generate the RPM:

./configure --conf-path=/etc/nginx/nginx.conf --sbin-path=/usr/sbin/  --prefix=/usr/share/nginx --error-log-path=/var/log/nginx/error.log --pid-path=/var/run/nginx.pid
 
make
 
checkinstall --fstrans=no

We need to follow the steps asked by checkinstall and then install the generated RPM.
Finally we have to copy and paste in a file to add to “init.d” and then be able to run it as any service.
By the end of this “Step by Step” there is an example of how to do it.
As a last step we only have to start it like a normal service.

vim /etc/init.d/nginx  # Paste here the example named "Example to start service"
/etc/init.d/nginx start

I hope this to be usefull for you. If we want to use, for example, PHP 5.2 we can download PHP and Nginx compatible with Amazon Kernel(Xen Kernel) from the CentosALT Repository.

Example to start service.

#!/bin/sh
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig:   - 85 15
# description:  Nginx is an HTTP(S) server, HTTP(S) reverse \
#               proxy and IMAP/POP3 proxy server
# processname: nginx
# config:      /etc/nginx/nginx.conf
# config:      /etc/sysconfig/nginx
# pidfile:     /var/run/nginx.pid
 
# Source function library.
. /etc/rc.d/init.d/functions
 
# Source networking configuration.
. /etc/sysconfig/network
 
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
 
nginx="/usr/sbin/nginx"
prog=$(basename $nginx)
 
NGINX_CONF_FILE="/etc/nginx/nginx.conf"
 
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
 
lockfile=/var/lock/subsys/nginx
 
start() {
    [ -x $nginx ] || exit 5
    [ -f $NGINX_CONF_FILE ] || exit 6
    echo -n $"Starting $prog: "
    daemon $nginx -c $NGINX_CONF_FILE
    retval=$?
    echo
    [ $retval -eq 0 ] && touch $lockfile
    return $retval
}
 
stop() {
    echo -n $"Stopping $prog: "
    killproc $prog
    retval=$?
    echo
    [ $retval -eq 0 ] && rm -f $lockfile
    return $retval
}
 
restart() {
    configtest_q || configtest || return 6
    stop
    start
}
 
reload() {
    configtest_q || configtest || return 6
    echo -n $"Reloading $prog: "
    killproc $nginx -HUP
    echo
}
 
configtest() {
  $nginx -t -c $NGINX_CONF_FILE
}
 
configtest_q() {
    configtest >/dev/null 2>&1
}
 
rh_status() {
    status $prog
}
 
rh_status_q() {
    rh_status >/dev/null 2>&1
}
 
# Upgrade the binary with no downtime.
upgrade() {
    local pidfile="/var/run/${prog}.pid"
    local oldbin_pidfile="${pidfile}.oldbin"
 
    configtest_q || configtest || return 6
    echo -n $"Staring new master $prog: "
    killproc $nginx -USR2
    retval=$?
    echo 
    sleep 1
    if [[ -f ${oldbin_pidfile} && -f ${pidfile} ]];  then
        echo -n $"Graceful shutdown of old $prog: "
        killproc -p ${oldbin_pidfile} -QUIT
        retval=$?
        echo 
        return 0
    else
        echo $"Something bad happened, manual intervention required, maybe restart?"
        return 1
    fi
}
 
case "$1" in
    start)
        rh_status_q && exit 0
        $1
        ;;
    stop)
        rh_status_q || exit 0
        $1
        ;;
    restart|configtest)
        $1
        ;;
    force-reload|upgrade) 
        rh_status_q || exit 7
        upgrade
        ;;
    reload)
        rh_status_q || exit 7
        $1
        ;;
    status|status_q)
        rh_$1
        ;;
    condrestart|try-restart)
        rh_status_q || exit 7
        restart
	    ;;
    *)
        echo $"Usage: $0 {start|stop|reload|configtest|status|force-reload|upgrade|restart}"
        exit 2
esac

Source: Netman Blog

Tags: amazon apache centos checkinstall config ec2 EPEL nginx rhel rpmforge Server

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics