Automation
自动化
需要安装Puppet
class nginx {
package {"nginx": ensure => 'installed',} #确认Nginx已安装
service {"nginx":
ensure => 'true',
hasrestart => 'true', #确认开机自启
restart => '/etc/init.d/nginx reload', #重启Nginx
}
file { "nginx.conf":
path => '/etc/nginx/nginx.conf',
require => Package['nginx'],
notify => Service['nginx'],
content => template('nginx/templates/nginx.conf.erb'),
user=>'root',
group=>'root',
mode='0644';
}
}
Chef
安装Chef
package 'nginx' do
action :install
end
service 'nginx' do
supports :status => true, :restart => true, :reload => true
action [ :start, :enable ]
end
template 'nginx.conf' do
path "/etc/nginx.conf"
source "nginx.conf.erb"
owner 'root'
group 'root'
mode '0644'
notifies :reload, 'service[nginx]', :delayed
end
Ansible
安装Ansible
- name: NGINX | Installing NGINX
package: name=nginx state=present
- name: NGINX | Starting NGINX
service:
name: nginx
state: started
enabled: yes
- name: Copy nginx configuration in place.
template:
src: nginx.conf.j2
dest: "/etc/nginx/nginx.conf"
owner: root
group: root
mode: 0644
notify:
- reload nginx
SaltStack
安装SaltStack
nginx:
pkg:
- installed
service:
- name: nginx
- running
- enable: True
- reload: True
- watch:
- file: /etc/nginx/nginx.conf
/etc/nginx/nginx.conf:
file:
- managed
- source: salt://path/to/nginx.conf
- user: root
- group: root
- template: jinja
- mode: 644
- require:
- pkg: nginx
Consul Templating
这个压根没看懂,后续有时间可以了解一下
来源:oschina
链接:https://my.oschina.net/u/4255948/blog/4288065