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

哪里网站可以有做那个的女人百度推广优化中心

哪里网站可以有做那个的女人,百度推广优化中心,wordpress搬家后空白,b2b电子商务模式的网站文章目录 Playbook核心元素hosts 组件remote_user 组件task列表和action组件其它组件ShellScripts VS Playbook 案例 playbook 命令利用 playbook 创建 mysql 用户playbook安装nginx利用 playbook 安装和卸载 httpd Playbook核心元素 Hosts 执行的远程主机列表Tasks 任务集Var…

文章目录

  • Playbook核心元素
    • hosts 组件
    • remote_user 组件
    • task列表和action组件
    • 其它组件
    • ShellScripts VS Playbook 案例
  • playbook 命令
    • 利用 playbook 创建 mysql 用户
    • playbook安装nginx
    • 利用 playbook 安装和卸载 httpd

Playbook核心元素

  • Hosts 执行的远程主机列表
  • Tasks 任务集
  • Variables 内置变量自定义变量,在playbook中调用
  • Templates 模板,可替换模板文件中的变量并实现一些简单逻辑的文件
    -Handlersnotify 结合使用,由特定条件触发的操作,满足条件方才执行,否则不执行
  • tags 标签 指定某条任务执行,用于选择运行playbook中的部分代码。ansible具有幂等性,因此会自动跳过没有变化的部分,即便如此,有些代码为测试其确实没有发生变化的时间依然会非常地长。此时,如果确信其没有变化,就可以通过tags跳过此些代码片断。

hosts 组件

Hosts:playbook中的每一个play的目的都是为了让特定主机以某个指定的用户身份执行任务。hosts用于指定要执行指定任务的主机,须事先定义在主机清单中:

one.example.com
one.example.com:two.example.com
192.168.1.50
192.168.1.*
linux101
Websrvs:dbsrvs      #或者,两个组的并集
Websrvs:&dbsrvs     #与,两个组的交集
webservers:!phoenix  #在websrvs组,但不在dbsrvs组

案例:

- hosts: webservers:appservers

remote_user 组件

remote_user: 可用于Host和task中。也可以通过指定其通过sudo的方式在远程主机上执行任务,其可用于play全局或某任务;此外,甚至可以在sudo时使用sudo_user指定sudo时切换的用户

当 Ansible playbook 与远程主机通信时,需要指定一个用户名和密码(或 SSH 私钥),以便连接到目标主机。
通过指定 remote_user,可以让 Ansible playbook 自动使用指定的用户名和密码(或 SSH 私钥)来连接目标主机。

---
- hosts: websrvsremote_user: roottasks:- name: test connectionping:remote_user: magedusudo: yes                 #默认sudo为rootsudo_user:wang        #sudo为wang

task列表和action组件

  • play的主体部分是task list,task list中有一个或多个task,各个task 按次序逐个在hosts中指定的所有主机上执行,即在所有主机上完成第一个task后,再开始第二个task.
  • task的目的是使用指定的参数执行模块,而在模块参数中可以使用变量。模块执行是幂等的,这意味着多次执行是安全的,因为其结果均一致
  • 每个task都应该有其name,用于playbook的执行结果输出,建议其内容能清晰地描述任务执行步骤。如果未提供name,则action的结果将用于输出

task两种格式:

  1. action: module arguments
  2. module: arguments 建议使用

注意:shell和command模块后面跟命令,而非key=value

范例:

---
- hosts: webserversremote_user: roottasks:#两个任务:安装和启动服务- name: install httpdyum: name=httpd - name: start httpdservice: name=httpd state=started enabled=yes

其它组件

某任务的状态在运行后为changed时,可通过“notify”通知给相应的handlers
任务可以通过"tags“打标签,可在ansible-playbook命令上使用-t指定进行调用

ShellScripts VS Playbook 案例

SHELL脚本实现

#!/bin/bash
# 安装Apache
yum install --quiet -y httpd 
# 复制配置文件
cp /tmp/httpd.conf /etc/httpd/conf/httpd.conf
cp/tmp/vhosts.conf /etc/httpd/conf.d/
# 启动Apache,并设置开机启动
systemctl enable --now httpd 

Playbook实现

---
- hosts: websrvsremote_user: roottasks:- name: "安装Apache"yum: name=httpd- name: "复制配置文件"copy: src=/tmp/httpd.conf dest=/etc/httpd/conf/- name: "复制配置文件"copy: src=/tmp/vhosts.conf dest=/etc/httpd/conf.d/- name: "启动Apache,并设置开机启动"service: name=httpd state=started enabled=yes

playbook 命令

  • 格式
ansible-playbook <filename.yml> ... [options]
  • 常见选项
    -C --check #只检测可能会发生的改变,但不真正执行操作
    --list-hosts #列出运行任务的主机
    --list-tags #列出tag
    --list-tasks #列出task
    --limit 主机列表 #只针对主机列表中的主机执行
    -v -vv -vvv #显示过程
    范例
ansible-playbook  file.yml  --check #只检测
ansible-playbook  file.yml  
ansible-playbook  file.yml  --limit webservers

利用 playbook 创建 mysql 用户

mkdir playbookcd playbook/
vim mysql_user.yml
---
- hosts: dbserversremote_user: roottasks:- { name: create group,group: name=mysql system=yes gid=306 }- name: create useruser: name=mysql shell=/sbin/nologin system=yes group=mysql uid=306 home=/data/mysql create_home=no
#检查文件是否有错误
ansible-playbook -C mysql_user.yml

在这里插入图片描述
还可以在yaml中增加一行gather_facts: no,禁止收集其他系统信息,增加运行速度:

---
- hosts: dbserversremote_user: rootgather_facts: notasks:- { name: create group,group: name=mysql system=yes gid=306 }- name: create useruser: name=mysql shell=/sbin/nologin system=yes group=mysql uid=306 home=/data/mysql create_home=no

在这里插入图片描述
执行:

ansible-playbook mysql_user.yml 

在这里插入图片描述

#查询是否新建成功
ansible dbservers -a 'id mysql'

在这里插入图片描述

ansible webservers -a 'ss -ntl'

在这里插入图片描述

playbook安装nginx

1.卸载httpd,因为httpd和nginx可能会有冲突

ansible webservers -m yum -a 'name=httpd state=absent'
  1. 创建playbook脚本
vim install_nginx.yml
---
#install nginx 
- hosts: webserversremote_user: rootgather_facts: notasks:- name: add group nginxgroup: name=nginx state=present- name: add user nginxgroup: name=nginx state=present group=nginx- name: Install Nginxyum: name=nginx state=present- name: Start Nginxservice: name=nginx state=started enabled=yes

3.检查playbook代码

ansible-playbook -C install_nginx.yml

如果显示安装nginx有问题,可以先安装epel-release

---
#install nginx 
- hosts: webserversremote_user: rootgather_facts: notasks:- name: add group nginxgroup: name=nginx state=present- name: add user nginxgroup: name=nginx state=present group=nginx- name: install epel-releaseyum: name=epel-release- name: Install Nginxyum: name=nginx- name: Start Nginxservice: name=nginx state=started enabled=yes
  1. 执行playbook安装
ansible-playbook install_nginx.yml 

在这里插入图片描述
5. 查看nginx网络状态

ansible webservers -a 'netstat -anp|grep nginx'

在这里插入图片描述
6. 如果打开网页无法显示nginx界面,可以尝试关掉远程主机的防火墙:

ansible webservers -a 'systemctl stop firewalld.service'
ansible webservers -a 'systemctl disable firewalld.service'

在这里插入图片描述
7. 可以替换ngnix原始网页,显示成自己的页面:

mkdir files
vim files/index.html
<!DOCTYPE html>  
<html lang="zh">  <head>  <meta charset="UTF-8">  <meta name="viewport" content="width=device-width, initial-scale=1.0">  <title>欢迎来到我的网站</title>  <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300&display=swap" rel="stylesheet">  <style>  body {  margin: 0;  padding: 0;  font-family: 'Roboto', sans-serif;  background-color: #f0f8ff;  color: #333;  display: flex;  justify-content: center;  align-items: center;  height: 100vh;  text-align: center;  }  h1 {  font-size: 48px;  margin: 0;  color: #4A90E2;  transition: color 0.3s;  }  h1:hover {  color: #1C74B7;  }  p {  font-size: 20px;  margin: 20px 0;  line-height: 1.5;  }  a {  text-decoration: none;  color: #fff;  background-color: #4A90E2;  padding: 10px 20px;  border-radius: 5px;  font-size: 18px;  transition: background-color 0.3s;  }  a:hover {  background-color: #1C74B7;  }  footer {  position: absolute;  bottom: 20px;  font-size: 14px;  color: #777;  }  </style>  
</head>  <body>  <div>  <h1>欢迎来到我的网站!</h1>  <p>这是一个简单而美观的欢迎界面。希望你能在这里找到你需要的信息。</p>  <a href="#" onclick="alert('感谢您的访问!')">点击我了解更多</a>  </div>  <footer>  &copy; 2023 我的网页版权所有  </footer>  
</body>  </html>
vim install_nginx.yml
---
#install nginx 
- hosts: webserversremote_user: rootgather_facts: notasks:- name: add group nginxgroup: name=nginx state=present- name: add user nginxgroup: name=nginx state=present group=nginx- name: install epel-releaseyum: name=epel-release- name: Install Nginxyum: name=nginx- name: web pagecopy: src=files/index.html dest=/usr/share/nginx/html/index.html- name: Start Nginxservice: name=nginx state=started enabled=yes
  1. 重新运行
ansible-playbook install_nginx.yml 

在这里插入图片描述
在这里插入图片描述

利用 playbook 安装和卸载 httpd

本地先安装httpd

yum install httpd
cp /etc/httpd/conf/httpd.conf files/
vim files/httpd.conf

在这里插入图片描述

vim install_httpd.yml
---
#install httpd 
- hosts: webserversremote_user: rootgather_facts: notasks:- name: Install httpdyum: name=httpd state=present- name: Install configure filecopy: src=files/httpd.conf dest=/etc/httpd/conf/- name: web htmlcopy: src=files/index.html  dest=/var/www/html/- name: start serviceservice: name=httpd state=started enabled=yes
#先把nginx停掉
ansible webservers -m servers -a 'name=nginx state=stopped'
ansible-playbook -C install_httpd.yml
ansible-playbook  install_httpd.yml

在这里插入图片描述

---
- hosts: webserversremote_user: rootgather_facts: notasks:- name: remove httpd packageyum: name=httpd state=absent- name: remove apache useruser: name=apache state=absent- name: remove config filefile: name=/etc/httpd  state=absent- name: remove web htmlfile: name=/var/www/html/index.html state=absent
ansible-playbook -C remove_httpd.yml 
ansible-playbook  remove_httpd.yml 
http://www.dtcms.com/wzjs/102528.html

相关文章:

  • wap建站系统seo的优化技巧有哪些
  • 泉州网站建设技术支持百度一下浏览器
  • wordpress富编辑器seo网站关键词快速排名
  • 保山市城乡建设局网站谷歌搜索引擎363入口
  • 可以做宣传的网站谷歌搜索引擎大全
  • 公司网站一般多少钱如何自己建个网站
  • 哪个网站做的最好广州网站优化服务商
  • 人才网网站开发手册在线优化工具
  • 日本可以自己做网站吗百度账号登录个人中心
  • 网站建设动图代码360收录提交
  • 学校网站建设教程百度站长工具排名
  • 仪征网站建设整站优化要多少钱
  • 做网站需要注意多少页百度推广竞价排名
  • 邢台做企业网站制作网站要找什么公司
  • 郑州大学动态网站开发考试答案百度新闻排行榜
  • 做网站用宋体有版权问题吗成全在线观看免费高清动漫
  • 深圳建设局网站电商运营自学网站
  • 百度站长平台链接网络工程师是干什么的
  • 电子商务网站开发需要注意问题短网址生成网站
  • 做淘客网站品牌营销策划公司哪家好
  • 怎么做钓鱼网站生成做网站的步骤
  • 企业定制网站建设公司什么是口碑营销
  • 婚恋网站开发平台代理招商线上推广活动有哪些
  • 做水果网站用什么域名什么软件可以找客户资源
  • 深圳网站建设哪个平台好网页搜索排名提升
  • 关于国际贸易的网站网络整合营销理论
  • 网站建设列表销售外包公司
  • cnd中国室内设计网排名优化
  • 安庆做网站哪个公司好seo快速排名关键词
  • 做网站是什么专业什么工作个人建网站需要多少钱