当前位置: 首页 > news >正文

阿里地区网站建设_网站建设公司_产品经理_seo优化

做一个回收网站怎么做,做企业网站要多少钱,制作灯笼的视频,网站上传大马后怎么做一、关于AnsibleAnsible是一个自动化部署工具;Ansible通过SSH协议实现远程节点和管理节点之间的通信。理论上说#xff0c;只要管理员通过ssh登录到一台远程主机上能做的操作#xff0c;Ansible都可以做到。Ansible是python开发的,故依赖一些python库和组件,如:paramiko…一、关于AnsibleAnsible是一个自动化部署工具;Ansible通过SSH协议实现远程节点和管理节点之间的通信。理论上说只要管理员通过ssh登录到一台远程主机上能做的操作Ansible都可以做到。Ansible是python开发的,故依赖一些python库和组件,如:paramikoPyYaml和jinja三个关键组件。 1、安装epel源 RHEL/CentOS 6:# yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpmRHEL/CentOS 7:# yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm2、安装Ansible [rootn1 ~]# yum install ansible -y 3、目录结构 [rootn1 ~]# tree /etc/ansible/ /etc/ansible/ |-- ansible.cfg |-- hosts -- roles1 directory, 2 files #Ansible 定义主机、组规则的配置文件 vim /etc/ansible/hostswww.abc.com # 定义域名192.168.1.100 # 定义 IP192.168.1.150:37268 # 指定端口号[WebServer] # 定义分组192.168.1.10 192.168.1.20 192.168.1.30[DBServer] # 定义多个分组192.168.1.50 192.168.1.60Monitor ansible_ssh_port12378 ansible_ssh_host192.168.1.200 # 定义别名# ansible_ssh_host 连接目标主机的地址# ansible_ssh_port 连接目标主机的端口默认 22 时无需指定# ansible_ssh_user 连接目标主机默认用户# ansible_ssh_pass 连接目标主机默认用户密码# ansible_ssh_connection 目标主机连接类型可以是 local 、ssh 或 paramiko# ansible_ssh_private_key_file 连接目标主机的 ssh 私钥# ansible_*_interpreter 指定采用非 Python 的其他脚本语言如 Ruby 、Perl 或其他类似 ansible_python_interpreter 解释器[webservers] # 主机名支持正则描述www[01:50].example.com[dbservers]db-[a:f].example.com #ansible-doc 获取帮助信息   ansible模块比较多,可以通过ansible-doc --help 显示帮助信息[rootn1 ~]# ansible-doc --help Usage: ansible-doc [-l|-F|-s] [options] [-t plugin type ] [plugin]plugin documentation toolOptions: -a, --all **For internal testing only** Show documentation for all plugins. -h, --help show this help message and exit -j, --json **For internal testing only** Dump json metadata for all plugins. -l, --list List available plugins -F, --list_files Show plugin names and their source files without summaries (implies --list) -M MODULE_PATH, --module-pathMODULE_PATH prepend colon-separated path(s) to module library (default[u/root/.ansible/plugins/modules, u/usr/share/ansible/plugins/modules]) -s, --snippet Show playbook snippet for specified plugin(s) -t TYPE, --typeTYPE Choose which plugin type (defaults to module) -v, --verbose verbose mode (-vvv for more, -vvvv to enable connection debugging) --version show programs version number and exitSee man pages for Ansible CLI options or website for tutorials https://docs.ansible.com 4、查看ansible版本 [rootn1 ~]# ansible --version ansible 2.6.4config file /etc/ansible/ansible.cfgconfigured module search path [u/root/.ansible/plugins/modules, u/usr/share/ansible/plugins/modules]ansible python module location /usr/lib/python2.6/site-packages/ansibleexecutable location /usr/bin/ansiblepython version 2.6.6 (r266:84292, Aug 18 2016, 15:13:37) [GCC 4.4.7 20120313 (Red Hat 4.4.7-17)]5、hosts 文件添加被管理机 [rootn1 ~]# vi /etc/ansible/hosts# Ex 2: A collection of hosts belonging to the webservers group ## [webservers] ## alpha.example.org ## beta.example.org ## 192.168.1.100 ## 192.168.1.110[webservers] m1.gree.com m2.gree.com 6、配置/etc/hosts 192.168.1.8 n1.gree.com 192.168.1.4 m1.gree.com 192.168.1.6 m2.gree.com7、ssh-keygen认证 [rootn1 ~]# ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/root/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /root/.ssh/id_rsa. Your public key has been saved in /root/.ssh/id_rsa.pub. The key fingerprint is: f4:53:3b:17:15:4b:30:39:c5:1d:7e:bf:75:d7:cb:5d rootn1.gree.com The keys randomart image is: --[ RSA 2048]---- | o| | ooo| | . . oo.| | . . . . .| | S o o . E| | . o. O| | .| | | | | -----------------[rootn1 ~]# ssh-copy-id -i ~/.ssh/id_rsa 192.168.1.4 The authenticity of host 192.168.1.4 (192.168.1.4) cant be established. RSA key fingerprint is ac:e2:3b:c8:eb:4c:af:a2:83:ac:7c:51:13:22:95:5d. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added 192.168.1.4 (RSA) to the list of known hosts. root192.168.1.4s password: Now try logging into the machine, with ssh 192.168.1.4, and check in:.ssh/authorized_keysto make sure we havent added extra keys that you werent expecting.#测试登录[rootn1 ~]# ssh m1.gree.com The authenticity of host m1.gree.com (192.168.1.4) cant be established. RSA key fingerprint is ac:e2:3b:c8:eb:4c:af:a2:83:ac:7c:51:13:22:95:5d. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added m1.gree.com (RSA) to the list of known hosts. Last login: Fri Nov 9 14:52:03 2018 from 120.236.245.14 [rootm1 ~]# exit 二、ansible常用模块 2.1、ansible 使用格式 HOST-PATTERN #匹配主机模式,如all表示所有主机 -m MOD_NAME #模块名 如:ping -a MOD_ARGS #模块执行的参数 -f FORKS #生成几个子进行程执行 -C #(不执行模拟跑) -u Username #某主机的用户名 -c CONNection #连接方式default smart 示例 #查看IP地址 [rootn1 ~]# ansible all -m shell -a ifconfig m2.gree.com | SUCCESS | rc0 eth0 Link encap:Ethernet HWaddr 52:54:00:2F:CA:4A inet addr:192.168.1.6 Bcast:192.168.1.255 Mask:255.255.255.0UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1RX packets:60690 errors:0 dropped:0 overruns:0 frame:0TX packets:53579 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:1000 RX bytes:15046135 (14.3 MiB) TX bytes:6350897 (6.0 MiB)lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0UP LOOPBACK RUNNING MTU:65536 Metric:1RX packets:0 errors:0 dropped:0 overruns:0 frame:0TX packets:0 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:0 RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)m1.gree.com | SUCCESS | rc0 eth0 Link encap:Ethernet HWaddr 52:54:00:98:4B:1D inet addr:192.168.1.4 Bcast:192.168.1.255 Mask:255.255.255.0UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1RX packets:42579 errors:0 dropped:0 overruns:0 frame:0TX packets:32927 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:1000 RX bytes:27319373 (26.0 MiB) TX bytes:5283478 (5.0 MiB)lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0UP LOOPBACK RUNNING MTU:65536 Metric:1RX packets:0 errors:0 dropped:0 overruns:0 frame:0TX packets:0 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:0 RX bytes:0 (0.0 b) TX bytes:0 (0.0 b) 2.2、copy模块从本地copy文件分发到目录主机路径 参数说明:src 源文件路径dest 目标路径 注意src 路径后面带/ 表示带里面的所有内容复制到目标目录下不带/是目录递归复制过去content 自行填充的文件内容owner 属主group 属组mode权限 [rootn1 tmp]# ansible all -m copy -a src/tmp/1.txt dest/tmp/1.txt mode644 m2.gree.com | SUCCESS {changed: true, checksum: da39a3ee5e6b4b0d3255bfef95601890afd80709, dest: /tmp/1.txt, gid: 0, group: root, md5sum: d41d8cd98f00b204e9800998ecf8427e, mode: 0644, owner: root, size: 0, src: /root/.ansible/tmp/ansible-tmp-1541754612.03-46738208597425/source, state: file, uid: 0 } m1.gree.com | SUCCESS {changed: true, checksum: da39a3ee5e6b4b0d3255bfef95601890afd80709, dest: /tmp/1.txt, gid: 0, group: root, md5sum: d41d8cd98f00b204e9800998ecf8427e, mode: 0644, owner: root, size: 0, src: /root/.ansible/tmp/ansible-tmp-1541754612.03-181393664674709/source, state: file, uid: 0 }2.3 fetch模块从远程主机拉取文件到本地示例 [rootn1 tmp]# ansible all -m fetch -a src/tmp/2.txt dest/tmp m1.gree.com | SUCCESS {changed: false, checksum: da39a3ee5e6b4b0d3255bfef95601890afd80709, dest: /tmp/m1.gree.com/tmp/2.txt, file: /tmp/2.txt, md5sum: d41d8cd98f00b204e9800998ecf8427e } m2.gree.com | SUCCESS {changed: true, checksum: da39a3ee5e6b4b0d3255bfef95601890afd80709, dest: /tmp/m2.gree.com/tmp/2.txt, md5sum: d41d8cd98f00b204e9800998ecf8427e, remote_checksum: da39a3ee5e6b4b0d3255bfef95601890afd80709, remote_md5sum: null } [rootn1 tmp]# ll total 24 -rw-r--r-- 1 root root 0 Nov 9 17:09 1.txt -rw-r--r-- 1 root root 3018 Nov 9 14:48 cvm_init.log drwxr-xr-x 3 root root 4096 Nov 9 17:19 m1.gree.com drwxr-xr-x 3 root root 4096 Nov 9 17:20 m2.gree.com -rw-r--r-- 1 root root 797 Nov 9 14:48 net_affinity.log -rw-r--r-- 1 root root 26 Nov 9 14:48 nv_gpu_conf.log -rw-r--r-- 1 root root 192 Nov 9 14:48 setRps.log [rootn1 tmp]# cd m2.gree.com/ [rootn1 m2.gree.com]# ll total 4 drwxr-xr-x 2 root root 4096 Nov 9 17:20 tmp [rootn1 m2.gree.com]# cd tmp/ [rootn1 tmp]# ll total 0 -rw-r--r-- 1 root root 0 Nov 9 17:20 2.txt2.3、command模块在远程主机上执行命令,属于裸执行,非键值对显示;不进行shell解析; [rootn1 tmp]# ansible all -m command -a ifconfig m2.gree.com | SUCCESS | rc0 eth0 Link encap:Ethernet HWaddr 52:54:00:2F:CA:4A inet addr:192.168.1.6 Bcast:192.168.1.255 Mask:255.255.255.0UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1RX packets:85804 errors:0 dropped:0 overruns:0 frame:0TX packets:78728 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:1000 RX bytes:17782454 (16.9 MiB) TX bytes:9652720 (9.2 MiB)lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0UP LOOPBACK RUNNING MTU:65536 Metric:1RX packets:0 errors:0 dropped:0 overruns:0 frame:0TX packets:0 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:0 RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)2.4、shell模块由于commnad只能执行裸命令(即系统环境中有支持的命令),至于管道之类的功能不支持,shell模块可以做到 [rootn1 tmp]# ansible all -m shell -a ifconfig|grep lo m1.gree.com | SUCCESS | rc0 lo Link encap:Local Loopback m2.gree.com | SUCCESS | rc0 lo Link encap:Local Loopback 2.5、file模块设置文件属性(创建文件)常用参数:path目标路径state directory为目录,link为软件链接group 目录属组owner 属主等,其他参数通过ansible-doc -s file 获取示例1:创建目录 [rootn1 tmp]# ansible all -m file -a path/tmp/hello statedirectory m1.gree.com | SUCCESS {changed: true, gid: 0, group: root, mode: 0755, owner: root, path: /tmp/hello, size: 4096, state: directory, uid: 0 }2.6、   参考 http://blog.51cto.com/dyc2005/2070729  https://www.cnblogs.com/wangxiaoqiangs/p/5685239.html转载于:https://www.cnblogs.com/nulige/p/9936091.html
http://www.ihoyoo.com/news/108259.html

相关文章:

  • 做网站一般都需要什么功能要怎么网络做推广
  • 网站如何创建首页怎么选择徐州网站开发
  • iis网站服务器安全隐患分析安徽城乡建设局网站
  • 永仁县工程建设信息网站温州网站建设钱
  • 公司网站怎么做站外链接申请网站服务器
  • 萧县做网站的公司国家信用信息企业公示网官网
  • 东莞网站建设的公司南京网站优化工具
  • 做棋牌推广网站违法不新闻今天
  • 设计之窗网站如何撰写网站建设方案书
  • 怎么给喜欢的人做网站找人做网站一套多少钱
  • WordPress小说漫画主题国外seo快速排名工具
  • 郑州高端品牌网站建设招商加盟的网站应该怎么做
  • 淘宝客为什么做网站flash 网站带后台
  • html5手机网站实例百度链接收录
  • 网站优化怎么做 百度文库颍上建设局网站
  • 武威市凉州区建设局网站服装网站html模板
  • 免费学校网站模板htmlwordpress 网校插件
  • 静态动漫网站模板网页设计师培训和继续教育的机会
  • 网站 开发 备案代理企业自己做网站方法
  • 旧电脑怎么做网站网站模板 html
  • 汉中网站seo溧水区住房建设局网站
  • 山东济南网站制作wordpress 悬浮广告
  • 微信网站怎么写网站开发经理具备什么知识
  • WordPress网站图片预加载shopify和wordpress
  • 外贸营销型网站设计起名网站是怎么做的
  • 常平镇网站仿做企业网站最下面的那栏叫啥
  • 中介网站设计单页网站优化
  • win2012 iis配置网站书画艺术网站建设
  • vs 网站开发自己做网站百度会收录
  • 建设个人网站ip天天外链