使用 ansible 安裝 NGINX
[root@master1 etc]# yum install -yq epel-release && sudo yum install -yq ansible [root@master1 etc]# cat <<EOF > $HOME/ansible-nginx/deploy.yml - hosts: nginx tasks: - include: 'tasks/install_nginx.yml' EOF [root@master1 etc]# cat <<EOF > $HOME/ansible-nginx/tasks/install_nginx.yml - name: NGINX | Installing NGINX repo rpm yum: name: http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm - name: NGINX | Installing NGINX yum: name: nginx state: latest - name: NGINX | Starting NGINX service: name: nginx state: started EOF [root@master1 etc]# mv /etc/ansible/hosts /etc/ansible/hosts.backup [root@master1 etc]# cat <<EOF > /etc/ansible/hosts # /etc/ansible/hosts [nginx] master2 EOF
[root@master1 etc]# sudo ansible-playbook --ask-pass $HOME/ansible-nginx/deploy.yml
SSH password:
PLAY [nginx] ************************************************************************************************************************
TASK [Gathering Facts] **************************************************************************************************************
ok: [master2]
TASK [NGINX | Installing NGINX repo rpm] ********************************************************************************************
changed: [master2]
TASK [NGINX | Installing NGINX] *****************************************************************************************************
changed: [master2]
TASK [NGINX | Starting NGINX] *******************************************************************************************************
changed: [master2]
PLAY RECAP **************************************************************************************************************************
master2 : ok=4 changed=3 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
[root@master2 kubelet]# ps -ef | grep nginx
root 48337 1 0 15:04 ? 00:00:00 nginx: master process /usr/sbin/nginx
nginx 48338 48337 0 15:04 ? 00:00:00 nginx: worker process
nginx 48339 48337 0 15:04 ? 00:00:00 nginx: worker process
nginx 48340 48337 0 15:04 ? 00:00:00 nginx: worker process
nginx 48341 48337 0 15:04 ? 00:00:00 nginx: worker process
root 48480 14520 0 15:05 pts/1 00:00:00 grep --color=auto nginx