• friewall/ansible


    1.firewall-cmd: 设置访问web服务器的80端口时转发到8081端口 

    搭建环境(首先我们要可以访问8081端口)

    #进入/etc/httpd/conf.d目录下配置额外的子配置文件
    [root@cotenos ~]# cd /etc/httpd/conf.d/

    # 添加配置文件myhost.conf(名字可自取),并进入配置文件进行配置
    [root@cotenos conf.d]# vim myhost.conf
    listen 8081                                  # 监听8081端口
                    # "/www/ip"为首页文件所在的目录(此时还并未创建)
        AllowOverride None                # 不允许这个目录下的访问控制文件来改变这里的配置
        Require all granted                #允许所有用户访问

            
        DocumentRoot "/www/ip"
        ServerName 192.168.112.135

    保存并退出

    #创建首页文件以及他所在的目录
    [root@cotenos conf.d]# mkdir -p /www/ip
    [root@cotenos conf.d]# vim /www/ip/index.html
    This is port 8081

    # 重启httpd服务(注意要关闭SElinux)
    #查看SELinux状态
    [root@cotenos conf.d]# getenforce
    Enforcing
    #此时是开启状态,我们进行修改(注意这里是临时修改,想要永久修改进入配置文件修改)
    [root@cotenos conf.d]# setenforce 0
    [root@cotenos conf.d]# getenforce 
    Permissive
    #重启服务
    [root@cotenos conf.d]# systemctl restart httpd

    此时并不能访问,这是因为我们的防火墙是开启状态(默认设置是拒绝)
    对防火墙进行配置

    # 同意httpd服务的访问
    [root@cotenos conf.d]# firewall-cmd --add-service=http 
    success
     #这是临时生效,想要永久生效需添加  --permanent命令
     

    查看所有规则:

    root@cotenos conf.d]# firewall-cmd --list-all
    public (active)
      target: default
      icmp-block-inversion: no
      interfaces: ens33
      sources: 
      services: dhcpv6-client http ssh                # 已开启
      ports: 
      protocols: 
      masquerade: no
      forward-ports: 
      source-ports: 
      icmp-blocks: 
      rich rules: 
        

     此时80端口能访问,但是8081端口不能访问,这是因为http协议的默认端口为80端口

    #使任何人都可以访问8081端口
    [root@cotenos conf.d]# firewall-cmd --permanent --add-prot=8081/tcp
    [root@cotenos conf.d]# firewall-cmd --reload
    --permanent:永久生效
    --reload:让“永久生效”的配置规则立即生效,并覆盖当前的配置规则

     将本机80端口转发到192.168.112.35:8081端口上

    [root@cotenos conf.d]# firewall-cmd --add-forward-port=port=80:proto=tcp:toport=8081:toaddr=192.168.112.135
    success

    此时访问80端口:

    2.ansible: 使用shell或者command模块创建用户:testuser1 使用script/shell/command模块执行脚本: 脚本内容为:echo "Hello World" 使用copy模块:将管理主机(manage)上 /root/ansible/copyfile 文件拷贝到 被管理主机node1上的/home/testuser1目录下 使用blockinfile模块:向/home/testuser1/copyfile文件中插入:Hello World 在Hello World之后插入: Hello Shaanxi 在Hello World之前插入:Hello China 删除 Hello World 替换 Hello Shaanxi 为 Hello Xian

    使用shell或者command模块创建用户:testuser1

    [root@manage ansible]# ansible localhost -m shell -a "useradd testuser1"
    localhost | CHANGED | rc=0 >>

     

    使用script/shell/command模块执行脚本: 脚本内容为:echo "Hello World"
    [root@manage ansible]# ansible localhost -m shell -a 'echo "Hello world"'
    localhost | CHANGED | rc=0 >>
    Hello world

    使用copy模块:将管理主机(manage)上 /root/ansible/copyfile 文件拷贝到 被管理主机node1上的/home/testuser1目录下
    [root@manage ansible]# ansible node1 -m copy -a 'src=/root/ansible/copyfile dest=/home/testuser1 '

    查看node1主机的/home/test目录:

    [root@manage ansible]# ansible node1 -m shell -a 'ls -l /home/testuser1'
    node1 | CHANGED | rc=0 >>
    total 4
    -rw-r--r--. 1 root root 13 Nov  4 15:01 copyfile

     

    使用blockinfile模块:向/home/testuser1/copyfile文件中  插入:Hello World     在Hello World之后插入: Hello Shaanxi       在Hello World之前插入:Hello China     删除 Hello World

    替换 Hello Shaanxi 为 Hello Xian

    [root@manage ansible]# ansible node1 -m blockinfile -a 'path=/home/testuser1/copyfile block="Hello World" marker="#{mark} Hello" insertafter="Hello World"'
    node1 | CHANGED => {
        "ansible_facts": {
            "discovered_interpreter_python": "/usr/libexec/platform-python"
        },
        "changed": true,
        "msg": "Block inserted"
    }
     

    [root@manage ansible]# ansible node1 -m blockinfile -a 'path=/home/testuser1/copyfile block="Hello Shaani" marker="#{mark} Shaanxi"'
    node1 | CHANGED => {
        "ansible_facts": {
            "discovered_interpreter_python": "/usr/libexec/platform-python"
        },
        "changed": true,
        "msg": "Block inserted"
    }
     

    [root@manage ansible]# ansible node1 -m blockinfile -a 'path=/home/testuser1/copyfile block="Hello China" marker="#{mark} Shaanxi" insertbefore=BOF'
    node1 | CHANGED => {
        "ansible_facts": {
            "discovered_interpreter_python": "/usr/libexec/platform-python"
        },
        "changed": true,
        "msg": "Block inserted"
    }
     

    [root@manage ansible]# ansible node1 -m blockinfile -a 'path=/home/testuser1/copyfile block="Hello Xian" marker="#{mark} Shaanxi" insertbefore=BOF'
    node1 | CHANGED => {
        "ansible_facts": {
            "discovered_interpreter_python": "/usr/libexec/platform-python"
        },
        "changed": true,
        "msg": "Block inserted"
    }
     

  • 相关阅读:
    Windows 允许 Ping 请求
    L46.linux命令每日一练 -- 第七章 Linux用户管理及用户信息查询命令 -- w和who
    二叉树与二叉搜索树的公共祖先 力扣 (Python)
    基于FPGA的交通信号灯设计
    安防视频平台EasyCVR视频调阅全屏播放显示异常是什么原因?
    web3.js:使用eth包
    Java 变量和数据类型
    xml创建模型组合体
    gridControlExport.ExportToXls(fileName) dev gridcontrol导出excel列宽问题
    Socks5代理与IP代理:网络安全与爬虫中的应用
  • 原文地址:https://blog.csdn.net/weixin_58297531/article/details/127686892