您的位置:首页 > 房产 > 家装 > 外贸市场推广_如何制作一个网站包含多个网页_抖音营销软件_怎么开发网站

外贸市场推广_如何制作一个网站包含多个网页_抖音营销软件_怎么开发网站

2024/10/5 22:28:13 来源:https://blog.csdn.net/xuwenpeng/article/details/142165073  浏览:    关键词:外贸市场推广_如何制作一个网站包含多个网页_抖音营销软件_怎么开发网站
外贸市场推广_如何制作一个网站包含多个网页_抖音营销软件_怎么开发网站
基本配置
#主机清单文件
[root@harbor ansible]# cat hostlist
[web]
192.168.29.161
192.168.29.162
[es]
192.168.29.171
192.168.29.172
192.168.29.173
#查看所有被管理的主机
[root@harbor ansible]# ansible all --list-hostshosts (5):192.168.29.161192.168.29.162192.168.29.171192.168.29.172192.168.29.173
#查看web组中所有主机
[root@harbor ansible]# ansible web --list-hostshosts (2):192.168.29.161192.168.29.162
ansible远程管理方式
  • adhoc临时命令–>在命令行中执行管理命令
  • playbook剧本–>把管理任务用特定格式写到文件中
adhoc临时命令
  • 语法
ansible 主机或组列表 -m 模块 -a "参数"    # -a是可选的
ansible模块
#列出所有模块
[root@harbor ansible]# ansible-doc -l 
# 查看包含yum的模块名
[root@harbor ansible]# ansible-doc -l | grep yum
# 查看yum模块的帮助文档,按空格键向下翻页,按q退出
[root@harbor ansible]# ansible-doc yum
command模块
  • ansible默认模块,用于在远程主机上执行任意命令
  • command不支持shell特性,如管道、重定向
# 在所有被管主机上创建目录/tmp/demo
[root@harbor ansible]# ansible all -a "mkdir /tmp/demo"
# 查看we1的ip地址
[root@harbor ansible]# ansible web1 -a "ip a s"
[root@harbor ansible]# ansible web1 -a "ip a s | head"  # 报错
shell模块
  • 与command模块类似,但是支持shell特性,如管道、重定向
# 查看web1的ip地址,只显示前10行
[root@harbor ansible]# ansible web1 -m shell -a "ip a s | head"
script模块
# 在控制端创建脚本即可
[root@harbor ansible]# vim test.sh
#!/bin/bash
for user in user{1..5}
douseradd $userecho '123456' | passwd --stdin $user
done# 在webservers组的主机上执行脚本
[root@harbor ansible]# ansible webservers -m script -a "test.sh"
file模块
  • 可以创建文件、目录、链接等,还可以修改权限、属性等
  • 常用的选项:
    • path:指定文件路径
    • owner:设置文件所有者
    • group:设置文件所属组
    • state:状态。touch表示创建文件,directory表示创建目录,link表示创建软链接,absent表示删除
    • mode:设置权限
    • src:source的简写,源
    • dest:destination的简写,目标
#查看使用帮助
[root@harbor ansible]# ansible-doc file
... ...
EXAMPLES:- name: Change file ownership, group and permissions  # 忽略ansible.builtin.file:           # 模块名。以下是它的各种参数path: /etc/foo.conf           # 要修改的文件的路径owner: foo                    # 文件所有者group: foo                    # 文件的所有组mode: '0644'                  # 权限
... ...
# 在webservers组的主机上创建/tmp/file.txt
[root@harbor ansible]# ansible webservers -m file -a "path=/tmp/file.txt state=touch"   # touch是指如果文件不存在,则创建;如果存在则改变它的时间戳
# 在webservers组的主机上创建/tmp/demo目录
[root@harbor ansible]# ansible webservers -m file -a "path=/tmp/demo state=directory"
# 将webservers组的主机上/tmp/file.txt的属主改为sshd,属组改为adm,权限改为0777
[root@harbor ansible]# ansible webservers -m file -a "path=/tmp/file.txt owner=sshd group=adm mode='0777'"
[root@harbor ansible]# ansible webservers -a "ls -l /tmp/file.txt"
# 删除webservers组的主机上/tmp/file.txt
[root@harbor ansible]# ansible webservers -m file -a "path=/tmp/file.txt state=absent"    # absent英文缺席的、不存在的
# 删除webservers组的主机上/tmp/demo
[root@harbor ansible]# ansible webservers -m file -a "path=/tmp/demo state=absent"
# 在webservers组的主机上创建/etc/hosts的软链接,目标是/tmp/hosts.txt
[root@harbor ansible]# ansible webservers -m file -a "src=/etc/hosts dest=/tmp/hosts.txt state=link"
copy模块
  • 用于将文件从控制端拷贝到被控端
  • 常用选项:
    • src:源。控制端的文件路径
    • dest:目标。被控制端的文件路径
    • content:内容。需要写到文件中的内容
[root@harbor ansible]# echo "hello world" > hello.txt
# 将hello.txt拷贝到webservers主机的/root/
[root@harbor ansible]# ansible web-m copy -a "src=hello.txt dest=/root/"
# 在目标主机上创建/tmp/mytest.txt,内容是Hello World
[root@harbor ansible]# ansible web-m copy -a "content='Hello World' dest=/tmp/mytest.txt"
fetch模块
  • 与copy模块相反,copy是上传,fetch是下载
  • 常用选项:
    • src:源。被控制端的文件路径
    • dest:目标。控制端的文件路径
# 将webservers主机上的/etc/hostname下载到本地用户的家目录下
[root@harbor ansible]# ansible web -m fetch -a "src=/etc/hostname dest=~/"
#查看从远程主机上下载的文件
[root@harbor ansible]# tree /root
/root
├── 192.168.29.161
│   └── etc
│       └── hostname
├── 192.168.29.162
│   └── etc
│       └── hostname
lineinfile模块
  • 用于确保目标文件中有某一行内容
  • 常用选项:
    • path:待修改的文件路径
    • line:写入文件的一行内容
    • regexp:正则表达式,用于查找文件中的内容
#web组中的主机,/etc/issue中一定要有一行Hello World。如果该行不存在,则默认添加到文件结尾
[root@harbor ansible]# ansible web -m lineinfile -a "path=/etc/issue line='hello world'"
[root@web1 ~]# cat /etc/issue
\S
Kernel \r on an \m
hello world
# web组中的主机,把/etc/issue中有hello的行,替换成welcome to china
[root@harbor ansible]# ansible web -m lineinfile -a "path=/etc/issue line='welcome to china' regexp='hello'"
[root@web1 ~]# cat /etc/issue
\S
Kernel \r on an \m
welcome to china
replace模块
  • lineinfile会替换一行,replace可以替换关键词
  • 常用选项:
    • path:待修改的文件路径
    • replace:将正则表达式查到的内容,替换成replace的内容
    • regexp:正则表达式,用于查找文件中的内容
# 把web组中主机上/etc/issue文件中的china,替换成henan
[root@harbor ansible]# ansible web -m replace -a "path=/etc/issue replace='china' regexp='henan'"
[root@web1 ~]# cat /etc/issue
\S
Kernel \r on an \m
welcome to henan
user模块
  • 实现linux用户管理
  • 常用选项:
    • name:待创建的用户名
    • uid:用户ID
    • group:设置主组
    • groups:设置附加组
    • home:设置家目录
    • password:设置用户密码
    • state:状态。present表示创建,它是默认选项。absent表示删除
    • remove:删除家目录、邮箱等。值为yes或true都可以。
# 在web组中的主机上,创建edison用户
[root@harbor ansible]# ansible web -m user -a "name=edison"
[root@web1 ~]# cat /etc/passwd | grep edison
edison:x:1000:1000::/home/edison:/bin/bash
# 在web组中的主机上,创建dizzy用户,设置uid=1010,主组adm,附加组daemon,root,家目录/home/dizzy
[root@harbor ansible]# ansible web -m user -a "name=dizzy uid=1010 group=adm groups=daemon,root home=/home/dizzy"
# 设置water的密码是123456
# {{}}是固定格式,表示执行命令。password_hash是函数,sha512是加密算法,则password_hash函数将会把123456通过sha512加密变成zhangsan的密码
[root@harbor ansible]# ansible web -m user -a "name=water password={{'123456' | password_hash('sha512')}}"
#删除edison用户,不删除家目录
[root@harbor ansible]# ansible web -m user -a "name=edison state=absent"
[root@web1 ~]# ls /home
dizzy  edison  water
#删除water用户,同时删除家目录
[root@harbor ansible]# ansible web -m user -a "name=water state=absent remove=yes"
[root@web1 ~]# ls /home
dizzy  edison
group模块
  • 创建、删除组
  • 常用选项:
    • name:待创建的组名
    • gid:组的ID号
    • state:present表示创建,它是默认选项。absent表示删除
# 在web组中的主机上添加名为devops的组
[root@harbor ansible]# ansible web -m group -a "name=devops"
[root@web1 ~]# cat /etc/group | grep devops
devops:x:1000:
# 在web组中的主机上删除名为devops的组
[root@harbor ansible]# ansible web -m group -a "name=devops state=absent"

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com