devops--day3

昨日內容回顧

git push origin --delete namepython

git log --pretty=format:"%h:%s:%an"linux

git rebase 變基 將提交記錄合併成一條直線git

git fetch 只拉取不合並web

git merge 合併docker

.gitignoreshell

git tag 查看標籤json

git tag -a name -m "" 建立標籤vim

git tag -a name -m "" hash值 給以前的建立一個標籤ruby

git tag -d name 刪除bash

git push origin --tags 將本地的標籤都推送到遠程

git show name 查看詳情

git push origin :refs/tags/name

git checkout name 切換標籤

git checkout filename 將指定文件會退到最近一次提交的地方

給別人貢獻代碼

  • 合做人
  • 新建一個組織
  • fork+new pull request

正則

openpyxl

from openpyxl import Workbook
wb=Workbook()
wb1=wb.create_sheet("name",index)
wb.active
wb1.title=""
wb1["A3"]=
wb1.cell(row=3,column=3,vlaue="")
wb1.append([])
wb.save("1.xlsx")
from openpyxl import load_workbook
#data_only 獲取函數的值 read_only 只讀
wb=load_workbook(filename,data_only=True,read_only=True)
wb.sheetnames
wb1=wb["name"]
wb1["A3"].value
wb1.cell(row=3,column=4).value
wb1.rows
wb1.columns 不能用read_only
wb1.max_row
wb1.max_column

ansible

用來批量在遠程主機上執行命令或者腳本的一個工具

python 2.7

saltstack python

puppet ruby https ssl認證

pip install

下載源碼

python setup.py build

python setup.py install

編譯安裝

  • configure
  • make
  • make install

1.epel源(第三方的rpm包)

編譯安裝

yum 安裝 rpm

https://opsx.alibaba.com/mirror 阿里鏡像網站

163

sohu

ali

騰訊

清華

北大

中科院

docke ce 社區版本 開源

docker ee 商業版本 oracle redhat

128 是管理者 控制節點

129 130 131 是被控節點

安裝ansible

#安裝wget
yum install -y wget
#下載epel源
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
#安裝ansible
yum install -y ansible

命令格式

ansible --help
Usage: ansible <host-pattern> [options]
 -a MODULE_ARGS #模塊參數 ,一個命令就是一個模塊
 -C, --check 不會真正的執行,可是會白跑一次,幹跑
 -f FORKS 指定進程數,高併發
 --list-hosts 列出匹配到的主機列表
 -m MODULE_NAME, 指定模塊
 --syntax-check 語法檢查
 -k, --ask-pass  輸入密碼

ping 走的是ICMP 協議(做業)

/etc/ansible/ansible.cfg #配置文件
/etc/ansible/hosts
/etc/ansible/roles #

hosts
# This is the default ansible 'hosts' file.
#
# It should live in /etc/ansible/hosts
#
#   - Comments begin with the '#' character #號用來註釋
#   - Blank lines are ignored 空行能夠被忽略
#   - Groups of hosts are delimited by [header] elements
#   - You can enter hostnames or ip addresses 能夠輸入主機名或者ip地址
#   - A hostname/ip can be a member of multiple groups 一個ip或者主機能夠被分在多個組
#10.0.0.129
#10.0.0.130
#10.0.0.131
[web]
10.0.0.129
10.0.0.130
[db]
10.0.0.130
10.0.0.131
[cache]
10.0.0.131
#www[001:006].example.com www001 - www006

ping

ansible 10.0.0.129 -m ping -k
ansible 10.0.0.130 -m ping 
ansible 10.0.0.131 -m ping
ansible 10.0.0.130,10.0.0.129 -m ping
ansible all -m ping
ansible web -m ping
ansible web,db -m ping
ansible "web:&db" -m ping
ansible 'web:!db' -m ping

祕鑰

ssh-keygen #生成祕鑰 一直回車 祕鑰對 公鑰 私鑰
ssh-copy-id root@ip #將本地的key複製到遠程機器
vi /etc/ssh/sshd_config 
修改UserDNS no 
sed  -i "s@#UseDNS yes@UseDNS no@" /etc/ssh/sshd_config 
systemctl restart sshd 重啓sshd

交集 有相同的

並集 合併的集合

差集 相差的集合

host-pattern 寫法

  • 單個的ip地址

  • 多個的ip地址 用,隔開

  • 全部的ip地址 all

  • 單個的組

  • 多個的組

    • 交集
      • 'web:&db'
    • 並集
      • web,db
      • 'web:db'
    • 差集 表示在前面,可是不在後面的
      • 'web:!db'

    ansible-doc

    Usage: ansible-doc [-l|-F|-s] [options] [-t <plugin type> ] [plugin]
    -j 以json的方式返回全部的模塊信息
    -l 列出全部的模塊
    -s 簡短的方式來展現模塊信息
    [root@bogon ~]# ansible-doc -l|wc -l
    2834
    ansible-doc ping 查看詳細信息

    A10 F5

    aws 亞馬遜雲

    azure 微軟雲

    command

    ansible web -a "pwd"  執行命令
    ansible web -a "ls"
    ansible web -a "chdir=/tmp pwd" 先切換目錄在執行命令,通常用在編譯
    ansible web -a "creates=/tmp pwd"  命令不會被執行,由於/tmp是存在的
    ansible web -a "creates=/tmp2 pwd" 命令會被執行,由於/tmp2目錄是不存在的
    ansible web -a "removes=/tmp2 pwd" 命令不會被執行 ,由於/tmp2目錄不存在
    ansible web -a "removes=/tmp pwd" 命令會被執行,由於/tmp存在
    ansible web -a "creates=/data mkdir /data" /data目錄會被建立,由於/data不存在

    補充

    查看用戶是否建立成功

    id alex
    tail -1 /etc/passwd
    tail -1 /etc/shadow
    su alex

    設置密碼

    echo "1" |passwd --stdin alex

    shell

    ansible web -m shell -a "chdir=/tmp pwd"
    ansible 10.0.0.129 -m shell -a "bash a.sh" 執行腳本 文件能夠沒有執行權限
    ansible 10.0.0.129 -m shell -a "/root/a.sh" 執行腳本 文件必需要有執行權限
    ansible 10.0.0.129 -m shell -a "python a.py"
    ansible 10.0.0.129 -m shell -a "/root/a.py"
    若是說腳本里面指定了解釋器,那麼就用執行的解釋器來解釋,若是沒有指定解釋器的話,則用bash 
    shabang

    補充

    [root@localhost ~]# cat a.sh 
    #!/bin/bash
    echo "shell"
    [root@localhost ~]# bash a.sh
    shell
    [root@localhost ~]# chmod +x a.sh 
    [root@localhost ~]# ./a.sh 
    shell
    [root@localhost ~]# python a.py 
    停車坐愛楓林晚,霜葉紅於二月花
    [root@localhost ~]# ./a.py
    -bash: ./a.py: Permission denied
    [root@localhost ~]# chmod +x a.py 
    [root@localhost ~]# ./a.py
    停車坐愛楓林晚,霜葉紅於二月花
    [root@localhost ~]# cat a.py
    #!/usr/bin/python
    #coding:utf-8
    print("停車坐愛楓林晚,霜葉紅於二月花")

    script

    文件必須得有執行權限
    ansible web -m script -a "/root/a.sh"
    ansible web -m script -a "a.sh"
    ansible web -m script -a "chdir=/tmp a.sh" 先切換目錄在執行腳本
    ansible web -m script -a "creates=/root/a.sh a.sh" 判斷的是遠程主機上是否存在文件,若是存在就跳過
    ansible web -m script -a "removes=/root/a.sh a.sh" 判斷遠程主機上是否存在,若是存在的話就執行

今日內容總結

git 使用ssh的方式上傳或者下載文件

pycharm裏面的git客戶端

ansible

  • 安裝 epel源

  • host-pattern格式

    • 單個ip
    • 多個ip地址,用,分割
    • all 全部的ip地址
    • 單個組
    • 多個組
      • 交集
        • 'web:&db'
      • 並集
        • web,db
        • 'web:db'
      • 差集 前面存在,可是後面沒有
        • 'web:!db'

    ping

    ansible 是基於ssh的

    command 執行遠程主機上的命令,不支持特殊字符 $ < > | & !

    • chdir 切換目錄,編譯的時候
    • creates 判斷是否存在,若是存在,就不執行
    • removes 判斷是否存在,若是存在,就執行

    shell 執行遠程主機上的命令或者腳本

    • chdir 切換目錄,編譯的時候
    • creates 判斷是否存在,若是存在,就不執行
    • removes 判斷是否存在,若是存在,就執行

    script 執行本地的腳本(管理機上) 腳本必需要有執行的權限

    • chdir 切換目錄,編譯的時候
    • creates 判斷遠程是否存在,若是存在,就不執行
    • removes 判斷遠程是否存在,若是存在,就執行

做業

icmp

把crm分頁 找出來

複習linux

用戶

用戶組

yum

pip

crontab

systemctl

service

vim

本站公眾號
   歡迎關注本站公眾號,獲取更多信息