##文件上传和下载
1.windows往linux系统里上传和下载文件有多少种方式?
2.linux系统和linux之间上传和下载文件?
1.xshell --》ssh---》sftp (ftp服务是底层依赖ssh服务的)
2.ftp、samba
3.rz
4.windows共享文件夹,linux挂载过去
5.NFS
6.U盘
7.邮件
8.http(提供下载)
apache来做下载 --》默认支持
nginx来做下载,默认不支持
在配置文件里添加,autoindex开头的配置
location / {
autoindex on;
autoindex_exact_size off;
autoindex_localtime on;
}
#ansible
运维自动化: ansible、SaltStack、puppet等
Ansible 是近年越来越火的一款运维自动化工具,其主要功能是帮忙运维实现 IT 工作的自动化、降低人为操作失误、提高业务自动化率、提升运维工作效率,常用于软件部署自动化、配置自动化、管理自动化、系统化系统任务、持续集成、零宕机平滑升级等。它丰富的内置模块(如acl、command、shell、cron、yum、copy、file、user等,多达569个)和开放的 API接口,同时任何遵循 GPL 协议的企业或个人都可以随意修改和发布自己的版本。
Web 界面是一款功能完善的管理工具的必备功能, Tower 是 Ansible 的 Web 化管理界面,但免费版的容量只有 10 台主机,付费版则无容量限制。
##简要
1、关于Ansible
Ansible是一个部署一群远程主机的工具;Ansible通过SSH协议实现远程节点和管理节点之间的通信。理论上说,只要管理员通过ssh登录到一台远程主机上能做的操作,Ansible都可以做到。Ansible是python开发的,故依赖一些python库和组件,如:paramiko,PyYaml和jinja三个关键组件;
##ansible架构
主机清单 host inventory 定义客户机
配置文档 playbooks 剧本 (写明了ansible需要客户机操作的事情) —》定义客户机做什么事情的
模块: 每个模块实现相应的功能
agentless —》没有代理端(无客户端程序)
ssh:密钥认证,免密码登录 —》双向、单向信任关系
node 节点
inode 索引节点 index node
##安装部署
本次测试环境:
ansible: CentOS7.3_x64 192.168.0.116 epel yum安装ansible
node1: 192.168.0.117 CenOS7.3_x64
node2: 192.168.0.80 CentOS7.3_x64
从ansible上生成ssh公钥同步到两台node主机上,实现无密钥登录管理(推荐)
配置无密码登录
1.在ansible主机上生成密钥对
[root@ansible ~]# ssh-keygen -t ecdsa
Generating public/private ecdsa key pair.
Enter file in which to save the key (/root/.ssh/id_ecdsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_ecdsa.
Your public key has been saved in /root/.ssh/id_ecdsa.pub.
The key fingerprint is:
d0:cd:38:85:4a:6a:5a:f4:39:d8:5f:6a:26:0d:67:ed root@ansible
The key's randomart image is:
+--[ECDSA 256]---+
| .. |
| . ...= |
| . *.o+.o |
| = B.o.o |
| + BS+ |
| . . * E |
| + |
| |
| |
+-----------------+
[root@ansible ~]#
2.上传公钥到node1和node2节点服务器的root用户家目录下,同步到到两台node上
2个节点服务器上开启ssh服务 ,开放22号端口,允许root用户登录
[root@ansible .ssh]# ssh-copy-id -i id_ecdsa.pub root@192.168.0.117 上传到第一台节点服务器
/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/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@192.168.0.117's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'root@192.168.0.117'"
and check to make sure that only the key(s) you wanted were added.
[root@ansible .ssh]# ssh-copy-id -i id_ecdsa.pub root@192.168.0.80 上传到第2台节点服务器
The authenticity of host '192.168.0.80 (192.168.0.80)' can't be established.
ECDSA key fingerprint is 67:a6:f8:b3:78:08:3b:81:8c:fa:ef:90:32:c2:21:f7.
Are you sure you want to continue connecting (yes/no)? yes
/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/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@192.168.0.80's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'root@192.168.0.80'"
and check to make sure that only the key(s) you wanted were added.
[root@ansible .ssh]#
3.测试免密码登录是否成功
[root@ansible .ssh]# ssh root@192.168.0.117
Last login: Thu Sep 6 10:32:38 2018 from 192.168.0.39
[root@LB-BACKUP ~]# exit
登出
Connection to 192.168.0.117 closed.
[root@ansible .ssh]# ssh root@192.168.0.80
Last login: Thu Sep 6 10:33:07 2018 from 192.168.0.39
[root@www ~]# exit
登出
Connection to 192.168.0.80 closed.
[root@ansible .ssh]#
4、安装ansible,在管理节点上
目前,只要机器上安装了 Python 2.6 或 Python 2.7 (windows系统不可以做控制主机),都可以运行Ansible.
安装ansible很简单,可通过git从githu上直接获取代码,也可以像redhat/CentOS上通过yum进行安装
[root@ansible .ssh]# yum install epel-release -y
[root@ansible .ssh]# yum install ansible -y
[root@ansible ~]# ansible --version
ansible 2.6.3
config file = /etc/ansible/ansible.cfg
configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python2.7/site-packages/ansible
executable location = /bin/ansible
python version = 2.7.5 (default, Nov 6 2016, 00:28:07) [GCC 4.8.5 20150623 (Red Hat 4.8.5-11)]
[root@ansible ~]#
#认识ansible配置文件
1、配置与执行文件说明
ansible的主配置文件
/etc/ansible/ansible.cfg
这个文件主要定义了roles_path路径,主机清单路径,连接清单中的主机方式等配置,这些大部的默认配置已经足够我们平时使用,如需要特别配置可以自行去修改;
/etc/ansible/hosts
这个配置文件就是默认主机清单配置文件,可通过ansible.cfg重新定义的;
如定义一组主机:
[root@ansible ~]# cd /etc/ansible/
[root@ansible ansible]# ls
ansible.cfg hosts roles
[root@ansible ansible]# vim hosts 添加服务器ip到webservers组里
[webservers]
192.168.0.117
192.168.0.80
[root@ansible ~]# egrep -v '(^$|^#)' /etc/ansible/hosts 查看效果
[webservers]
192.168.0.117
192.168.0.80
除了以上两个重要的配置文件还有三个重要的可执行文件分别是:
ansible 主执行程序,一般用于命令行下执行
ansible-playbook 执行playbook中的任务
ansible-doc 获取各模块的帮助信息
2、ansible 使用格式
ansible
HOST-PATTERN #匹配主机模式,如all表示所有主机
-m MOD_NAME #模块名 如:ping
-a MOD_ARGS #模块执行的参数
-f FORKS #生成几个子进行程执行
-C #(不执行,模拟跑)
-u Username #某主机的用户名
-c CONNection #连接方式(default smart)
完整示例:
查看ip地址的信息
[root@ansible ansible]# ansible all -m shell -a "ifconfig"
192.168.0.80 | SUCCESS | rc=0 >>
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.0.80 netmask 255.255.255.0 broadcast 192.168.0.255
inet6 fe80::158a:f4e6:a40d:8b96 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:b8:49:e6 txqueuelen 1000 (Ethernet)
RX packets 128102 bytes 16335565 (15.5 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 6440 bytes 1203869 (1.1 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1 (Local Loopback)
RX packets 44 bytes 3192 (3.1 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 44 bytes 3192 (3.1 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
192.168.0.117 | SUCCESS | rc=0 >>
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.0.117 netmask 255.255.255.0 broadcast 192.168.0.255
inet6 fe80::20c:29ff:fe66:e2e8 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:66:e2:e8 txqueuelen 1000 (Ethernet)
RX packets 2196102 bytes 1015239838 (968.2 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 256318 bytes 24165084 (23.0 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1 (Local Loopback)
RX packets 53 bytes 7962 (7.7 KiB)
RX er