栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

部署httpd的playbook

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

部署httpd的playbook

前期准备工作

在做的时候,主控机和受控机已经连接了

首先,先把受控机恢复快照到空配置的时候

此时ssh则需要输入密码

[root@control httpd]# ssh web01.example.com
root@web01.example.com's password: 
Activate the web console with: systemctl enable --now cockpit.socket

This system is not registered to Red Hat Insights. See https://cloud.redhat.com/
To register this system, run: insights-client --register

Last login: Fri May 27 15:43:57 2022
[root@localhost ~]# exit
logout
Connection to web01.example.com closed.

设置免密登录

[root@control httpd]# ssh-copy-id web01.example.com
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@web01.example.com's password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'web01.example.com'"
and check to make sure that only the key(s) you wanted were added.

//现在可以ping通了
[root@control httpd]# ansible all -m ping
web01.example.com | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": false,
    "ping": "pong"
}
 playbook
[root@control httpd]# vim install.yml
---
- hosts: webservers
  tasks:
    - name: provides repo file
      copy:
        src: files/CentOS-Base.repo
        dest: /etc/yum.repos.d/
        
    - name: install apache
      yum:
        name: httpd
        state: latest
        
    - name: porvides web site
      copy:
        src: files/mm
        dest: /var/www/html
        
    - name: config apache
      copy:
        src: files/httpd-vhosts.conf
        dest: /etc/httpd/conf.d/
        
    - name: run httpd
      service:
        name: httpd
        state: started
        enabled: yes
        
    - name: close firewalld
      service:
        name: firewalld
        state: stopped
        enabled: no
[root@control httpd]# ansible-playbook -C install.yml    //测试能不能跑
[root@control httpd]# ansible-playbook install.yml    //运行
详细步骤
//先装apache
[root@control httpd]# vim install.yml
---
- hosts: webservers
  tasks:
    - name: provides repo file
      copy:
        src: files/CentOS-Base.repo
        dest: /etc/yum.repos.d/

    - name: install apache
      yum:
        name: httpd
        state: latest
[root@control httpd]# ansible-playbook install.yml 
//受控机
[root@localhost ~]# rpm -qa | grep httpd
centos-logos-httpd-85.8-2.el8.noarch
httpd-tools-2.4.37-43.module_el8.5.0+1022+b541f3b1.x86_64
httpd-2.4.37-43.module_el8.5.0+1022+b541f3b1.x86_64
httpd-filesystem-2.4.37-43.module_el8.5.0+1022+b541f3b1.noarch
[root@localhost ~]# 


//在受控机上找到配置文件
[root@localhost ~]# cd /etc/httpd
[root@localhost httpd]# ls
conf  conf.d  conf.modules.d  logs  modules  run  state
[root@localhost httpd]# cd conf
[root@localhost conf]# ls
httpd.conf  magic
[root@localhost conf]# cd ../conf.d/
[root@localhost conf.d]# ls
autoindex.conf  README  userdir.conf  welcome.conf
[root@localhost conf.d]# find / -name *vhosts.conf
/usr/share/doc/httpd/httpd-vhosts.conf
[root@localhost conf.d]# 

//修改配置文件
[root@control httpd]# cd files
[root@control files]# scp web01.example.com:/usr/share/doc/httpd/httpd-vhosts.conf .
httpd-vhosts.conf                                 100% 1477     1.3MB/s   00:00    
[root@control files]# ls
CentOS-Base.repo  httpd-vhosts.conf
[root@control files]# vim httpd-vhosts.conf 

    DocumentRoot "/var/www/html/ting"
    ServerName ting.example.com
    ErrorLog "/var/log/httpd/ting.example.com-error_log"
    CustomLog "/var/log/httpd/ting.example.com-access_log" common



//把配置文件弄到受控机上
[root@localhost conf.d]# ls    //此时没有
autoindex.conf  README  userdir.conf  welcome.conf

//playbook
[root@control files]# cd ..
[root@control httpd]# vim install.yml 
---
- hosts: webservers
  tasks:
    - name: provides repo file
      copy:
        src: files/CentOS-Base.repo
        dest: /etc/yum.repos.d/

    - name: install apache
      yum:
        name: httpd
        state: latest

    - name: config apache
      copy:
        src: files/httpd-vhosts.conf
        dest: /etc/httpd/conf.d/
[root@control httpd]# ansible-playbook install.yml 

PLAY [webservers] ******************************************************************

TASK [Gathering Facts] *************************************************************
ok: [web01.example.com]

TASK [provides repo file] **********************************************************
ok: [web01.example.com]

TASK [install apache] **************************************************************
ok: [web01.example.com]

TASK [config apache] ***************************************************************
changed: [web01.example.com]

PLAY RECAP *************************************************************************
web01.example.com          : ok=4    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
//现在受控机可以查看到了/
[root@localhost conf.d]# ls
autoindex.conf  httpd-vhosts.conf  README  userdir.conf  welcome.conf
[root@localhost conf.d]# cat httpd-vhosts.conf 

    DocumentRoot "/var/www/html/ting"
    ServerName ting.example.com
    ErrorLog "/var/log/httpd/ting.example.com-error_log"
    CustomLog "/var/log/httpd/ting.example.com-access_log" common


//下载一个网站
[root@control files]# yum -y install unzip
[root@control files]# unzip jcB.zip
[root@control files]# mv  jcB小游戏 ting
[root@control files]# rm -rf jcB.zip

//playbook
[root@control httpd]# vim install.yml
---
- hosts: webservers
  tasks:
    - name: provides repo file
      copy:
        src: files/CentOS-Base.repo
        dest: /etc/yum.repos.d/
        
    - name: install apache
      yum:
        name: httpd
        state: latest
        
    - name: porvides web site
      copy:
        src: files/ting
        dest: /var/www/html
        
    - name: config apache
      copy:
        src: files/httpd-vhosts.conf
        dest: /etc/httpd/conf.d/
        
    - name: run httpd
      service:
        name: httpd
        state: started
        enabled: yes
        
    - name: close firewalld
      service:
        name: firewalld
        state: stopped
        enabled: no
[root@control httpd]# ansible-playbook install.yml

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/941926.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号