首页 > 系统相关 >ansible实战__使用yum方法安装nginx

ansible实战__使用yum方法安装nginx

时间:2024-07-29 19:50:05浏览次数:8  
标签:__ name CentOS mirrors nginx ansible yum install

目录结构

[root@master yum_install_nginx]# tree
.
├── CentOS-Base.repo
└── nginx_install.yaml

如果yum源有问题需要建 CentOS-Base.repo文件,没有则不需要

报错信息可参考如下链接:

CentOS-Base.repo文件内容

# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client.  You should use this for CentOS
# updates unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#
[base]
name=CentOS-$releasever - Base - Aliyun
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
 
#released updates
[updates]
name=CentOS-$releasever - Updates - Aliyun
baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
 
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - Aliyun
baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
 
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus - Aliyun
baseurl=http://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

注释区域就是为了解决yum源问题,没有则不需要打开

nginx_install.yaml内容

- hosts: node2
  tasks:
    #- name: replace aliyun
    #  copy: src=./CentOS-Base.repo dest=/etc/yum.repos.d/CentOS-Base.repo backup=yes mode=644
    #- name: clean all
    #  command: yum clean all
    #- name: makecache
    #  command: yum makecache
    #- name: install epel-release
    #  yum: name=epel-release state=latest
    #- name: update yum
    #  command: yum update
    - name: install nginx
      yum:
        name: nginx
        state: latest
    - name: start nginx
      systemd:           #或者使用service
        name: nginx
        state: started
        enabled: yes
    - name: start firewall 80
      firewalld:
        port: 80/tcp
        permanent: yes
        immediate: yes
        state: enabled

检查yml文件格式是否正确,没有报错则没问题

[root@master yum_install_nginx]# ansible-playbook -i ../hosts nginx_install.yaml --syntax-check

playbook: nginx_install.yaml

查看操作哪些机器节点

[root@master yum_install_nginx]# ansible-playbook -i ../hosts nginx_install.yaml --list-hosts

playbook: nginx_install.yaml

  play #1 (node2): node2        TAGS: []
    pattern: [u'node2']
    hosts (1):
      node2

执行,注意yaml文件没有和主机清单文件在同一目录,需要指定主机清单文件路径

[root@master yum_install_nginx]# ansible-playbook -i ../hosts nginx_install.yaml

标签:__,name,CentOS,mirrors,nginx,ansible,yum,install
From: https://www.cnblogs.com/yohoolook/p/18330918

相关文章

  • javadoc
    javadoc命令是用来生成自己API文档的参数信息@author作者名@version版本号@since指明需要最早使用的jdk版本@param参数名@return返回值情况@throws异常抛出情况packagecom.studen.base;/***@authorshudou*@version1.0*@since1.8*/publicclass......
  • Python操作MySQL数据库的5种方式
    不管你是做数据分析,还是网络爬虫,Web开发、亦或是机器学习,你都离不开要和数据库打交道,而MySQL又是最流行的一种数据库,这篇文章介绍Python操作MySQL的5种方式,你可以在实际开发过程中根据实际情况合理选择。1、MySQLdbMySQLdb又叫MySQL-python,是Python连接MySQL最流行......
  • Python自定义排序
    Python封装了成熟的排序函数,我们只需要调用内部的sort函数,就可以完成排序。但是实际场景当中,排序的应用往往比较复杂,比如对象类型,当中有多个字段,我们希望按照指定字段排序,或者是希望按照多关键字排序,这个时候就不能简单的函数调用来解决了。1.字典排序我们先来看下最常见的字典......
  • Python中清空list的几种方法
    本文介绍清空list的四种方法,以及list=[]和list.clear()在使用中的区别(坑)。1、使用clear()方法lists=[1,2,1,1,5]lists.clear()print(lists)>>>[]2、重新初始化列表:初始化该范围内的列表,初始化列表没有值,即大小为0的列表lists=[1,2,1,1,5]lists=[]print......
  • 2024夏中山集训第1周
    【NOIP模拟一】20240729比赛有点唐,C没开ll挂50,D挂了一点部分分。C注意到答案是s除以区间gcd。裴蜀定理推广D像这样建图,跑全源最短路。在这张图上有\(1\to2\to3\to4\to5\)和\(7\to8\to9\to3\to10\to11\)两条路径。把路径上的点看作车上的点,每个点本身看作......
  • CF1523D Love-Hate 题解
    CF1523DLove-Hate题解传送门题目大意:给定\(m\)和\(n\)个集合,而且这\(n\)个集合的元素都是\(1\)~\(m\)中的数且没有重复,而且大小都不超过\(15\)。求一个最大的集合,使得这个集合是至少\(\left\lceil\frac{n}{2}\right\rceil\)个集合的子集。先想一个问题:题目是让......
  • CF1523E Crypto Lights 题解
    CF1523ECryptoLights题解传送门。题目大意:有\(n\)个台灯,初始时都是暗的,每次随机点亮一个暗台灯,若点亮后存在一个长度为\(k\)的连续段有大于一个台灯被点亮则立刻停止,求期望点亮多少台灯。(就是直接把原题翻译搬过来了)很明显的期望dp,状态定义也很明显,设\(f_i\)表示......
  • P8347 「Wdoi-6」另一侧的月 题解
    P8347「Wdoi-6」另一侧的月题解第一次自己思考出来紫题,题解纪念一下。下面为大家讲解如何一步步推到最终结论:首先,原树没有根,不妨设它的根为\(1\),将它转化成有根的,便于操作。为了方便描述,我们称将一个非根节点的点的父亲删去,保留含这个点的连通块这个操作为截取操作(就是......
  • 一个小时内快速部署大模型
    这个教程有以下几部分构成:硬件配置概念介绍实操测试结果1.硬件配置本文使用的方法配置要求低,没有gpu也可以正常使用(就是有点慢),不管是windows还是linux,都可以无障碍使用大模型,有脚就行,废话少说,let'srock!2.概念介绍几个部署要用到的概念,工具和项目huggingface:......
  • CF538G Berserk Robot 题解
    Description有一个机器人,第\(0\)秒时在\((0,0)\)位置。机器人会循环执行一个长度为\(l\)的指令序列,每秒执行一个指令。指令有ULDR四种,分别代表向上/左/下/右移动一格。你不知道这个指令序列具体是什么,但是你知道\(n\)条信息,第\(i\)条信息为「第\(t_i\)秒时机器......