salt源码安装nginx
今天周五,为了迎接美好的周末。下午写了些sls。希望可以愉快的度过一个完美的周末# pwd
/srv/salt
# tree nginx/
nginx/
├── conf.sls
├── files
│ ├── blog.conf
│ ├── nginx.conf
│ └── www.conf
├── init.sls
└── install.sls
1 directory, 6 files
# more nginx/init.sls
include:
- nginx.install
- nginx.conf
# more nginx/install.sls
nginx:
pkg.installed:
- names:
- gcc-c++
- pcre-devel
- zlib-devel
- openssl-devel
- libxslt-devel
- gd-devel
user.present:
- shell: /sbin/nologin
- uid: 1001
- gid_from_name: True
archive.extracted:
- name: /tmp/
- source: http://nginx.org/download/nginx-1.12.2.tar.gz
- skip_verify: True
cmd.run:
- cwd: /tmp/nginx-1.12.2/
- names:
- ./configure --prefix=/usr/local/nginx112 --user=nginx --group=nginx --with-http_stub_status_module --with-pcre--with-http_realip_module--with-htt
p_image_filter_module--with-http_ssl_module--with-http_gzip_static_module && make
- make install
- require:
- archive: nginx
# more nginx/conf.sls
master:
file.managed:
- name: /usr/local/nginx112/conf/nginx.conf
- source: salt://nginx/files/nginx.conf
- template: jinja
www:
file.managed:
- name: /usr/local/nginx112/conf.d/www.conf
- source: salt://nginx/files/www.conf
- makedirs: True
- require:
- file: master
blog:
file.managed:
- name: /usr/local/nginx112/conf.d/blog.conf
- source: salt://nginx/files/blog.conf
- makedirs: True
- require:
- file: master
# more nginx/files/nginx.conf
usernginx nignx;
worker_processes{{ grains['num_cpus'] }};
{% if grains['num_cpus'] == 2 %}
worker_cpu_affinity 10 01;
{% elif grains['num_cpus'] == 4 %}
worker_cpu_affinity 1000 0100 0010 0001;
{% elif grains['num_cpus'] >= 8 %}
worker_cpu_affinity 10000000 01000000 00100000 00010000 00001000 00000100 00000010 00000001;
{% else %}
worker_processes1;
{% endif %}
error_loglogs/error.log;
error_loglogs/error.lognotice;
worker_rlimit_nofile4096;
#pid logs/nginx.pid;
events {
use epoll;
worker_connections4096;
}
http {
include mime.types;
default_typeapplication/octet-stream;
log_formatmain'$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
sendfile on;
tcp_nopush on;
keepalive_timeout65;
include/usr/local/nginx1.10/conf.d/*.conf;
server {
listen 80;
server_namengx.status;
location /status {
stub_status on;
access_log off;
allow 192.168.199.0/24;
deny all;
}
error_page 404 /404.html;
location = /404.html {
root html;
}
}
}
# more nginx/files/www.conf
server {
listen 80;
server_name www.bjdaos.com bjdaos.com;
location / {
root html;
access_loglogs/www.access.log main;
index index.htmlindex.htm;
}
}
# more nginx/files/blog.conf
server {
listen 80;
server_name blog.bjdaos.com;
location / {
root html/word;
index index.php index.html index.htm;
}
}
最后:
salt '*' state.sls nginx
页:
[1]