ansible 自动化运维实战
千锋教育-云计算&网络安全教学团队
1.ansible 介绍
ansible是新出现的自动化运维工具,基于Python开发,集合了众多运维工具(puppet、cfengine、chef、func、fabric)的优点,
实现了批量系统配置、批量程序部署、批量运行命令等功能。
无客户端。
我们要学一些Ansible的安装和一些基本概念,然后我们会开始研究一些真正有意思的东西 – playbook,配置管理,部署以及语法编排.我们将会学习如何使用/usr/bin/ansible执行ad-hoc并行命令,我们还会学习ansible的核心有什么样的模块可供使用.当然以后你也可以写你自己的模块。
a.工作原理
2.install-安装部署
a.环境介绍
ansible 服务器
192.168.20.136
ansible 客户机
192.168.20.134
b.安装ansible服务
[root@zabbix-server ~]# yum install -y epel-*
[root@zabbix-server ~]# yum install -y ansible
c.域名解析
[root@zabbix-server ~]# vim /etc/hosts
192.168.20.136 ansible
192.168.20.134 host1
注意:客户机无需任何操作,只需要准备yum源即可。
生成密钥对并传送:
1) 在客户端生成密钥对
[root@server ~]# ssh-keygen -t rsa
[root@server ~]# ls .ssh/
id_rsa id_rsa.pub known_hosts
id_rsa 私钥
id_rsa.pub 公钥
2) 把公钥传送给服务器
[root@server ~]# ssh-copy-id -i 192.168.20.134
d.测试安装是否成功
检测部署是否完成
rpm -ql ansible
列出所有文件
rpm -qc ansible
查看配置文件
ansible --help
查看ansible帮助
ansible-doc -l
看所有模块(A10,华为,docker,EC2,aws等等广大厂商设备)
ansible-doc -s yum
看yum模块,了解其功能
install (`present' or `installed', `latest'), or remove (`absent' or `removed')
yum list
Package name
enablerepo
3.ansible基础使用
ansible基础
1.定义主机清单
vim /etc/ansible/hosts
host1
host2
host3
......
2.测试连通性
ansible localhost -m ping
测试host1连通性 -m 指定模块。什么功能ping只是其中一个模块。还有shell,yum等等
3.简洁输出
ansible host1 -m ping -o
ansible host1 -m ping -u root -k -o
增加用户名选项
增加密码选项
去掉(yes/no)的询问
vim /etc/ssh/ssh_config
StrictHostKeyChecking no
systemctl restart sshd
ansible host1 -m ping -u root -k -o
成功不提示
5.错误示范
ansible host4 -m ping -u root -k -o
失败,主机清单未标注主机。
6.请注意ping和ssh
ping
ICMP:网际消息管理协议
关闭host1主机的sshd进程,进行ping连通性测试。
再使用ansible对host1进行联通测试时,却是失败的。
结论ansible的ping,是探测ssh程序是否连接。不是icmp协议
ansible host1 -m ping -u root -k
4.ansible模块介绍使用
查看ansible支持的模块
[root@master ~]# ansible-doc -l
查看模块支持的参数
# ansible-doc <模块名称>
[root@master ~]# ansible-doc ping
ansible模块的说明:
# ansible <pattern> -m <module_name> [-a <arguments>]
1、ping
检测被管理端是否在线
[root@master ~]# ansible test -m ping
192.168.87.102 | SUCCESS => {
"changed": false,
"ping": "pong"
}
[root@master ~]#
2、command
在被管理端执行命令 (常用命令)
不支持重定向,管道
默认模块
[root@master ~]# ansible test -m command -a 'uptime'
192.168.87.102 | SUCCESS | rc=0 >>
19:02:25 up 1:02, 3 users, load average: 0.00, 0.00, 0.00
[root@master ~]# ansible test -m command -a 'date'
192.168.87.102 | SUCCESS | rc=0 >>
Fri Dec 2 19:02:43 CST 2016
[root@master ~]# ansible test -m command -a 'touch /tmp/aa.txt'
192.168.87.102 | SUCCESS | rc=0 >>
[root@master ~]# ansible test -m command -a 'ls /tmp'
192.168.87.102 | SUCCESS | rc=0 >>
aa.txt
ansible_Rp0Uws
yum.log
[root@master ~]# ansible test -a "ls /tmp"
192.168.87.102 | SUCCESS | rc=0 >>
aa.txt
ansible_SaISP7
yum.log
参数:
chdir=<Directory>
[root@master ~]# ansible test -m command -a "chdir=/tmp ls ./"
192.168.87.102 | SUCCESS | rc=0 >>
aa.txt
ansible_zYCyTU
yum.log
[root@master ~]#
3、shell
在被管理端执行命令 (常用命令)
支持重定向,管道
[root@master ~]# ansible test -m shell -a 'echo "hello ansible" > /tmp/bb.txt'
192.168.87.102 | SUCCESS | rc=0 >>
[root@master ~]# ansible test -m shell -a "ls /tmp"
192.168.87.102 | SUCCESS | rc=0 >>
aa.txt
ansible_D4YLv4
bb.txt
yum.log
[root@master ~]#
参数:
chdir=<Directory>
[root@master ~]# ansible test -m shell -a "chdir=/tmp ls ./"
192.168.87.102 | SUCCESS | rc=0 >>
aa.txt
ansible_0umV5w
bb.txt
yum.log
4.copy模块
拷贝ansible管理端的文件到远程主机的指定位置
常见参数有:
dest= 指明拷贝文件的目标目录位置,使用绝对路径,如果源是目录,则目标也要是目录,如果目标文件已存在,会覆盖原有内容
src= 指明本地路径下的某个文件,可以使用相对路径和绝对路径,支持直接指定目录,如果源是目录,则目标也要是目录
mode= 指明复制时,目标文件的权限
owner= 指明复制时,目标文件的属主
group= 指明复制时,目标文件的属组
content= 指明复制到目标主机上的内容,不能与src一起使用,相当于复制content指明的数据,到目标文件中
[root@master ~]# ansible test -m copy -a "src=/etc/hosts dest=/tmp"
192.168.87.102 | SUCCESS => {
"changed": true,
"checksum": "7335999eb54c15c67566186bdfc46f64e0d5a1aa",
"dest": "/tmp/hosts",
"gid": 0,
"group": "root",
"md5sum": "54fb6627dbaa37721048e4549db3224d",
"mode": "0644",
"owner": "root",
"size": 158,
"src": "/root/.ansible/tmp/ansible-tmp-1480678980.74-146396715953485/source",
"state": "file",
"uid": 0
}
[root@master ~]# ansible test -m copy -a "src=/etc/passwd dest=/tmp mode=600 owner=nobody group=nobody"
192.168.87.102 | SUCCESS => {
"changed": true,
"checksum": "aa66816b64b79345d60de19b642cc7e62020038f",
"dest": "/tmp/passwd",
"gid": 99,
"group": "nobody",
"md5sum": "d97afe1f271c470a54f1f0763f97ba81",
"mode": "0600",
"owner": "nobody",
"size": 947,
"src": "/root/.ansible/tmp/ansible-tmp-1480679085.29-206165455771870/source",
"state": "file",
"uid": 99
}
[root@master ~]# ansible test -m copy -a 'content="hello linux" dest=/tmp/cc.txt mode=600'
192.168.87.102 | SUCCESS => {
"changed": true,
"checksum": "223ce1d650508823f9dd51d8cb4b527ad3d03ca7",
"dest": "/tmp/cc.txt",
"gid": 0,
"group": "root",
"md5sum": "c5fe55563f6ea61e2b28be7c8a5835c2",
"mode": "0600",
"owner": "root",
"size": 11,
"src": "/root/.ansible/tmp/ansible-tmp-1480679297.69-177631978154126/source",
"state": "file",
"uid": 0
}
5.fetch模块
从远程主机拉取文件到本地
一般情况下,只会从一个远程节点拉取数据
常见参数有:
dest= 从远程主机上拉取的文件存放在本地的位置,一般只能是目录
src= 指明远程主机上要拉取的文件,只能是文件,不能是目录
[root@master ~]# ansible test -m fetch -a 'src=/etc/passwd dest=/tmp'
192.168.87.102 | SUCCESS => {
"changed": true,
"checksum": "974b44c114ecbd71bdee11e09a9bc14c9b0395bd",
"dest": "/tmp/192.168.87.102/etc/passwd",
"md5sum": "01d72332a8d9737631212995fe1494f4",
"remote_checksum": "974b44c114ecbd71bdee11e09a9bc14c9b0395bd",
"remote_md5sum": null
}
6.file模块
用于设定远程主机上的文件属性
常见参数有:
path= 指明对哪个文件修改其属性
src= 指明path=指明的文件是软链接文件,其对应的源文件是谁,必须要在state=link时才有用
state=directory|link|absent 表示创建的文件是目录还是软链接
owner= 指明文件的属主
group= 指明文件的属组
mode= 指明文件的权限
创建软链接的用法:
src= path= state=link
修改文件属性的用法:
path= owner= mode= group=
创建目录的用法:
path= state=directory
删除文件:
path= state=absent
创建软连接
[root@master ~]# ansible test -m file -a 'src=/etc/passwd path=/tmp/passwd.link state=link'
192.168.87.102 | SUCCESS => {
"changed": true,
"dest": "/tmp/passwd.link",
"gid": 0,
"group": "root",
"mode": "0777",
"owner": "root",
"size": 11,
"src": "/etc/passwd",
"state": "link",
"uid": 0
}
删除文件
[root@master ~]# ansible test -m file -a 'path=/tmp/cc.txt state=absent'
192.168.87.102 | SUCCESS => {
"changed": true,
"path": "/tmp/cc.txt",
"state": "absent"
}
修改文件属性
[root@master ~]# ansible test -m file -a 'path=/tmp/bb.txt mode=700 owner=root group=nobody'
192.168.87.102 | SUCCESS => {
"changed": true,
"gid": 99,
"group": "nobody",
"mode": "0700",
"owner": "root",
"path": "/tmp/bb.txt",
"size": 14,
"state": "file",
"uid": 0
}
[root@master ~]# ansible test -m shell -a 'ls -l /tmp/bb.txt'
192.168.87.102 | SUCCESS | rc=0 >>
-rwx------ 1 root nobody 14 Dec 2 2016 /tmp/bb.txt
[root@master ~]#
创建目录
[root@master ~]# ansible test -m file -a 'path=/tmp/bj state=directory'
192.168.87.102 | SUCCESS => {
"changed": true,
"gid": 0,
"group": "root",
"mode": "0755",
"owner": "root",
"path": "/tmp/bj",
"size": 4096,
"state": "directory",
"uid": 0
}
删除目录
[root@master ~]# ansible test -m file -a 'path=/tmp/bj state=absent'
192.168.87.102 | SUCCESS => {
"changed": true,
"path": "/tmp/bj",
"state": "absent"
}
[root@master ~]# ansible test -m shell -a 'ls -l /tmp'
192.168.87.102 | SUCCESS | rc=0 >>
total 16
-rw-r--r-- 1 root root 0 Dec 2 2016 aa.txt
drwx------ 2 root root 4096 Dec 2 13:41 ansible_twMJYb
-rwx------ 1 root nobody 14 Dec 2 2016 bb.txt
-rw-r--r-- 1 root root 158 Dec 2 2016 hosts
-rw------- 1 nobody nobody 947 Dec 2 2016 passwd
lrwxrwxrwx 1 root root 11 Dec 2 13:35 passwd.link -> /etc/passwd
-rw------- 1 root root 0 Dec 2 00:58 yum.log
7.yum模块
基于yum机制,对远程主机管理程序包
常用参数有:
name= 指明程序包的名称,可以带上版本号,不指明版本,就是默认最新版本
name=httpd
name=httpd-2.2.15
state=present|lastest|absent 指明对程序包执行的操作,present表示安装程序包,latest表示安装最新版本的程序包,absent表示卸载程序包
disablerepo= 在用yum安装时,临时禁用某个仓库,仓库的ID
enablerepo= 在用yum安装时,临时启用某个仓库,仓库的ID
conf_file= 指明yum运行时采用哪个配置文件,而不是使用默认的配置文件
disable_gpg_check=yes|no 是否启用gpg-check
卸载软件包:
[root@master ~]# ansible test -m yum -a 'name=httpd state=absent'
[root@master ~]# ansible test -m shell -a 'rpm -q httpd'
安装软件包:
[root@master ~]# ansible test -m yum -a 'name=httpd state=present'
8.service模块
用来管理远程主机上的服务的模块
常见参数有:
name= 被管理的服务名称(/etc/init.d)
state=started|stopped|restarted 表示启动或关闭或重启
enabled=yes|no 表示要不要设定该服务开机自启动
runlevel= 如果设定了enabled开机自动启动,则要定义在哪些运行级别下自动启动
[root@master ~]# ansible test -m service -a 'name=nginx state=started'
192.168.87.102 | SUCCESS => {
"changed": true,
"name": "nginx",
"state": "started"
}
[root@master ~]# ansible test -m shell -a 'service nginx status'
192.168.87.102 | SUCCESS | rc=0 >>
nginx (pid 4054) is running...
[root@master ~]#
[root@master ~]# ansible test -m service -a 'name=nginx state=stopped'
192.168.87.102 | SUCCESS => {
"changed": true,
"name": "nginx",
"state": "stopped"
}
[root@master ~]# ansible test -m shell -a 'service nginx status'
192.168.87.102 | FAILED | rc=3 >>
nginx is stopped
[root@master ~]# ansible test -m service -a 'name=nginx state=started enabled=yes runlevel=2345'
192.168.87.102 | SUCCESS => {
"changed": true,
"enabled": true,
"name": "nginx",
"state": "started"
}
[root@master ~]# ansible test -m shell -a 'chkconfig --list nginx'
192.168.87.102 | SUCCESS | rc=0 >>
nginx 0:off 1:off 2:on 3:on 4:on 5:on 6:off
5.Inventory -主机清单
含义
清查;存货清单;财产目录;主机清单
1 增加主机组
官方链接
http://docs.ansible.com/ansible/intro_inventory.html#
vim /etc/ansible/hosts
[webserver]
host1
host2
host3
host4
ansible webserver -m ping -o
输出提示
[root@localhost ~]# ansible webserver -m ping -u root -k -o
SSH password:
host3 | SUCCESS => {"changed": false, "ping": "pong"}
host1 | SUCCESS => {"changed": false, "ping": "pong"}
host4 | SUCCESS => {"changed": false, "ping": "pong"}
host2 | SUCCESS => {"changed": false, "ping": "pong"}
2 增加用户名 密码
2 增加用户名 密码
vim /etc/ansible/hosts
[webserver]
host[1:4] ansible_ssh_user='root' ansible_ssh_pass='666666'
注意您的密码与教材中不同。
ansible webservers -m ping -o
免用户名和密码成功
请思考主机和主机的用户名密码不同。如何设置?
[webservers]
host1 ansible_ssh_user='root' ansible_ssh_pass='777777'
host[2:4] ansible_ssh_user='root' ansible_ssh_pass='666666'
3 增加端口
3 增加端口
请将host1的sshd程序端口修改为2222
# vim /etc/ssh/sshd_config
Port 2222
# systemctl restart sshd
ansible webservers -m ping -o
失败,因为默认端口已更改
vim /etc/ansible/hosts
[webserver]
host1 ansible_ssh_user='root' ansible_ssh_pass='777777' ansible_ssh_port='2222'
host[2:4] ansible_ssh_user='root' ansible_ssh_pass='666666'
请将用户名密码和端口回复原状
4 组:变量
ansible内部变量可以帮助我们简化主机清单的设置
vim /etc/ansible/hosts
[webserver]
host[1:4]
[webserver:vars]
ansible_ssh_user='root'
ansible_ssh_pass='666666'
常用变量
5 子分组
5 子分组
将不同的分组进行组合
vim /etc/ansible/hosts
[apache]
host[1:2]
[nginx]
host[3:4]
[webserver:children]
apache
nginx
[webserver:vars]
ansible_ssh_user='root'
ansible_ssh_pass='666666'
6 自定义主机列表
6 自定义主机列表
vim hostlist
[dockers]
host1
host2
[dockers:vars]
ansible_ssh_user='root'
ansible_ssh_pass='666666'
注意您的计算机密码
ansible -i hostlist dockers -m ping -o
6.Ad-Hoc-点对点模式
简介
临时的,在ansible中是指需要快速执行的单条命令,并且不需要保存的命令。对于复杂的命令则为 playbook。
1.shell模块
1.shell模块
帮助
ansible-doc shell
ansible webserver -m shell -a 'hostname' -o
获取主机名
ansible webserver -m shell -a 'hostname' -o -f 2
-f 2 指定线程数
-f FORKS, --forks=FORKS Ansible一次命令执行并发的线程数。NUM被指定为一个整数,默认是5
specify number of parallel processes to use
(default=5)
ansible host2 -m shell -a 'yum -y install httpd' -o
部署apache
ansible host3 -m shell -a 'uptime' -o
查询系统负载
2.复制模块
2.复制模块
帮助
ansible-doc copy
案例
ansible webserver -m copy -a 'src=/etc/hosts dest=/tmp/2.txt owner=root group=bin mode=777'
ansible webserver -m copy -a 'src=/etc/hosts dest=/tmp/2.txt owner=root group=bin mode=777 backup=yes'
如果文件有多份,可以进行备份。
[root@localhost ~]# ls /tmp/
2.txt 2.txt.17037.2017-11-16@16:23:41~
3.用户模块
3.用户模块
帮助
ansible-doc user
创建用户
ansible webserver -m user -a 'name=qianfeng state=present'
创建
删除用户
ansible webserver -m user -a 'name=qianfeng state=absent'
删除
修改密码
1.生成加密密码
echo '777777' | openssl passwd -1 -stdin
生成加密密码值
$1$XVzsJMDr$5wI4oUaQ.emxap6s.N272.
2.修改密码
ansible webserver -m user -a 'name=qianfeng password="$1$XVzsJMDr$5wI4oUaQ.emxap6s.N272."'
修改shell
ansible webserver -m user -a 'name=qianfeng shell=/sbin/nologin append=yes'
追加
4.软件包管理
4.软件包管理
帮助
ansible-doc yum
ansible host1 -m yum -a 'name="*" state=latest'
升级所有包
ansible host2 -m yum -a 'name="httpd" state=latest'
安装apache
5.服务模块
5.服务模块
帮助
ansible-doc service
ansible host2 -m service -a 'name=httpd state=started'
启动
ansible host2 -m service -a 'name=httpd state=started enabled=yes'
开机启动
ansible host2 -m service -a 'name=httpd state=stopped'
停止
ansible host2 -m service -a 'name=httpd state=restarted'
重启
ansible host2 -m service -a 'name=httpd state=started enabled=no'
开机禁止启动
6.文件模块
6.文件模块
帮助
ansible-doc file
ansible host1 -m file -a 'path=/tmp/88.txt mode=777 state=touch'
创建文件
ansible host1 -m file -a 'path=/tmp/99 mode=777 state=directory'
7.收集模块
7.收集模块
帮助
ansible-doc setup
ansible host3 -m setup
查询所有信息
ansible host3 -m setup -a 'filter=ansible_all_ipv4_addresses'
7.YAML-YAML Ain’t Markup Language-非标记语言
语法
列表
fruits:
- Apple
- Orange
- Strawberry
- Mango
字典
martin:
name: Martin D'vloper
job: Developer
skill: Elite
需求
通过YAML编写一个简单的剧本,完成web的部署,配置,启动的全过程。
ansible服务器
准备工作
ansible all -m yum -a 'name=httpd state=removed' -o
清理一下环境
yum install -y httpd
准备配置文件
mkdir apache
cd apache
cp -rf /etc/httpd/conf/httpd.conf .
grep '^Listen' httpd.conf
Listen 8080
修改配置,用作推送
编写剧本
vim apache.yaml
- hosts: host2
tasks:
- name: install apache packages
yum: name=httpd state=present
- name: copy apache conf
copy: src=./httpd.conf dest=/etc/httpd/conf/httpd.conf
- name: ensure apache is running
service: name=httpd state=started enabled=yes
测试:
ansible-playbook apache.yaml --syntax-check
检验语法
ansible-playbook apache.yaml --list-tasks
列出任务
ansible-playbook apache.yaml --list-hosts
列出主机
ansible-playbook apache.yaml
执行
http://192.168.2.142:8080/
注意端口
handlers
如果配置文件发生变化。
Listen 9000
ansible-playbook apache.yaml
再次执行,命令成功,但配置未生效,所以要增加处理程序。设置触发器
vim apache.yaml
如果配置文件再发生变化。
Listen 9080
ansible-playbook apache.yaml
再次执行,配置生效,触发成功
8.Role-角色扮演
简介
roles则是在ansible中,playbooks的目录组织结构。
将代码或文件进行模块化,成为roles的文件目录组织结构,
易读,代码可重用,层次清晰。
目标
通过role远程部署nginx并配置
1.目录结构
nginx 角色名
files 普通文件
handlers 触发器程序
tasks 主任务
templates 金甲模板(有变量的文件)
vars 自定义变量
准备目录结构
mkdir roles/nginx/{files,handlers,tasks,templates,vars} -p
touch roles/site.yaml roles/nginx/{handlers,tasks,vars}/main.yaml
echo 1234 > roles/nginx/files/index.html
yum install -y nginx && cp /etc/nginx/nginx.conf roles/nginx/templates/nginx.conf.j2
2.编写任务
vim roles/nginx/tasks/main.yaml
---
- name: install epel-release packge
yum: name=epel-release state=latest
- name: install nginx packge
yum: name=nginx state=latest
- name: copy index.html
copy: src=index.html dest=/usr/share/nginx/html/index.html
- name: copy nginx.conf template
template: src=nginx.conf.j2 dest=/etc/nginx/nginx.conf
notify: restart nginx
- name: make sure nginx service running
service: name=nginx state=started enabled=yes
对迭代项的引用,固定变量名为"item”,使用with_item属性给定要迭代的元素;
3.准备配置文件
vim roles/nginx/templates/nginx.conf.j2
worker_processes {{ ansible_processor_cores }};
调用内部已知变量
worker_connections {{ worker_connections }};
自定义变量
4.编写变量
vim roles/nginx/vars/main.yaml
worker_connections: 10240
5.编写处理程序
vim roles/nginx/handlers/main.yaml
---
- name: restart nginx
service: name=nginx state=restarted
6.编写剧本
vim roles/site.yaml
- hosts: host4
roles:
- nginx
7.实施
7.实施
cd roles
ansible-playbook site.yaml --syntax-check
测试
ansible-playbook site.yaml
实施剧本
验证host4
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-TmLvnBZw-1583245954054)(C:\Users\17801\AppData\Roaming\Typora\typora-user-images\image-20200303172045729.png)]
9.Homework
了解行业背景知识
==采购服务器并托管==
1. 了解DELL常见服务器的价格、型号、配置(CPU,内存、硬盘、支持的RAID功能)(3款)
2. 了解HP常见服务器的价格、型号、配置(CPU,内存、硬盘、支持的RAID功能)(3款)
3. 了解常见的硬盘接口类型、速率、价格如:ATA, SATA, SCSI, SAS, FC(3款)
4. 了解国内主要是北京托管商的信息如:厂商名称、托管的价格、地理位置(光环新网/世纪互联)(3家)
==云主机==
1. 了解青云qingcloud.com如价格、基本部署
2. 了解阿里云价格、基本部署
3. 了解阿亚马逊云价格、基本部署
4. 了解腾讯云价格、基本部署
==DNS 解析==
1. 了解国内主要的DNS ISP如万网、新网、DNSPOD、阿里DNS
2. 申请自己的域名,学习在DNS管理界面上添加各种记录
==CDN 技术==
1.了解国内主要的3家CDN ISP,对比其价格、性能、市场的占有率等
2.了解主要CDN购买及使用方式
3.了解反向代理技术Varnish原理及部署
4.查看126.com,sina.com, baidu.com使用的代理机制
[root@tianyun ~]# curl -I http http://www.126.com
DELL R730
戴尔PowerEdge R730 机架式服务器(Xeon E5-2603 V3/8GB/1.2TB)
所属:
戴尔 PowerEdge R730 机架式
产品类别:机架式
CPU型号:Xeon E5-2603 v3 1.6GHz
标配CPU数量:1颗
内存容量:8GB DDR4
标配硬盘容量:1.2TB
内部硬盘架数:最大支持16块2.5英寸硬盘-使用1.2TB热插拔SAS硬盘最高可配19.2TB
网络控制器:四端口千兆网
¥1.18万 2019-02-07
DELL R740
戴尔PowerEdge R740 机架式服务器(R740-A420805CN)
所属:
戴尔 PowerEdge R740 机架式
产品类别:机架式
CPU型号:Xeon Bronze 3104 1.7GHz
标配CPU数量:1颗
内存容量:8GB DDR4
标配硬盘容量:600GB*2
内部硬盘架数:前置硬盘托架: 高达16×2.5"SAS/SATA/SSD,最大60TB 高达8×3.5"SAS/SATA,最大80TB
网络控制器:QLogic FastL
¥1.84万 2019-02-07
DELL R940
戴尔PowerEdge R940 机架式服务器(R940-A420813CN)
所属:
戴尔 PowerEdge R940 机架式
产品类别:机架式
CPU型号:Xeon Gold 5120 2.2GHz
标配CPU数量:2颗
内存容量:32GB DDR4
标配硬盘容量:1.2TB
内部硬盘架数:最大支持8块2.5英寸硬盘
网络控制器:Broadcom 572
¥8.82万 2019-02-07
服务器托管费用示例
服务器托管的收费依据,服务器托管按照空间大小、电量消耗、以及带宽大小、IP数量还有机房等级来确定收费的。一般来说最低的托管配置是:
托管规格:1U
机柜功率:1A/220V
带宽:10M独享
IP地址:1个
电力:1A
网络线路:BGP线路
这个配置的托管,目前九河互联深圳数据中心月付是699元,年付6999元。在国内这个价格算是非常便宜的了,当然更重要的是上述网络是阿里云BGP,稳定性和性价比都非常优越。
百度云CDN计费标准
百度云CDN计费标准
按使用流量计费:CDN内容分发是按下行流量计费方式,是一种后付费模式;用户可以按照时间使用的流量付费,也可以通过购买流量包来抵扣;
按日峰值带宽计费:日峰值计费模式不限流量,日峰值带宽是指CDN每天的最高峰值,按照当天的最高CDN峰值计费,默认日峰值带宽上限是100Gbps;
注意:CDN按日峰值带宽计费和按流量计费可以相互切换,提交切换申请后,在第二日零点生效。用户可以根据自身的实际情况选择最优的付费模式,例如:平时流量较少的用户可以选择按流量计费。
一:按使用流量计费价格表
流量阶梯 折扣价(元/GB)
0GB-10TB(含) 0.20
10TB-50TB(含) 0.17
50TB-100TB(含) 0.14
100TB-1PB(含) 0.12
大于1PB 0.10
举例说明:
如累计消耗流量为10300GB,则其中10000G属于0GB–10TB阶梯内,单价为0.20元/GB。剩下的300G在10TB-50TB阶梯内,则单价为0.17元/GB。则总账单金额为10000GB ∗ 0.20元/GB+300GB ∗ 0.17元/GB=2051元。
当然,用户也可以通过购买流量包的形式来抵扣CDN所产生的流量,流量包计费说明参考:百度云CDN流量包收费价格表
二:按日峰值带宽计费
规格 单价(元/Mbps/日)
0~500Mbps(含) 0.52
500Mbps-5Gbps(含) 0.51
5Gbps-20Gbps(含) 0.48
大于20Gbps 0.47
举例说明:
用户当日的峰值带宽为912Mbps,则用户的账单费用应为912 ∗ 0.51元=465.12元。
如何在ansible中,使用不同的用户登录不同的主机?
在主机清单里设置
[webservers`]
asdf.example.com ansible_port=5000 ansible_user=alice ansible_pass=123456
jkl.example.com ansible_port=5001 ansible_user=bob ansible_pass=654321
如何加密hosts主机清单文件
[root@node1 ansible]# cat db_hosts
localhost ansible_connection=local
[root@node1 ansible]# ansible-vault encrypt db_hosts
New Vault password:
Confirm New Vault password:
Encryption successful
[root@node1 ansible]# ansible -i db_hosts localhost -m ping
ERROR! Decryption failed
Decryption failed
[root@node1 ansible]# ansible -i db_hosts --ask-vault-pass localhost -m ping
Vault password:
localhost | SUCCESS => {
"changed": false,
"ping": "pong"
}
[root@node1 ansible]# cat db_hosts
$ANSIBLE_VAULT;1.1;AES256
61663966666265363465653064386666326234353433346163633838366532366236313032303636
6437313333333936396164663031633566613233343161650a333163333732616130343762636135
30303864663138643661393234336433313465623830333832663165393964353961323261373130
3135626236626435640a396338616563646532623966333337366365636665663563666432333539
61663632633130623733316232353836663366623136636432616332376266383263356264303765
6133616235363066356164653232326139643862653464623037
判断主机地址为10.18.46.37的主机。关闭该主机
- hosts: webserver
tasks:
- name: "shut down 10.18.46.37 systems"
command: /usr/sbin/init 0
when: ansible_all_ipv4_addresses == "10.18.46.37"
关闭两台呢?
- hosts: webserver
tasks:
- name: "shut down 10.18.46.37 systems"
command: /usr/sbin/init 0
when: (ansible_all_ipv4_addresses == "10.18.46.37") or(ansible_all_ipv4_addresses == "10.18.46.47")
循环创建多个用户
- hosts: host2
tasks:
- name: add several users
user: name={{ item }} state=present groups=wheel
with_items:
- testuser1
- testuser2
判断主机地址为10.18.46.37的主机。关闭该主机
- hosts: webserver
tasks:
- name: "shut down 10.18.46.37 systems"
command: /usr/sbin/init 0
when: ansible_all_ipv4_addresses == "10.18.46.37"
关闭两台呢?
- hosts: webserver
tasks:
- name: "shut down 10.18.46.37 systems"
command: /usr/sbin/init 0
when: (ansible_all_ipv4_addresses == "10.18.46.37") or(ansible_all_ipv4_addresses == "10.18.46.47")
循环创建多个用户
- hosts: host2
tasks:
- name: add several users
user: name={{ item }} state=present groups=wheel
with_items:
- testuser1
- testuser2