通过乘客自动安装nginx

时间:2013-05-28 15:55:08

标签: ruby nginx passenger

每次我们使用乘客重新安装nginx时,我们必须提供一系列选项来定义我们想要激活的路径,模块和选项,这可能会有点痛苦。

有人知道使用某种答案文件自动执行此操作的方法吗?

3 个答案:

答案 0 :(得分:3)

是的,您可以使用像Chef或Puppet这样的配置工具,但在某些情况下,这些工具可能过度。我只有一个Bash脚本,顶部有一些变量可以根据需要进行更改,然后我只需将脚本传输到目标服务器并执行它。

nginx&的实际包我保留在自己的S3桶里。

#!/bin/sh

# setup download location
DOWNLOAD_DIR=/tmp
NGINX="nginx-1.4.1"
NGINX_DIR=${DOWNLOAD_DIR}/${NGINX}
PASSENGER_VERSION="4.0.3"
S3HOST="your-s3-host"

# download nginx source
curl http://${S3HOST}.s3.amazonaws.com/software/${NGINX}.tar.gz -o $DOWNLOAD_DIR/${NGINX}.tar.gz
tar xzf $DOWNLOAD_DIR/${NGINX}.tar.gz --directory $DOWNLOAD_DIR

# download headers module
curl http://${S3HOST}.s3.amazonaws.com/software/headers-more-nginx-module-v0.16.zip -o $DOWNLOAD_DIR/headers-more-nginx-module-v0.16.zip
unzip $DOWNLOAD_DIR/headers-more-nginx-module-v0.16.zip -d $DOWNLOAD_DIR

# install passenger
apt-get install -y gcc g++ build-essential bison openssl libreadline6 lsof
apt-get install -y libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libpcre3-dev
apt-get install -y libyaml-dev libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev libcurl4-openssl-dev
apt-get install -y default-jre python-software-properties imagemagick

apt-get install -y ruby1.9.3 ruby1.9.1-dev libruby1.9.1 rubygems1.9.1 irb1.9.1 ri1.9.1 rdoc1.9.1 s3cmd


ln -nfs /var/lib/gems/1.9.1/bin/* /usr/bin/
gem install passenger -v ${PASSENGER_VERSION} --no-ri --no-rdoc
gem install bundler sass --no-ri --no-rdoc

# postgres client libraries
aptitude install software-properties-common -y
add-apt-repository -y ppa:pitti/postgresql
apt-get update

apt-get install -y postgresql-client-9.2 postgresql-server-dev-9.2

wget http://${S3HOST}.s3.amazonaws.com/software/passenger-enterprise-server-${PASSENGER_VERSION}.gem
gem install ./passenger-enterprise-server-${PASSENGER_VERSION}.gem --no-ri --no-rdoc
/var/lib/gems/1.9.1/gems/passenger-enterprise-server-${PASSENGER_VERSION}/bin/passenger-install-nginx-module \
--auto --prefix=/usr --nginx-source-dir=${NGINX_DIR} \
--extra-configure-flags="--conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --pid-path=/var/run/nginx.pid --http-client-body-temp-path=/var/tmp/nginx/client --http-proxy-temp-path=/var/tmp/nginx/proxy --http-fastcgi-temp-path=/var/tmp/nginx/fastcgi --with-md5-asm --with-md5=/usr/include --with-sha1-asm --with-sha1=/usr/include --without-http_fastcgi_module --with-http_stub_status_module --with-http_ssl_module --add-module=${DOWNLOAD_DIR}/headers-more-nginx-module-v0.16"

# make proper folders
mkdir -p /etc/nginx/sites-enabled
mkdir -p /etc/nginx/conf.d
mkdir -p /var/tmp/nginx
mkdir -p /etc/nginx/ssl/rapidssl
mkdir -p /var/www/shared/log/old_logs
chown -R vino:vino /var/www

# cleanup the stupid files
rm /etc/nginx/*.default

# start from init script
update-rc.d nginx defaults

# cleanup
rm -rf $DOWNLOAD_DIR/nginx*

答案 1 :(得分:2)

passenger-install-apache2-module通过命令行选项支持非交互式,自动,无头安装或升级。您可以使用这些选项自动化答案。这在手册中有记录:http://www.modrails.com/documentation/Users%20guide%20Nginx.html#_non_interactive_automatic_headless_installs_or_upgrades

或者,您可以安装Phusion Passenger,就像它是一个普通的Nginx模块一样,并使用正常的Nginx安装自动化脚本:http://www.modrails.com/documentation/Users%20guide%20Nginx.html#_installing_as_a_normal_nginx_module_without_using_the_installer

答案 2 :(得分:1)

您可以使用chefpuppet等配置工具。单独使用它本身可能有点过分,但您可以使用它从头开始准备整个服务器或工作站。