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

泉州网站优化排名三六五网做网站吗

泉州网站优化排名,三六五网做网站吗,品牌设计就业前景怎么样,登录注册入口#x1f618;作者简介#xff1a;一名运维工作人员。 #x1f44a;宣言#xff1a;人生就是B#xff08;birth#xff09;和D#xff08;death#xff09;之间的C#xff08;choise#xff09;#xff0c;做好每一个选择。 #x1f64f;创作不易#xff0c;动动小… 作者简介一名运维工作人员。 宣言人生就是Bbirth和Ddeath之间的Cchoise做好每一个选择。 创作不易动动小手给个点赞加关注吧有什么意见评论区告诉我。 目录 一、剧本playbook 1、介绍 2、剧本组成 3、剧本编写规范 4、实战编写搭建nginx的剧本 1本机安装nginx准备配置文件 2 编写剧本 3测试并执行剧本 测试剧本 执行剧本 测试web2的nginx  5、使用剧本的变量部署httpd 1本机安装httpd准备配置文件 2编写剧本 3检测脚本 4执行剧本 5使用web浏览器访问web1的9090端口  6、handlers 1更改nginx的配置文件 2编写剧本 3测试剧本 4运行剧本 5使用web浏览器访问web2的8888端口 7、template  1准备模板 2修改nginx剧本 3运行剧本并用查看web2的nginx的配置文件 8、tags模块 1编写剧本以创建目录为例 2运行剧本 3查看web2主机的/test目录 二、roles角色扮演 1、介绍 2、实战远程配置nginx 1目录结构 2准备目录 3准备file、template文件 4编写任务 5定义变量 6定义handlers 7编写剧本 8测试并运行剧本 9查看web2的配置文件并用web浏览器访问web2的8090端口 一、剧本playbook 1、介绍 playbook是ansible用于配置部署和管理被控节点的剧本。通过playbook的详细描述执行其中的tasks可以让远端主机达到预期的状态。playbook是由一个或多个”play”组成的列表。 当对一台机器做环境初始化的时候往往需要不止做一件事情这时使用playbook会更加适合。通过playbook你可以一次在多台机器执行多个指令。通过这种预先设计的配置保持了机器的配置统一并很简单的执行日常任务。 ansible通过不同的模块实现相应的管理管理的方式通过定义的清单文件(hosts)所管理的主机包括认证的方式连接的端口等。所有的功能都是通过调用不同的模块(modules)来完成不同的功能的。不管是执行单条命令还是play-book都是基于清单文件。 playbook格式playbook由YMAL语言编写。YMAL格式是类似于JSON的文件格式便于人理解和阅读同时便于书写。 2、剧本组成 剧本的角色play, 定义的是主机信息 剧本的任务task, 定义的是具体任务 playbook组成部分: 1 一个playbook有多个play组成 2 一个play可以包含多个task任务 3 简单理解为使用多个模块功能完成一件事 task         Variables变量         Templates模板         Handlers触发器当 changed 状态条件满足时notify触发执行的操作。 3、剧本编写规范 编写规范遵循yaml语法规范 缩进规范 两个空格表示一个缩进 不平级标题之间一定要开头相隔两个空格 注意: 缩进只能以空格表示 tab会报错。 字典规范 冒号后面必须要有空格 注意: 冒号结尾时不需要有空格 注释信息中冒号也不需要。 列表规范: 横线后面要有一个空格 4、实战编写搭建nginx的剧本 1本机安装nginx准备配置文件 #安装nginx这里我之前安装好的 [rootlocalhost ~]# yum install -y nginx 上次元数据过期检查0:40:12 前执行于 2023年07月26日 星期三 08时23分53秒。 软件包 nginx-1:1.22.1-2.el9.x86_64 已安装。 依赖关系解决。 无需任何处理。 完毕 #创建一个存放nginx配置文件的目录用作copy到远程服务器使用 [rootlocalhost ~]# mkdir /nginx [rootlocalhost ~]# cp /etc/nginx/nginx.conf /nginx/ #更改nginx的默认端口用作检测推送 [rootlocalhost ~]# sed -i /listen/s/80/8090/g /nginx/nginx.conf 2 编写剧本 [rootlocalhost ~]# vim nginx.yml [rootlocalhost ~]# cat nginx.yml - hosts: nginxtasks:- name: install nginxyum: namenginx statepresent- name: copy nginx confcopy: src/nginx/nginx.conf dest/etc/nginx/nginx.conf- name: start serviceservice: namenginx statestarted enabledyes 剧本解释 - hosts指定需要执行剧本的主机 tasks任务列表 - name类似于注释    ansible模块相关命令 3测试并执行剧本 ansible-playbook nginx.yml  --syntax-check        检验语法 ansible-playbook nginx.yml --list-tasks        列出任务 ansible-playbook nginx.yml --list-hosts        列出主机 ansible-playbook nginx.yml        执行 测试剧本 #测试剧本语法无报错即可报错根据报错提示去修改剧本 [rootlocalhost ~]# ansible-playbook nginx.yml --syntax-checkplaybook: nginx.yml #列出任务列表展示有哪些任务需要执行 [rootlocalhost ~]# ansible-playbook nginx.yml --list-tasksplaybook: nginx.ymlplay #1 (nginx): nginx TAGS: []tasks:install nginx TAGS: []copy nginx conf TAGS: []start service TAGS: [] #列出需要执行剧本的主机 [rootlocalhost ~]# ansible-playbook nginx.yml --list-hostsplaybook: nginx.ymlplay #1 (nginx): nginx TAGS: []pattern: [nginx]hosts (1):web2 执行剧本 [rootlocalhost ~]# ansible-playbook nginx.yml PLAY [nginx] ************************************************************************************************************************************************************ TASK [Gathering Facts] ************************************************************************************************************************************************** ok: [web2] #web2可以执行TASK [install nginx] **************************************************************************************************************************************************** changed: [web2] #web2安装了nginxTASK [copy nginx conf] ************************************************************************************************************************************************** changed: [web2] #拷贝配置文件到web2成功TASK [start service] **************************************************************************************************************************************************** changed: [web2] #启动nginx成功PLAY RECAP ************************************************************************************************************************************************************** web2 : ok4 changed3 unreachable0 failed0 skipped0 rescued0 ignored0 测试web2的nginx  用浏览器分别访问web2的80端口和8090端口。 80端口访问失败。 8090端口访问成功说明剧本执行成功web2的nginx配置文件是刚刚在ansible主机修改的配置文件。 5、使用剧本的变量部署httpd 在剧本中定义变量并使用变量比如部署软件的时候将软件的名字和配置文件的路径设置为变量这样一个剧本只需要更改变量即可完成剧本的复用。 下面在web1使用剧本部署httpd并且使用变量来测试。 1本机安装httpd准备配置文件 思路准备一个httpd文件夹将httpd配置文件拷贝到httpd文件夹备用并且更改配置文件的端口为9090以便检测远程主机的配置文件是否是推送过去的。 [rootlocalhost ~]# mkdir /httpd [rootlocalhost ~]# cp /etc/httpd/conf/httpd.conf /httpd/ [rootlocalhost ~]# sed -i /^Listen/s/80/9090/g /httpd/httpd.conf 2编写剧本 定义变量  vars:       - keyvalues 引用变量{{key}} [rootlocalhost ~]# vim http.yml [rootlocalhost ~]# cat http.yml - hosts: httpvars: #定义变量- pkg: httpd #包名- svc: httpd #服务名tasks:- name: install httpdyum: name{{pkg}} statepresent #引用包名变量- name: cpoy http confcopy: src/httpd/httpd.conf dest/etc/httpd/conf/httpd.conf- name: start httpd serviceservice: name{{svc}} statestarted enabledyes #引用服务名变量 3检测脚本 [rootlocalhost ~]# ansible-playbook http.yml --syntax-check [DEPRECATION WARNING]: Specifying a list of dictionaries for vars is deprecated in favor of specifying a dictionary. This feature will be removed in version 2.18. Deprecation warnings can be disabled by setting deprecation_warningsFalse in ansible.cfg.playbook: http.yml 4执行剧本 [rootlocalhost ~]# ansible-playbook http.yml [DEPRECATION WARNING]: Specifying a list of dictionaries for vars is deprecated in favor of specifying a dictionary. This feature will be removed in version 2.18. Deprecation warnings can be disabled by setting deprecation_warningsFalse in ansible.cfg.PLAY [http] *************************************************************************************************************************************************************TASK [Gathering Facts] ************************************************************************************************************************************************** ok: [web1]TASK [install httpd] **************************************************************************************************************************************************** changed: [web1]TASK [copy http conf] *************************************************************************************************************************************************** changed: [web1]TASK [start httpd service] ********************************************************************************************************************************************** changed: [web1]PLAY RECAP ************************************************************************************************************************************************************** web1 : ok4 changed3 unreachable0 failed0 skipped0 rescued0 ignored0 5使用web浏览器访问web1的9090端口  6、handlers 触发器当 changed 状态条件满足时notify触发执行的操作。 在需要执行触发器的位置设置 notify标记 然后在定义触发器 handlers  - name标记    触发执行命令 注意notify的标记要和handlers的标记要一致这里是一一对应的。 在配置文件发生改变的时候需要重启服务才能生效所以一般在拷贝配置文件任务那里添加一个notify在触发器位置执行重启服务器。 这里使用刚刚nginx的剧本来进行测试。 1更改nginx的配置文件 [rootlocalhost ~]# sed -i /listen/s/8090/8888/g /nginx/nginx.conf 将默认端口改为8888  2编写剧本 [rootlocalhost ~]# vim nginx.yml [rootlocalhost ~]# cat nginx.yml - hosts: nginxtasks:- name: install nginxyum: namenginx statepresent- name: copy nginx confcopy: src/nginx/nginx.conf dest/etc/nginx/nginx.confnotify: restart nginx service- name: update index.htmlshell: echo i am sure /usr/share/nginx/html/index.html- name: start serviceservice: namenginx statestarted enabledyeshandlers:- name: restart nginx serviceservice: namenginx staterestarted 3测试剧本 [rootlocalhost ~]# ansible-playbook nginx.yml --syntax-checkplaybook: nginx.yml 4运行剧本 5使用web浏览器访问web2的8888端口 成功 7、template  可以看作是一个编译过的模板文件用来产生目标文本传递Python的变量给模板去替换模板中的标记。 1准备模板 将原本的配置文件重命名改成.j2文件作为配置文件模板。 然后更改模板内容。 在主机清单定义一个变量 [rootlocalhost ~]# mv /nginx/nginx.conf /nginx/nginx.conf.j2 这里将模板文件的listen处改为使用变量ansible_http_port。 2修改nginx剧本 - hosts: nginxtasks:- name: install nginxyum: namenginx statepresent- name: nginx conftemplate: src/nginx/nginx.conf.j2 dest/etc/nginx/nginx.confnotify: restart nginx service- name: update index.htmlshell: echo i am sure /usr/share/nginx/html/index.html- name: start serviceservice: namenginx statestarted enabledyeshandlers:- name: restart nginx serviceservice: namenginx staterestarted 将原来的copy改为使用模板来推送配置文件 3运行剧本并用查看web2的nginx的配置文件 8、tags模块 可以在一个playbook中为某个或某些任务定义“标签”在执行此playbook时通过ansible-playbook命令使用–tags选项能实现仅运行指定的tasks。 playbook还提供了一个特殊的tags为always。作用就是当使用always当tags的task时无论执行哪一个tags时定义有always的tags都会执行。 1编写剧本以创建目录为例 [rootlocalhost ~]# cat tags.yml - hosts: nginxtasks:- name: mkdir dir1file: name/test/dir1 statedirectorytags:- first- name: mkdir dir2file: name/test/dir2 statedirectory- name: nkdir dir3file: name/test/dir3 statedirectorytags:- always 这里给dir1任务打了first的标签 给dir2任务没有打标签给dir3打了always的标签 2运行剧本 看到运行提示只有dir1和dir3被创建。 3查看web2主机的/test目录 [rootlocalhost ~]# ansible nginx -m shell -a ls /test web2 | CHANGED | rc0 dir1 dir3 发现只有dir1和dir3因为在运行剧本的时候加了tags“first”所以剧本中只有打first标签的任务和打always的任务被执行其余任务不会被执行。 二、roles角色扮演 1、介绍 roles则是在ansible中playbooks的目录组织结构。 将代码或文件进行模块化成为roles的文件目录组织结构 易读代码可重用层次清晰。 2、实战远程配置nginx 1目录结构 结构介绍 nginx 角色名files  普通文件用来存放由 copy 模块或 script 模块调用的文件。handlers  触发器程序此目录应当包含一个 main.yml 文件用于定义此角色中触发条件时执行的动作。tasks  主任务此目录应当包含一个 main.yml 文件用于定义此角色的任务列表此文件可以使用 include 包含其它的位于此目录的 task 文件。templates 金甲模板有变量的文件用来存放 j2 模板template 模块会自动在此目录中寻找 j2 模板文件。vars 自定义变量此目录应当包含一个 main.yml 文件用于定义此角色用到的变量。f除开files目录和templates目录不需要创建main.yml文件其余都要各个目录下都要创建 2准备目录 mkdir roles/nginx/{files,handlers,tasks,templates,vars} -p touch roles/site.yaml roles/nginx/{handlers,tasks,vars}/main.yaml [rootlocalhost ~]# tree roles/ roles/ ├── nginx │   ├── files │   ├── handlers │   │   └── main.yaml │   ├── tasks │   │   └── main.yaml │   ├── templates │   └── vars │   └── main.yaml └── site.yaml6 directories, 4 files 3准备file、template文件 制作nginx主页以及金甲模板并修改模板。 [rootlocalhost ~]# cp /nginx/nginx.conf.j2 roles/nginx/templates/ [rootlocalhost ~]# echo h1I am Sure Nginxh1/ roles/nginx/files/index.html [rootlocalhost ~]# tree roles/ roles/ ├── nginx │   ├── files │   │   └── index.html │   ├── handlers │   │   └── main.yaml │   ├── tasks │   │   └── main.yaml │   ├── templates │   │   └── nginx.conf.j2 │   └── vars │   └── main.yaml └── site.yaml 4编写任务 在tasks目录下的main.yaml写 [rootlocalhost ~]# cat roles/nginx/tasks/main.yaml tasks:- name: install nginxyum: name{{pkg}} statepresent- name: set nginx conftemplate: srcnginx.conf.j2 dest/etc/nginx/nginx.confnotify: restart nginx service- name: copy nginx indexcopy: srcindex.html dest/usr/share/nginx/html/index.html- name: start nginx serviceservice: name{{svc}} statestarted enabledyes 5定义变量 在vars目录下的main.yaml编写。 [rootlocalhost ~]# cat roles/nginx/vars/main.yaml port: 8090 work_connection: 1024 pkg: nginx svc: nginx 6定义handlers 在handlers目录下的main.yaml编写。 [rootlocalhost ~]# cat roles/nginx/handlers/main.yaml - name: restart nginx serviceservice: name{{svc}} staterestarted 7编写剧本 在site.yaml编写 剧本中的角色可以是多个这里是以一个nginx为例。 [rootlocalhost ~]# cat roles/site.yaml - hosts: nginxroles:- nginx8测试并运行剧本 [rootlocalhost ~]# ansible-playbook roles/site.yaml --syntax-checkplaybook: roles/site.yaml[rootlocalhost ~]# ansible-playbook roles/site.yaml [WARNING]: Found variable using reserved name: portPLAY [nginx] ************************************************************************************************************************************************************TASK [Gathering Facts] ************************************************************************************************************************************************** ok: [web2]TASK [nginx : install nginx] ******************************************************************************************************************************************** ok: [web2]TASK [nginx : set nginx conf] ******************************************************************************************************************************************* changed: [web2]TASK [nginx : copy nginx index] ***************************************************************************************************************************************** changed: [web2]TASK [nginx : start nginx service] ************************************************************************************************************************************** ok: [web2]RUNNING HANDLER [nginx : restart nginx service] ************************************************************************************************************************* changed: [web2]PLAY RECAP ************************************************************************************************************************************************************** web2 : ok6 changed3 unreachable0 failed0 skipped0 rescued0 ignored0 9查看web2的配置文件并用web浏览器访问web2的8090端口 [rootlocalhost ~]# ansible nginx -m shell -a cat /etc/nginx/nginx.conf | grep listen web2 | CHANGED | rc0 listen 8090;listen [::]:8090; # listen 443 ssl http2; # listen [::]:443 ssl http2; [rootlocalhost ~]# ansible nginx -m shell -a cat /etc/nginx/nginx.conf | grep worker_connection web2 | CHANGED | rc0 worker_connections 1024; web2的nginx的配置文件中发现端口为8090worker_connections是1024和刚刚设置的变量一致。  访问web2的8090端口展示的页面正是刚刚自己自定义的网络首页。
http://www.zqtcl.cn/news/72093/

相关文章:

  • 建了网站但是百度搜索不到wordpress主页内容修改
  • 自学网站建设工资淮北电子商务网站建设
  • 网站建设的最新技术数据调查的权威网站
  • 怎么注册一个网站免费的网站推广软件
  • 做网站用vs还是dw天津市建设工程协会网站
  • 天河区做网站ssr网站开发
  • 绵阳建设局官方网站汽车最好网站建设
  • 写作的网站有哪些建立企业网站的步骤
  • 清远网站seo公司hao123网站难做吗
  • 浙江华企做网站网站开发深圳
  • 网站开发需要干什么页面设计的怎么样
  • 江门网站制作服务沈阳专业工装公司
  • 做网站交互demo工具58同城兰州网站建设
  • 能够做代理的网站有哪些响应式网站模板多少钱
  • 网站前台后台网站的制作方法
  • 什么网站可以买世界杯呼叫中心系统软件
  • 怎样去各大网站做淘宝推广网站代理怎么做
  • 网业翻译成中文seo网站推广专员招聘
  • 网站重构工程师海口建站模板系统
  • 网站销售都怎么做的三拼域名做网站
  • 院校网站建设站长工具下载app
  • 唐河微网站建设p2p视频网站开发
  • 广东网站建设微信商城运营注册个公司一年需要多少费用
  • 长沙门户网站苏州街网站建设
  • 培训前端网站开发企业门户网站管理办法
  • 车墩做网站公司猪八戒上面还是淘宝上做网站技术好
  • 网站做电子链接标识申请好吗如何做网络营销宣传
  • 网站开发 税率dw网页制作软件官网
  • 网站设计案例网站什么是电商创业
  • 绵阳网站建设scmmwl设计建筑的软件