本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
範本
重要
該 AWS OpsWorks Stacks 服務於 2024 年 5 月 26 日終止使用壽命,並已針對新客戶和現有客戶停用。我們強烈建議客戶盡快將其工作負載移轉至其他解決方案。如果您對移轉有任何疑問,請透過 AWS Re: post
您可以建立組態檔案並將其放在適當的目錄中,以設定許多套件。您可以在技術指南中加入組態檔案,並將其複製到適當的目錄中,但更靈活的方法是使用配方以透過範本建立組態檔。範本的其中一個優點是,您可以使用屬性來定義範本的值。如此一來,您就可以使用自訂 JSON 覆寫適當的屬性值以修改組態檔案,而無需動用到技術指南。
基本上,範本的內容和結構與其相關聯的檔案相同。下列 httpd.conf
即為範例檔。
ServerRoot "<%= node[:apache][:dir] %>" <% if node[:platform] == "debian" || node[:platform] == "ubuntu" -%> LockFile /var/lock/apache2/accept.lock <% else -%> LockFile logs/accept.lock <% end -%> PidFile <%= node[:apache][:pid_file] %> Timeout <%= node[:apache][:timeout] %> KeepAlive <%= node[:apache][:keepalive] %> MaxKeepAliveRequests <%= node[:apache][:keepaliverequests] %> KeepAliveTimeout <%= node[:apache][:keepalivetimeout] %> <IfModule mpm_prefork_module> StartServers <%= node[:apache][:prefork][:startservers] %> MinSpareServers <%= node[:apache][:prefork][:minspareservers] %> MaxSpareServers <%= node[:apache][:prefork][:maxspareservers] %> ServerLimit <%= node[:apache][:prefork][:serverlimit] %> MaxClients <%= node[:apache][:prefork][:maxclients] %> MaxRequestsPerChild <%= node[:apache][:prefork][:maxrequestsperchild] %> </IfModule> ...
下列範例是針對 Ubuntu 執行個體產生的 httpd.conf
檔案:
ServerRoot "/etc/httpd" LockFile logs/accept.lock PidFile /var/run/httpd/httpd.pid Timeout 120 KeepAlive Off MaxKeepAliveRequests 100 KeepAliveTimeout 3 <IfModule mpm_prefork_module> StartServers 16 MinSpareServers 16 MaxSpareServers 32 ServerLimit 400 MaxClients 400 MaxRequestsPerChild 10000 </IfModule> ...
範本的許多文字都是從範本複製到 httpd.conf
檔案。不過,<%= ... %>
內容的處理方式則如下所示:
-
Chef 會將
<%= node[:attribute][:sub_attribute][:...]%>
取代為屬性值。例如,
StartServers <%= node[:apache][:prefork][:startservers] %>
會變成httpd.conf
中的StartServers 16
。 -
您可以使用
<%if-%>, <%else-%>, and <%end-%>
依條件選取值。此範例會根據平台設定不同的
accept.lock
檔案路徑。
注意
如需範本的詳細資訊,包括如何採用 Ruby 程式碼,請參閱關於範本