欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 健康 > 养生 > ansible一键安装nginx二进制版本

ansible一键安装nginx二进制版本

2025/1/22 8:36:26 来源:https://blog.csdn.net/weixin_66575196/article/details/145278925  浏览:    关键词:ansible一键安装nginx二进制版本

公司需求需要批量部署nginx,闲来无事,改进了原先手动部署的方式,写了一个ansible-playbook

- hosts: webgather_facts: yesvars:ansible_ssh_common_args: '-o StrictHostKeyChecking=no'tasks:- name: add groupgroup:name: nginxstate: present- name: add useruser:name: nginxstate: presentgroup: nginxshell: /sbin/nologin- name: check pathstat:path: /usr/local/nginxregister: file_stat- name: unarchiveunarchive:src: /etc/ansible/files/nginx/nginx.tar.gzdest: /usr/local/owner: nginxgroup: nginxwhen: file_stat.stat.exists == False- name: check pathstat:path: /apps/nginx/confregister: file_stat_nginx- name: compile and installshell:cmd: "./configure --prefix=/apps/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre --with-stream --with-stream_ssl_module --with-stream_realip_module &&  make && make install"chdir: "/usr/local/nginx"when: file_stat_nginx.stat.exists == False- name: chownshell:cmd: "chown -R  nginx.nginx /apps/nginx && ln -sv /apps/nginx/sbin/nginx /usr/sbin/nginx"ignore_errors: yes- name: mkdir  pidfile:path: /apps/nginx/runstate: directoryowner: nginxgroup: nginxrecurse: yes- name: conf filetemplate:src: /etc/ansible/files/nginx/nginx.confdest: /apps/nginx/conf/nginx.confowner: nginxgroup: nginx- name: mkdir  pidfile:path: /apps/nginx/conf.dstate: directoryowner: nginxgroup: nginxrecurse: yes- name: conf.d  filetemplate:src: /etc/ansible/files/nginx/bbs.com.confdest: /apps/nginx/conf.d/bbs.com.confowner: nginxgroup: nginx- name: service filetemplate:src: /etc/ansible/files/nginx/nginx.servicedest: /lib/systemd/system/nginx.servicechanged_when: False- name: start nginxservice:name: nginxstate: restartedenabled: yes

附加文件

bbs.com.conf

[root@devops nginx]#cat bbs.com.conf
server {listen       80;server_name  bbs.com;root /apps/nginx/html;
}[root@devops nginx]#cat nginx.conf
worker_processes  1;
pid        /apps/nginx/run/nginx.pid;
events {worker_connections  1024;
}
http {include       mime.types;default_type  application/octet-stream;sendfile        on;keepalive_timeout  65;include /apps/nginx/conf.d/*.conf;
}

添加service文件,方便后续管理

[root@devops nginx]#cat nginx.service
[Unit]
Description=The nginx HTTP and reverse proxy server
After=network.target remote-fs.target nss-lookup.target[Service]
Type=forking
PIDFile=/apps/nginx/run/nginx.pid
ExecStart=/apps/nginx/sbin/nginx -c /apps/nginx/conf/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID
LimitNOFILE=10000[Install]
WantedBy=multi-user.targe

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com