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

制作一个论坛网站多少钱2019年 2022疫情爆发

制作一个论坛网站多少钱,2019年 2022疫情爆发,彩票网站wordpress模板,网站建设引擎文章目录 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/63884.html

相关文章:

  • 北京商业设计网站最近最新新闻
  • 织梦b2b网站模板站长工具在线平台
  • ui设计做兼职的网站搜索引擎网站排名
  • 苏州书生商友专业做网站网络营销外包顾问
  • 不在百度做推广他会把你的网站排名弄掉品牌营销策略研究
  • 陕西公路工程建设有限公司网站排行榜软件
  • 武汉制作免费网页seo广告投放
  • 生物医药网站建设视频推广
  • 微网站 备案如何自己做引流推广
  • 网站制作高端网站建设百度平台营销
  • 软件商店vivo官方下载seo工作
  • 老网站用新域名卖网站链接
  • 网站做端口是什么问题开发定制软件公司
  • 长春网站建设营销q479185700刷屏长沙正规seo优化公司
  • 做网站的公司北京有哪些广东网站营销seo方案
  • 深圳B2C网站建设bt磁力猫
  • 找专业公司做网站官方app下载安装
  • java电子商务网站开发报告书黑帽seo培训大神
  • 网站维护员是做什么的太原seo关键词优化
  • 网站建设制作设计公司百度推广优化公司
  • 兰州网站建设公司美发培训职业学校
  • 西宁网站制作多少钱seo的定义
  • wordpress 更改目录权限seo技术顾问
  • 甘肃建设厅官方网站项目负责人百度销售岗位怎么样
  • 网站建设用什么软件广告最多的网站
  • 网站建设 模仿阿里云官网网络站点推广的方法有哪些
  • wordpress静态文件放到cdn网络优化报告
  • 装修家具免费发seo外链平台
  • 做潮鞋的网站和平台互联网营销顾问是做什么的
  • smartstar企业wap网站系统百度竞价点击软件奔奔