Rumah > pembangunan bahagian belakang > tutorial php > ansible自动化远程编译启动nginx

ansible自动化远程编译启动nginx

不言
Lepaskan: 2023-03-29 15:38:02
asal
1504 orang telah melayarinya

这篇文章主要介绍了关于ansible自动化远程编译启动nginx,有着一定的参考价值,现在分享给大家,有需要的朋友可以参考一下

环境:rhel7.3  
软件:

[root@server11 ~]# ansible --versionansible 2.5.3
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.5 (default, Aug  2 2016, 04:20:16) [GCC 4.8.5 20150623 (Red Hat 4.8.5-4)]
Salin selepas log masuk

ssh 免密

[root@server11 ansible]# ssh-keygen[root@server11 ansible]# ssh-copy-id 192.168.122.12
Salin selepas log masuk

文件目录结构

[root@server11 ansible]# tree.
├── ansible.cfg├── hosts
├── nginx.yaml└── roles
    └── nginx
        ├── default
        ├── files
        │   └── nginx-1.13.6.tar.gz
        ├── handlers
        ├── meta
        ├── tasks
        │   └── main.yml
        ├── templates
        │   ├── nginx.conf
        │   └── nginx.service
        └── vars
            └── main.yml9 directories, 8 files
Salin selepas log masuk

roles/nginx/tasks/main.yml

[root@server11 ansible]# cat roles/nginx/tasks/main.yml - name: copy package  
  copy: src=nginx-1.13.6.tar.gz dest=/usr/local/src/nginx-1.13.6.tar.gz  
  tags: cppkg  

- name: tar nginx  
  shell: cd /usr/local/src;tar -xf nginx-1.13.6.tar.gz  

- name: yum install  
  yum: name={{ item }} state=latest  
  with_items:  
    - openssl-devel  
    - pcre-devel  
    - gcc  

- name: install nginx  
  shell: useradd nginx;cd /usr/local/src/nginx-1.13.6;./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_flv_module --with-http_stub_status_module --with-http_gzip_static_module  --with-pcre;make && make install  - name: copy conf file  
  template: src=nginx.conf dest=/usr/local/nginx/conf/nginx.conf  

- name: systemctl init  
  template: src=nginx.service dest=/usr/lib/systemd/system/nginx.service  

- name: start nginx service  
  service: name=nginx state=started enabled=true
Salin selepas log masuk

roles/nginx/templates/nginx.conf

[root@server11 ansible]# cat roles/nginx/templates/nginx.conf user  nginx;  
worker_processes  {{ ansible_processor_vcpus }};  

#error_log  logs/error.log;  #error_log  logs/error.log  notice;  #error_log  logs/error.log  info;  #pid        logs/nginx.pid;  events {  
    worker_connections  65535;  
}  


http {  
    include       mime.types;  
    default_type  application/octet-stream;  

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '  
    #                  '$status $body_bytes_sent "$http_referer" '  
    #                  '"$http_user_agent" "$http_x_forwarded_for"';  

    #access_log  logs/access.log  main;  

    sendfile        on;  
    #tcp_nopush     on;  

    #keepalive_timeout  0;  
    keepalive_timeout  65;  

    #gzip  on;  

    server {  
        listen       {{ nginxport }};  
        server_name  localhost;  

        #charset koi8-r;  

        #access_log  logs/host.access.log  main;  

        location / {  
            root   html;  
            index  index.html index.htm;  
        }  

        #error_page  404              /404.html;  

        # redirect server error pages to the static page /50x.html  
        #  
        error_page   500 502 503 504  /50x.html;  
        location = /50x.html {  
            root   html;  
        }  

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80  
        #  
        #location ~ \.php$ {  
        #    proxy_pass   http://127.0.0.1;  
        #}  

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000  
        #  
        #location ~ \.php$ {  
        #    root           html;  
        #    fastcgi_pass   127.0.0.1:9000;  
        #    fastcgi_index  index.php;  
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;  
        #    include        fastcgi_params;  
        #}  

        # deny access to .htaccess files, if Apache's document root  
        # concurs with nginx's one  
        #  
        #location ~ /\.ht {  
        #    deny  all;  
        #}  
    }  


    # another virtual host using mix of IP-, name-, and port-based configuration  
    #  
    #server {  
    #    listen       8000;  
    #    listen       somename:8080;  
    #    server_name  somename  alias  another.alias;  

    #    location / {  
    #        root   html;  
    #        index  index.html index.htm;  
    #    }  
    #}  


    # HTTPS server  
    #  
    #server {  
    #    listen       443 ssl;  
    #    server_name  localhost;  

    #    ssl_certificate      cert.pem;  
    #    ssl_certificate_key  cert.key;  

    #    ssl_session_cache    shared:SSL:1m;  
    #    ssl_session_timeout  5m;  

    #    ssl_ciphers  HIGH:!aNULL:!MD5;  
    #    ssl_prefer_server_ciphers  on;  

    #    location / {  
    #        root   html;  
    #        index  index.html index.htm;  
    #    }  
    #}  }
Salin selepas log masuk

roles/nginx/templates/nginx.service

[root@server11 ansible]# cat roles/nginx/templates/nginx.service [Unit]  
Description=The nginx HTTP and reverse proxy server  
After=network.target remote-fs.target nss-lookup.target  

[Service]  
Type=forking  
PIDFile=/usr/local/nginx/logs/nginx.pid  
ExecStartPre=/usr/bin/rm -f /run/nginx.pid  
ExecStartPre=/usr/local/nginx/sbin/nginx -t  
ExecStart=/usr/local/nginx/sbin/nginx  
ExecReload=/bin/kill -s HUP $MAINPID  
KillMode=process  
KillSignal=SIGQUIT  
TimeoutStopSec=5  
PrivateTmp=true  

[Install]  
WantedBy=multi-user.target
Salin selepas log masuk

roles/nginx/vars/main.yml

[root@server11 ansible]# cat roles/nginx/vars/main.yml nginxport: "80"  server_name: "192.168.122.12"  root_dir: "/web"
Salin selepas log masuk

nginx.yaml

[root@server11 ansible]# cat nginx.yaml 
- hosts: 192.168.122.12  remote_user: root  
  roles:  
  - nginx
Salin selepas log masuk

相关推荐:

ansible api实现命令异步执行

Atas ialah kandungan terperinci ansible自动化远程编译启动nginx. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!

Label berkaitan:
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Artikel terbaru oleh pengarang
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan