代码发布系统python
代码发布:把本地的代码经过某些方式弄到线上,能够供别人访问git
部署web
ansible 批量在远程主机上执行命令shell
puppet rubyjson
ansiblewindows
saltstack跨域
python开发ruby
openpyxl 操做excel表格 读写bash
git 版本控制并发
celery 异步,延时任务,定时任务的一个芹菜
一、安装epel源
yum install -y wget # 安装wget
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo # 下载epel源文件
二、安装ansible
yum install ansible -y
Usage: ansible <host-pattern> [options]
-a MODULE_ARGS, --args=MODULE_ARGS # 模块的参数
-C, --check # 会去执行,可是不作任何的改变,干跑,白跑
-f FORKS, --forks=FORKS # 指定进程数,作并发
--list-hosts #列出主机
-m MODULE_NAME # 模块名称
--syntax-check #检查语法
-k, --ask-pass ask for connection password #指定密码
rpm -ql ansible
/etc/ansible
/etc/ansible/ansible.cfg
/etc/ansible/hosts
/etc/ansible/roles
10.0.0.132
10.0.0.133
10.0.0.134
密码
秘钥
ssh-keygen # 生成秘钥
ssh-copy-id root@10.0.0.132 # 将秘钥文件复制到远程主机
ansible 10.0.0.132 -m ping
ansible 10.0.0.133 -m ping
ansible 10.0.0.134 -m ping
ansible all -m ping # 全部机器,hosts文件里面
ansible 10.0.0.133,10.0.0.132 -m ping # 部分机器
## 分组信息
[web]
10.0.0.132
10.0.0.133
[db]
10.0.0.133
10.0.0.134
[cache]
10.0.0.134
## www[001:006].example.com 从www001到www006
ansible web --list-hosts # 用来获取符合条件的主机
ansible web -m ping # 探测组内的机器
ansible web,db -m ping # 获取db和web的并集
ansible 'web:&db' -m ping # 获取db和web的交集
ansible 'web:!db' -m ping # 获取db和web的差集,在web中可是不在db中的
ansible 'web:db' -m ping # 获取db和web的并集
弱口令校验
密码要符合的规则
必须有大写字母,小写字母,数字,特殊字符
密码必须12位以上
密码须要三个一换
单个的主机
单个组
多个组
交集
‘web:&db’
并集
‘web:db’
web,db
差集
‘web:!db’
全部的机器 all
多个主机
Usage: ansible-doc [-l|-F|-s] [options] [-t <plugin type> ] [plugin]
-j, --json #以json的方式返回全部模块的信息
-l # 列出全部的模块
-s, --snippet # 以片断式显示模块的帮助信息
# 显示所有信息
ansible-doc -l |wc -l #统计ansible的模块
chdir #切换目录
creates # 若是存在,就不执行,若是不存在,就执行
removes # 若是不存在,就不执行,若是存在,就执行
ansible web -m command -a "pwd"
ansible web -m command -a "ls /tmp"
ansible web -m command -a "chdir=/tmp pwd" # 切换目录,通常作编译安装
ansible web -m command -a "creates=/tmp pwd" # 不被执行,由于/tmp已经存在,
ansible web -m command -a "creates=/tmp2 pwd" # 被执行,由于/tmp2目录不存在
ansible web -m command -a "creates=/tmp2 mkdir /data" # 会被执行,由于/tmp2目录不存在
ansible web -m command -a "removes=/tmp2 pwd" # 不被执行,由于/tmp2目录不存在
ansible web -m command -a "removes=/tmp pwd" # 会被执行,由于/tmp已经存在,
补充
#查看用户建立成功与否
1.ll /home
2.tail -1 /etc/passwd
3.tail /etc/shadow
4.id alex
echo "alex3714" |passwd --stdin alex # 给用户设置密码,不须要二次确认
[root@localhost ~]# name=alex
[root@localhost ~]# echo "$name"
alex
[root@localhost ~]# echo '$name'
$name
shabang
ansible web -m shell -a "echo 'alex'|passwd --stdin alex" # 给用户设置密码
ansible 10.0.0.132 -m shell -a "bash a.sh" # 执行shell脚本
ansible 10.0.0.132 -m shell -a "./a.sh"
ansible 10.0.0.132 -m shell -a "/root/a.sh"
ansible 10.0.0.132 -m shell -a "/root/a.py" # 执行python脚本
ansible 10.0.0.132 -m shell -a "python a.py"
# shell 脚本
ansible db -m script -a "/root/a.sh" # 执行的是本地的脚本,管控机上的脚本
ansible db -m script -a "creates=/root/a.sh /root/a.sh" # 判断是远程主机是否存在,若是存在,就不执行,若是不存在,就执行
ansible db -m script -a "removes=/root/a.sh /root/a.sh" # 判断的主机是否存在,若是存在,就执行,若是不存在,就不执行
backup # 建立备份文件,以时间戳结尾
content # 直接写内容
dest # 目标地址
group #文件的属组
mode # 文件的权限W 2 R 4 X 1
owner #文件的属主
src # 原文件
ansible db -m copy -a "src=/root/a.sh dest=/root/a.sh" # 复制文件
ansible db -m copy -a "src=/root/a.sh dest=/root/a.sh mode=755" # 复制文件,并修改文件的权限
ansible db -m copy -a "src=/root/a.sh dest=/root/a.sh mode=755 owner=alex" #复制文件,修改文件的权限,属主,根据md5值来判断
ansible db -m copy -a "src=/etc/init.d dest=/tmp/" # 复制文件夹
ansible db -m copy -a "src=/etc/init.d/ dest=/tmp/" # 复制文件夹下面的全部文件
ansible db -m copy -a "src=/etc/init.d dest=/tmp/ owner=alex " # 复制文件夹,并改变文件夹的属性,文件夹的文件的属性也会跟着改变
ansible db -m copy -a "content='大弦嘈嘈如急雨,小弦切切如私语' dest=/tmp/a.sh" # 直接写文字,覆盖写入,要慎用
ansible db -m copy -a "src=/root/a.sh dest=/root/a.sh mode=755 owner=alex backup=yes" #备份文件,若是远程机器上没有要备份的文件,即便指定了backup=yes 也不会去备份文件
access_time # 访问事件
group # 属组
mode #权限
owner #属主
path #路径
src # 原文件,link和hard的时候使用
state:
directory 文件夹
file
touch 空文件
link 软链接
hard 硬连接
absent 删除
ansible db -m file -a "path=/tmp/baoyuan state=directory" # 建立一个目录
ansible db -m file -a "path=/tmp/baoyuan state=directory owner=alex mode=644" # 建立一个目录,并制定属主,权限
ansible db -m file -a "path=/tmp/baoyuan.txt state=touch owner=alex mode=644" # 建立一个文件,并制定属主,权限
ansible db -m file -a "path=/tmp/f src=/etc/fstab state=link" # 建立一个软链接
ansible db -m file -a "path=/tmp/f state=absent" # 删除
补充
软链接 windows的快捷方式 ln —s 原文件 目标文件 源文件改变,目标文件也改变 能够跨越分区 原文件删除,连接失效
硬连接 指向同一个硬盘的地址 ln 原文件 目标文件 原文件改变,目标文件也改变 不能够跨域分区 原文件删除,不会受影响
复制
ansible 安装,epel源
ansible 里面ping 走的是ssh
host-pattern的格式
单个的ip
多个的ip
单个组
多个组
交集
‘web:&db’
并集
‘web:db’
‘web,db’
差集
‘web:!db’
command 执行命令 不支持特殊字符 $ < > | ; &
chdir 切换目录,通常是编译安装
creates 判断是否存在,若是存在,就不执行,若是不存在,就执行
removes 判断是否存在,若是存在,就执行,若是不存在,就不执行
shell 执行远程机器上的shell脚本或者python脚本
chdir 切换目录,通常是编译安装
creates 判断是否存在,若是存在,就不执行,若是不存在,就执行
removes 判断是否存在,若是存在,就执行,若是不存在,就不执行
script 执行本地脚本,执行管控机上的脚本
chdir 切换目录,通常是编译安装
creates 判断远程主机是否存在,若是存在,就不执行,若是不存在,就执行
removes 判断远程主机是否存在,若是存在,就执行,若是不存在,就不执行
copy 将本地的文件复制到远程主机上
src 原文件
dest 目标文件
owner 属主
group 属组
mode 权限
backup 备份
content 直接写内容,覆盖写
file 在远程主机上建立文件,文件夹,软链接,硬连接
path 目录
src
link
hard
owner
group
mode
state
directory 文件夹
touch 文件
link 软链接
hard 硬连接
absent 删除
file