美文网首页
Linux云计算学习笔记day39

Linux云计算学习笔记day39

作者: 我要笑 | 来源:发表于2019-05-29 23:18 被阅读0次

    for  n in {1..10} ;

    do 

    echo $n  ;

    done

        i的初始化 ;i<=10 条件;i++

    从1开始每次增加1 大于10的时候结束循环

    for((i=1;i<=10;i++))

    do

    echo $i

    done

    每5分钟同步系统时间

    */5 * *  * *  ntpdate  ntp1.aliyun.com  >>/tmp/ntpdate.log 2>&1

    * * *  * *  ntpdate  ntp1.aliyun.com  >>/tmp/ntpdate.log 2>&1

    #sync time

    */5 * * * *  /sbin/ntpdate  ntp1.aliyun.com  >/dev/null 2>&1

    定时任务中 识别PATH环境变量默认  /usr/bin和/bin

    定时任务模块 cron

    #sync time

    */5 * * * *  /sbin/ntpdate  ntp1.aliyun.com  >/dev/null 2>&1.

    ansible all -m yum -a 'name=ntpdate state=present'

    ansible all -m cron -a 'name="sync time" minute="*/5" job="/sbin/ntpdate  ntp1.aliyun.com  >/dev/null 2>&1"'

    #ansible all -m cron -a 'name="zwav time" state=absent '

    ansible 172.16.1.7 -m mount -a "src=172.16.1.31:/data path=/backup fstype=nfs opts=defaults state=present"

    #nfs01

    /nfs      172.16.1.0/24(rw,all_squash,anonuid=888,anongid=888)

    [root@nfs01 ~]# showmount -e 172.16.1.31

    Export list for 172.16.1.31:

    /nfs    172.16.1.0/24

    /upload 172.16.1.0/24

    #web01 把nfs01 共享的/nfs  挂载到 /upload

    /upload

    [root@m01 ~]# #mount -t nfs  172.16.1.31:/nfs    /upload

    [root@m01 ~]# ansible 172.16.1.7 -m  mount -a 'fstype=nfs src=172.16.1.31:/nfs path=/upload state=mounted'

    172.16.1.7 | CHANGED => {

        "ansible_facts": {

            "discovered_interpreter_python": "/usr/bin/python"

        },

        "changed": true,

        "dump": "0",

        "fstab": "/etc/fstab",

        "fstype": "nfs",

        "name": "/upload",

        "opts": "defaults",

        "passno": "0",

        "src": "172.16.1.31:/nfs"

    }

    [root@m01 ~]# ansible 172.16.1.7 -a 'df -h'

    172.16.1.7 | CHANGED | rc=0 >>

    Filesystem        Size  Used Avail Use% Mounted on

    172.16.1.31:/nfs  99G  1.7G  98G  2% /upload

    [root@m01 ~]# ansible 172.16.1.7 -a 'grep upload /etc/fstab'

    172.16.1.7 | CHANGED | rc=0 >>

    172.16.1.31:/nfs /upload nfs defaults 0 0

    #playbook

    [root@m01 /etc/ansible]# cat touch.yml

    ---

      - hosts: all

        tasks:

        - name: make av

          command: mkdir -p /tmp/a/b/c/d/e/f/g/

     

    ansible-playbook -C touch.yml

    ansible-playbook  touch.yml

    [root@m01 /etc/ansible]# ansible all -a 'crontab -l'

    172.16.1.7 | CHANGED | rc=0 >>

    #backup

    00 00 * * * sh /server/scripts/bak.sh  >/dev/null 2>&1

    #Ansible: sync time

    */5 * * * * /sbin/ntpdate  ntp1.aliyun.com  >/dv/null 2>&1

    172.16.1.41 | CHANGED | rc=0 >>

    #Ansible: sync time

    */5 * * * * /sbin/ntpdate  ntp1.aliyun.com  >/dv/null 2>&1

    [root@m01 /etc/ansible]# cat cron-time.yml

    ---

      - hosts: all

        tasks:

        - name: sync time

          cron: name="sync time" minute="*/5" job="/sbin/ntpdate  ntp1.aliyun.com  >/dv/null 2>&1" state=present

     

    #ansible实现 部署nfs服务 及在web01 web02 挂载  playbook

    #!/bin/bash

    #one key install nfs

    #package  install?

    yum install -y rpcbind nfs-utils

    #configure

    cp /etc/exports{,.bak}

    cat >/etc/exports<<EOF

    #nfs01

    /nfs      172.16.1.0/24(rw,all_squash)

    EOF

    #dir owner

    mkdir -p /nfs

    chown nfsnobody.nfsnobody  /nfs

    #start  rpcbind nfs

    systemctl start rpcbind  nfs

    systemctl enable rpcbind  nfs

    ##部署nfs服务

    相关文章

      网友评论

          本文标题:Linux云计算学习笔记day39

          本文链接:https://www.haomeiwen.com/subject/sokptctx.html