ansible-roles之nginx
2021/8/7 7:09:33
本文主要是介绍ansible-roles之nginx,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
目录
1、建目录
2、tasks
3、handlers
4、files
5、templates
6、nginx_lb.yml
1、建目录
[root@zbx-server roles]# tree webservers/ webservers/ ├── files │ ├── installed_nginx.sh │ ├── nginx-1.18.0.tar.gz │ └── nginx.service ├── handlers │ └── main.yml ├── tasks │ ├── copy.yml │ ├── group.yml │ ├── main.yml │ ├── script.yml │ ├── template.yml │ ├── unarchive.yml │ ├── user.yml │ └── yum.yml ├── templates │ └── nginx.conf.j2 └── vars 5 directories, 13 files
2、tasks
1、 cat main.yml --- - include: group.yml - include: user.yml - include: unarchive.yml - include: yum.yml - include: script.yml - include: copy.yml - include: template.yml 2、cat group.yml - name: group www group: name=www system=yes 3、cat user.yml - name: user www user: name=www group=www system=yes shell=/sbin/nologin 4、 cat unarchive.yml - name: cp nginx.tar unarchive: src=/etc/ansible/roles/webservers/files/nginx-1.18.0.tar.gz dest=/opt 5、cat yum.yml - name: yum pcre-devel yum: name=pcre-devel state=installed - name: yum pcre-devel yum: name=zlib-devel state=installed - name: yum openssl-devel yum: name=openssl-devel state=installed - name: yum gcc yum: name=gcc state=installed - name: yum gcc-c++ yum: name=gcc-c++ state=installed 6、cat script.yml - name: script installed-nginx script: removes=/opt/nginx-1.18.0 /etc/ansible/roles/webservers/files/installed_nginx.sh 7、cat copy.yml - name: cp nginx.service copy: src=/etc/ansible/roles/webservers/files/nginx.service dest=/usr/lib/systemd/system/ - name: Refresh permissions shell: systemctl daemon-reload 8、cat template.yml - name: cp nginx.conf template: src=nginx.conf.j2 dest=/usr/local/nginx/conf/nginx.conf notify: restart nginx
3、handlers
1、 cat main.yml - name: restart nginx service: name=nginx state=restarted
4、files
1、cat installed_nginx.sh #!/bin/bash cd /opt/nginx-1.18.0 ./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module make && make install 2、cat nginx.service [Unit] Description=nginx After=network.target [Service] Type=forking ExecStart=/usr/local/nginx/sbin/nginx ExecReload=/usr/local/nginx/sbin/nginx -s reload ExecStop=/usr/local/nginx/sbin/nginx -s stop PrivateTmp=true [Install] WantedBy=multi-user.target 3、准备: nginx-1.18.0.tar.gz
5、templates
1、cat nginx.conf.j2 user www; worker_processes {{ ansible_processor_vcpus }}; events { accept_mutex on; #on可以work进程一起竞争一个请求链接请求多时可以关闭 multi_accept off; #off可以使一个work进程接多个请求 on是一个work接一个请求 worker_connections 1024; use epoll; } http { include mime.types; default_type application/octet-stream; sendfile on; #提高nginx处理静态资源的性能 keepalive_timeout 65; server { listen 80; server_name localhost; location / { root html; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } include conf.d/*.conf; }
6、nginx_lb.yml
1、[root@zbx-server roles]# ls nginx_lb.yml webservers 2、 cat nginx_lb.yml - name: installed nginx hosts: 192.168.0.3 roles: - webservers 3、ansible-playbook nginx_lb.yml
这篇关于ansible-roles之nginx的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-10-29Nginx发布学习:从入门到实践的简单教程
- 2024-10-28Nginx发布:新手入门教程
- 2024-10-21nginx 怎么设置文件上传最大20M限制-icode9专业技术文章分享
- 2024-10-17关闭 nginx的命令是什么?-icode9专业技术文章分享
- 2024-09-17Nginx实用篇:实现负载均衡、限流与动静分离
- 2024-08-21宝塔nginx新增8022端口方法步骤-icode9专业技术文章分享
- 2024-08-21nginx配置,让ws升级为wss访问的方法步骤-icode9专业技术文章分享
- 2024-08-15nginx ws代理配置方法步骤-icode9专业技术文章分享
- 2024-08-14nginx 让访问带有/relid的地址返回404 ,例子 /relid-x-0.36-y-131.html-icode9专业技术文章分享
- 2024-08-14nginx 判断地址有/statics/的路径,指向到/home/html/statics/目录-icode9专业技术文章分享