自動化部署達到以下幾個目的:
1.編譯
2.安裝
3.生成HTTPS 證書
4.配置
5.設置Ubuntu 服務
首先將Nginx的壓縮包解壓並放在工程目錄下,然後將要准備的的配置文件放在conf目錄下,還有作為service需要的啟動腳本文件nginx
目錄結構如下:
- # tree -L 2
- tree -L 2
- .
- ├── conf
- │ ├── agol.conf
- │ └── nginx.conf
- ├── install.sh
- ├── install.sh~
- ├── nginx
- └── nginx-1.2.3
- ├── auto
- ├── CHANGES
- ├── CHANGES.ru
- ├── conf
- ├── configure
- ├── contrib
- ├── html
- ├── LICENSE
- ├── man
- ├── README
- └── src
-
- 8 directories, 10 files
現在看一下install.sh腳本內容:
- #!/bin/bash
-
- source ../common/tool.sh
-
- installDpkg "libpcre3"
- installDpkg "libpcre3-dev"
- installDpkg "libssl-dev"
- installDpkg "openssl"
-
- cd ./nginx-1.2.3
- ./configure --prefix=/usr/nginx --with-http_ssl_module
- make
- make install
-
- cd ../
-
- cp ./nginx /etc/init.d/
- update-rc.d nginx defaults
-
- cp -r ./conf/* /usr/nginx/conf/
-
- #generate ssl certificate-begin
- cd /usr/nginx/conf
- openssl genrsa -des3 -out server.key -passout pass:freebird 1024
- openssl req -new -key server.key -out server.csr -passin pass:freebird -batch
- cp server.key server.key.org
- openssl rsa -in server.key.org -out server.key -passin pass:freebird
- openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
-
- cd -
- #generate ssl certificate-end
-
- service nginx start
-
- cd ./nginx-1.2.3
- make clean
這裡要關注的是生成證書的時候使用批處理方式
openssl genrsa 命令用到 -passout pass:freebird 避免提示輸入口令
openssl req 命令用到 -passin pass:freebird -batch 提供口令,避免輸入一堆其他信息
openssl rsa 命令也用到 -passin pass:freebird 提供口令
nginx啟動腳本參考我的另一篇文章:http://www.linuxidc.com/Linux/2011-09/42144.htm