您的位置:首页 > 博客中心 > 互联网 >

Ansible 使用roles安装服务

时间:2022-04-30 20:40

  • 创建所需要的目录

  • 新建tasks任务

  • 提供nginx的template文件

  • 提供vars的定义变量

  • 提供handlers配置文件

  • 查看/etc/ansible/hosts

  • 查看是否安装nginx

  • 运行前一定要检查,生产环境中

  • 运行,是正常OK的

  • 查看,发现端口不一样,是因为nginx.conf.j2配置模板引用了/etc/ansible/hosts中的nginx_prot变量

  • 修改nginx的work process运行用户为user5(remote必须有该账号)及修改为80端口并且指定tags定义的ngxconf运行,并触发handles

  • 验证,如我们所想的那样

  • [root@HA2 nginx]# ansible webserver -m shell -a "netstat -tunlp| grep nginx;echo "" ;ps aux| grep ‘nginx: worker process‘| grep -v grep"
    172.16.0.2 | SUCCESS | rc=0 >>
    tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      26856/nginx: master 
    
    user5     26857  0.0  0.7 124736  3500 ?        S    13:46   0:00 nginx: worker process
    user5     26858  0.0  0.7 124736  3500 ?        S    13:46   0:00 nginx: worker process
    172.16.0.4 | SUCCESS | rc=0 >>
    tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      27142/nginx: master 
    
    user5     27143  0.0  0.7 124736  3500 ?        S    13:46   0:00 nginx: worker process
    user5     27144  0.0  0.7 124736  3500 ?        S    13:46   0:00 nginx: worker process


    本文出自 “” 博客,请务必保留此出处

    本类排行

    今日推荐

    热门手游