自動化部署達到以下幾個目的:
1.編譯
2.安裝
3.產生HTTPS 認證
4.配置
5.設定Ubuntu 服務
首先將Nginx的壓縮包解壓並放在工程目錄下,然後將要準備的的設定檔放在conf目錄下,還有作為service需要的啟動指令檔nginx
目錄結構如下:
# tree -L 2tree -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 └── src8 directories, 10 files
現在看一下install.sh指令碼內容:
#!/bin/bash source ../common/tool.shinstallDpkg "libpcre3"installDpkg "libpcre3-dev"installDpkg "libssl-dev"installDpkg "openssl"cd ./nginx-1.2.3./configure --prefix=/usr/nginx --with-http_ssl_modulemakemake installcd ../cp ./nginx /etc/init.d/update-rc.d nginx defaultscp -r ./conf/* /usr/nginx/conf/#generate ssl certificate-begincd /usr/nginx/confopenssl genrsa -des3 -out server.key -passout pass:freebird 1024openssl req -new -key server.key -out server.csr -passin pass:freebird -batchcp server.key server.key.orgopenssl rsa -in server.key.org -out server.key -passin pass:freebirdopenssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crtcd -#generate ssl certificate-endservice nginx startcd ./nginx-1.2.3make clean
這裡要關注的是產生認證的時候使用批處理方式
openssl genrsa 命令用到 -passout pass:freebird 避免提示輸入口令
openssl req 命令用到 -passin pass:freebird -batch 提供口令,避免輸入一堆其他資訊
openssl rsa 命令也用到 -passin pass:freebird 提供口令
nginx啟動指令碼參考我的另一篇文章:
http://blog.csdn.net/sheismylife/article/details/6744394