歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> bash 腳本編程十九 Nginx自動部署

bash 腳本編程十九 Nginx自動部署

日期:2017/3/1 10:09:16   编辑:Linux編程

自動化部署達到以下幾個目的:

1.編譯

2.安裝

3.生成HTTPS 證書

4.配置

5.設置Ubuntu 服務

首先將Nginx的壓縮包解壓並放在工程目錄下,然後將要准備的的配置文件放在conf目錄下,還有作為service需要的啟動腳本文件nginx

目錄結構如下:

  1. # tree -L 2
  2. tree -L 2
  3. .
  4. ├── conf
  5. │ ├── agol.conf
  6. │ └── nginx.conf
  7. ├── install.sh
  8. ├── install.sh~
  9. ├── nginx
  10. └── nginx-1.2.3
  11. ├── auto
  12. ├── CHANGES
  13. ├── CHANGES.ru
  14. ├── conf
  15. ├── configure
  16. ├── contrib
  17. ├── html
  18. ├── LICENSE
  19. ├── man
  20. ├── README
  21. └── src
  22. 8 directories, 10 files
現在看一下install.sh腳本內容:
  1. #!/bin/bash
  2. source ../common/tool.sh
  3. installDpkg "libpcre3"
  4. installDpkg "libpcre3-dev"
  5. installDpkg "libssl-dev"
  6. installDpkg "openssl"
  7. cd ./nginx-1.2.3
  8. ./configure --prefix=/usr/nginx --with-http_ssl_module
  9. make
  10. make install
  11. cd ../
  12. cp ./nginx /etc/init.d/
  13. update-rc.d nginx defaults
  14. cp -r ./conf/* /usr/nginx/conf/
  15. #generate ssl certificate-begin
  16. cd /usr/nginx/conf
  17. openssl genrsa -des3 -out server.key -passout pass:freebird 1024
  18. openssl req -new -key server.key -out server.csr -passin pass:freebird -batch
  19. cp server.key server.key.org
  20. openssl rsa -in server.key.org -out server.key -passin pass:freebird
  21. openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
  22. cd -
  23. #generate ssl certificate-end
  24. service nginx start
  25. cd ./nginx-1.2.3
  26. 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

Copyright © Linux教程網 All Rights Reserved