Ansible自动化安装Nginx

我的配置:

/etc/hosts:

Ansible自动化安装Nginx

/etc/ansible/hosts:

Ansible自动化安装Nginx

 nglinx安装包:

Ansible自动化安装Nginx


ansible自动化安装nginx:

1.安装ansible。

2.创建目录结构:

mkdir -p /ansible/roles/nginx/{defaults,files,handlers,meta,tasks,templates,vars}

Ansible自动化安装Nginx

3.install_nginx.sh:

#!/bin/bash 
yum -y install zlib zlib-devel openssl openssl-devel pcre-devel
groupadd -r nginx
useradd -s /sbin/nologin -g nginx -r nginx
cd /tmp
tar xf nginx-1.9.9.tar.gz;cd nginx-1.9.9
mkdir /var/run/nginx/;chown nginx.nginx /var/run/nginx/
./configure \
--prefix=/usr \
--sbin-path=/usr/sbin/nginx \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--pid-path=/var/run/nginx/nginx.pid \
--user=nginx \
--group=nginx \
--with-http_ssl_module
make && make install
sed  "/^\s*index / i proxy_pass http://localhost:8080;" /etc/nginx/nginx.conf
/usr/sbin/nginx 
sed

 4.main.yml:

- name: copy nginx_tar_gz to client
  copy: src=nginx-1.9.9.tar.gz dest=/tmp/nginx-1.9.9.tar.gz
- name: copy install_shell to client
  copy: src=install_nginx.sh dest=/tmp/install_nginx.sh
- name: install nginx
  shell: /bin/bash /tmp/install_nginx.sh
 

 5.webservice.yml:

- hosts: Hadoop
 remote_user: root
  roles:
    - nginx

 6.执行安装:

cd /ansible
ansible-playbook webservice.yml

安装成功!

7.进入test2下检查:

   Ansible自动化安装Nginx

到这里就全部结束了!

Ansible 的详细介绍:请点这里
Ansible 的下载地址:请点这里

相关推荐