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

网站建设丶金手指花总12给人做网站能赚钱吗

网站建设丶金手指花总12,给人做网站能赚钱吗,wordpress less,买外链一、Playbook基础 1.1 Playbook定义 Playbook其实是Ansible服务的一个配置文件#xff0c;Ansible使用Playbook的YAML语言配置编写成操作需求#xff0c;实现对远端主机或策略部署#xff0c;实现对远端主机的控制与管理。 1.2 Playbook组成 Tasks#xff1a;任务…一、Playbook基础 1.1 Playbook定义 Playbook其实是Ansible服务的一个配置文件Ansible使用Playbook的YAML语言配置编写成操作需求实现对远端主机或策略部署实现对远端主机的控制与管理。 1.2 Playbook组成 Tasks任务即通过 task 调用 ansible 的模板将多个操作组织在一个 playbook 中运行 Variables变量 Templates模板 Handlers处理器当changed状态条件满足时notify触发执行的操作 Roles角色 1.3 Playbook剧本详解 vim test1.yaml --- #yaml文件以---开头以表明这是一个yaml文件可省略但是如果两个YAML配置叠加的话要以此为分割 - name: first play #定义一个play的名称可省略gather_facts: false #设置不进行facts信息收集这可以加快执行速度可省略hosts: webservers #指定要执行任务的被管理主机组如多个主机组用冒号分隔remote_user: root #指定被管理主机上执行任务的用户tasks: #定义任务列表任务列表中的各任务按次序逐个在hosts中指定的主机上执行- name: test connection #自定义任务名称ping: #使用 module: [options] 格式来定义一个任务- name: disable selinuxcommand: /sbin/setenforce 0 #command模块和shell模块无需使用keyvalue格式ignore_errors: True #如执行命令的返回值不为0就会报错tasks停止可使用ignore_errors忽略失败的任务- name: disable firewalldservice: namefirewalld statestopped #使用 module: options 格式来定义任务option使用keyvalue格式- name: install httpdyum: namehttpd statelatest- name: install configuration file for httpdcopy: src/opt/httpd.conf dest/etc/httpd/conf/httpd.conf #这里需要一个事先准备好的/opt/httpd.conf文件notify: restart httpd #如以上操作后为changed的状态时会通过notify指定的名称触发对应名称的handlers操作- name: start httpd serviceservice: enabledtrue namehttpd statestartedhandlers: #handlers中定义的就是任务此处handlers中的任务使用的是service模块- name: restart httpd #notify和handlers中任务的名称必须一致service: namehttpd staterestarted #Ansible在执行完某个任务之后并不会立即去执行对应的handler而是在当前play中所有普通任务都执行完后再去执行handler这样的好处是可以多次触发notify但最后只执行一次对应的handler从而避免多次重启。 1.4 Playbook命令  //运行playbook ansible-playbook test01.yaml //补充参数 -k–ask-pass用来交互输入ssh密码 -K-ask-become-pass用来交互输入sudo密码 -u指定用户 ansible-playbook test01.yaml --syntax-check #检查yaml文件的语法是否正确 ansible-playbook test01.yaml --list-task #检查tasks任务 ansible-playbook test01.yaml --list-hosts #检查生效的主机 ansible-playbook test01.yaml --start-at-taskinstall httpd #指定从某个task开始运行1.5 Playbook安装并启动httpd服务 cd /opt/ vim test01.yaml--- - name: install httpdgather_facts: falsehosts: webserversremote_user: roottasks:- name: connection ceshiping:- name: disable firewalldservice: namefirewalld statestopped- name: install apacheyum: namehttpd statelatest- name: install config filecopy: src/opt/httpd.conf dest/etc/httpd/conf/httpd.conf- name: start httpd serviceservice: enabledtrue namehttpd statestarted- name: write htmlcopy: src/opt/index.html dest/var/www/html/index.htmlnotify: restart httpdhandlers:- name: restart httpdservice: namehttpd staterestartedecho 123 index.html cat index.html ansible-playbook test01.yaml --syntax-checkansible-playbook test01.yaml --list-taskansible-playbook test01.yaml --list-hostansible-playbook test01.yaml1.6 变量的定义和引用 cd /opt vim test02.yaml --- - name: variablehosts: webserversremote_user: rootvars:- groupname: test01- username: nginxtasks:- name: create groupgroup: name{{groupname}} systemyes gid333- name: create useruser: name{{username}} uid333 group{{groupname}}- name: copy filecopy: content{{ansible_default_ipv4}} dest/opt/shibin.txt -e选项指定ymal配置文件中变量username因为指定了在yaml文件中指定的username为nginx实际命令中指定为test001最终是以-e选项指定的username生效 注意命令行中的变量优先级高于YAML配置文件中的变量优先级。 ansible-playbook test02.yaml -e usernametest001 ​ 1.7 指定远程主机sudo切换用户  cd /opt vim test03.yaml --- - hosts: webserversremote_user: zhangsan become: yes become_user: rootansible-playbook test03.yml -K ​ 这里红色显示sudo提权失败可以去远端主机的配置文件/etc/sudoers中修改zhangsan用户的权限 ​   ​ 1.8 When条件判断 cd /opt vim test04.yaml --- - name: reboot hosthosts: dbserversremote_user: roottasks:- name: shutdown hostcommand: /sbin/shutdown -r nowwhen: ansible_default_ipv4.address 192.168.133.10​ 由于判断条件为主机地址为192.168.133.10才执行Shutdown操作所以主机地址为192.168.133.100的主机跳过Playbook  1.9 迭代 1.9.1 创建文件夹 cd /opt vim test05.yaml - name: test05hosts: webserverstasks:- name: create directoriesfile: path{{item}} statetouchwith_items:- /opt/shibin/s1.txt- /opt/shibin/s2.txt- /opt/shibin/s3.txt- /opt/shibin/s4.txt 注意需提前在webservers里的主机上创建好目录/opt/shibin  ansible-playbook test05.yaml 1.9.2  创建文件夹并建立用户 cd /opt vim test06.yaml --- - name: test06hosts: webserversgather_facts: falsetasks:- name: create directoriesfile:path: {{item}}state: directorywith_items:- /tmp/test1- /tmp/test2- name: add usersuser: name{{item.name}} statepresent groups{{item.groups}}with_items:- name: test1groups: wheel- name: test2groups: root ansible-playbook test06.yaml 二、Templates模块 Jinja是基于Python的模板引擎。Template类是Jinja的一个重要组件可以看作是一个编译过的模板文件用来产生目标文本传递Python的变量给模板去替换模板中的标记。 2.1 准备模板文件并设置引用的变量 yum install -y httpdcp /etc/httpd/conf/httpd.conf /opt/httpd.conf.j2vim /opt/httpd.conf.j2-42行修改- Listen {{http_port}} -95行修改- ServerName {{server_name}} -119行修改- DocumentRoot {{root_dir}} 2.2 修改主机清单内的变量 vim /etc/ansible/hosts -19- [webservers] -20- 192.168.133.90 http_port192.168.133.90:80 server_namewww.test1.com:80 root_dir/etc/httpd/htdocs #注意 root_dir要和前面的server_name空格 不可另起一行否则报错UNREACHABLE!-34- [dbservers] -35- 192.168.133.100 http_port192.168.133.100:80 server_namewww.test2.com:80 root_dir/etc/httpd/htdocs #注意 root_dir要和前面的server_name空格 不可另起一行否则报错UNREACHABLE! 2.3 编写Playbook剧本 vim apache.yaml--- - hosts: allremote_user: rootvars:- package: httpd- service: httpdtasks:- name: create dirfile: path/etc/httpd/htdocs statedirectory- name: install httpd packageyum: name{{package}} statelatest- name: install configure filetemplate: src/opt/httpd.conf.j2 dest/etc/httpd/conf/httpd.confnotify: restart httpd- name: start httpd serverservice: name{{service}} enabledtrue statestartedhandlers:- name: restart httpdservice: name{{service}} staterestarted ansible-playbook apache.yaml 三、Tags模块 可以在一个playbook中为某个或某些任务定义“标签”在执行此playbook时通过ansible-playbook命令使用--tags选项能实现仅运行指定的tasks。 playbook还提供了一个特殊的tags为always。作用就是当使用always当tags的task时无论执行哪一个tags时定义有always的tags都会执行。 cd /opt vim test07.yaml --- - hosts: webserversremote_user: roottasks:- name: Copy hosts filecopy: src/etc/hosts dest/opt/hoststags: shibin- name: touch filefile: path/opt/testhost statetouchtags: always ansible-playbook test07.yaml --tagsshibin 四、Roles模块 Ansible为了层次化、结构化地组织Playbook使用了角色rolesroles可以根据层次型结构自动装载变量文件、task以及handlers等。简单来讲roles就是通过分别将变量、文件、任务、模块及处理器放置于单独的目录中并可以便捷地include它们。roles一般用于基于主机构建服务的场景中但也可以用于构建守护进程等场景中。 4.1 Roles目录详解 4.2 在Playbook中使用Roles步骤 4.2.1 环境准备 mkdir /etc/ansible/roles/ -p #创建以 roles 命名的目录mkdir /etc/ansible/group_vars/ -p touch /etc/ansible/group_vars/all #创建全局变量目录mkdir /etc/ansible/roles/httpd mkdir /etc/ansible/roles/mysql #在 roles 目录中分别创建以各角色名称命令的目录mkdir /etc/ansible/roles/httpd/{files,templates,tasks,handlers,vars,defaults,meta} mkdir /etc/ansible/roles/mysql/{files,templates,tasks,handlers,vars,defaults,meta} #在每个角色命令的目录中分别创建files、handlers、tasks、templates、meta、defaults和vars目录用不到的目录可以创建为空目录也可以不创建touch /etc/ansible/roles/httpd/{defaults,vars,tasks,meta,handlers}/main.yml touch /etc/ansible/roles/mysql/{defaults,vars,tasks,meta,handlers}/main.yml #在每个角色的 handlers、tasks、meta、defaults、vars 目录下创建 main.yml 文件千万不能自定义文件名 4.2.2 修改yml文件  vim /etc/ansible/site.yml --- - hosts: cxkremote_user: rootroles:- httpd - hosts: wybremote_user: rootroles:- mysql 4.2.3 运行Ansible-Playbook   cd /etc/ansible ansible-playbook site.yml 4.3 Roles模块举例——LAMP mkdir /etc/ansible/roles/httpd/{files,templates,tasks,handlers,vars,defaults,meta} -p mkdir /etc/ansible/roles/mysql/{files,templates,tasks,handlers,vars,defaults,meta} -p mkdir /etc/ansible/roles/php/{files,templates,tasks,handlers,vars,defaults,meta} -ptouch /etc/ansible/roles/httpd/{defaults,vars,tasks,meta,handlers}/main.yml touch /etc/ansible/roles/mysql/{defaults,vars,tasks,meta,handlers}/main.yml touch /etc/ansible/roles/php/{defaults,vars,tasks,meta,handlers}/main.yml 4.3.1 编写httpd模块 1编写yml文件 vim /etc/ansible/roles/httpd/tasks/main.yml - name: install apacheyum: name{{pkg}} statelatest - name: start apacheservice: enabledtrue name{{svc}} statestarted 2定义变量 vim /etc/ansible/roles/httpd/vars/main.yml #可以定义在全局变量中也可以定义在roles角色变量中一般定义在角色变量中 pkg: httpd svc: httpd 4.3.2 编写Mysql模块 1编写yml文件 vim /etc/ansible/roles/mysql/tasks/main.yml- name: install mysqlyum: name{{pkg}} statelatest - name: start mysqlservice: enabledtrue name{{svc}} statestarted 2定义变量 vim /etc/ansible/roles/mysql/vars/main.ymlpkg:- mariadb- mariadb-server svc: mariadb 4.3.3 编写Php模块 1编写yml文件 vim /etc/ansible/roles/php/tasks/main.yml- name: install phpyum: name{{pkg}} statelatest - name: start php-fpmservice: enabledtrue name{{svc}} statestarted 2定义变量 vim /etc/ansible/roles/php/vars/main.ymlpkg:- php- php-fpm svc: php-fpm 4.3.4 编写Roles实例并启动 vim /etc/ansible/site.yml--- - hosts: wybremote_user: rootroles:- httpd- mysql- phpcd /etc/ansible ansible-playbook site.yml 五、 Ansible常用命令小结 5.1.ansible-doc ansible-doc -h Usage: ansible-doc [options] [module...] #该指令用于查看模块信息常用参数有两个-l 和 -s 具体如下 ansible-doc -l #列出所有已安装的模块ansible-doc -s command #查看具体某模块的用法这里如查看command模块 5.2 ansible-galaxy ansible-galaxy -h Usage: ansible-galaxy [init|info|install|list|remove] [--help] [options] ... #ansible-galaxy指令用于方便的从https://galaxy.ansible.com/ 站点下载第三方扩展模块我们可以形象的理解其类似于centos下的yum、python下的pip 5.3 ansible-playbook 通过读取playbook 文件后执行相应的动作 5.4 ansible-pull 该指令使用需要谈到ansible的另一种模式——pull 模式这和我们平常经常用的push模式刚好相反其适用于以下场景你有数量巨大的机器需要配置即使使用非常高的线程还是要花费很多时间 5.5 ansible-vault ansible-vault主要应用于配置文件中含有敏感信息又不希望他能被人看到vault可以帮你加密/解密这个配置文件属高级用法。主要对于playbooks里比如涉及到配置密码或其他变量时可以通过该指令加密这样我们通过cat看到的会是一个密码串类的文件编辑的时候需要输入事先设定的密码才能打开。这种playbook文件在执行时需要加上 –ask-vault-pass参数同样需要输入密码后才能正常执行。
http://www.hkea.cn/news/14369774/

相关文章:

  • 自己如何网站建设wordpress 功能介绍
  • 厦门市建设局网站住房保障哪里帮做企业网站
  • 建网站的客户厦门网站建设网站
  • 网站名称和域名有关系如何建立自己的微信小程序
  • 网站建设二级分销坪地网站建设如何
  • 网站建设与管理就业岗位wordpress加会员中心
  • 建设外贸网站的细节团队拓展训练
  • 网站建设岗位任职资格手机开发框架
  • 2018爱情动做网站陕西 网站建设 陕ICP
  • 怎样找到专业做网站人discuz做视频网站
  • 专业微网站建设公司中国百科网vip钓鱼网站开发
  • 营销型网站建设明细报网站会说话
  • 免费flash网站源码佛山网站关键词优化公司
  • 网站建设英文翻译开展网络营销的方式
  • 网站建设收费标准咨询安徽两学一做网站
  • 做家常菜哪个网站最好西安交易网站建设
  • 做网站济南内网网站建设汇报
  • 哈尔滨网站推广服务网络营销思想的网站改版计划
  • 知道网站是wp程序做的如何仿站国外网站设计版式欣赏
  • 做网站多少钱zwnet网站设计需要会什么
  • 企业做网站的好处企业网站建设应注意什么
  • 做网站的软件是哪个莱芜一中谭苗苗事件
  • 网站vi设计公司湖北省住房部城乡建设厅网站
  • 做网站需要前置审批wordpress商用可以用吗
  • 西部数码网站管理助手3.1额尔古纳网站建设价格
  • 网站推广包括ui网站开发
  • 为什么选择做游戏网站深圳正规融资公司
  • 遂宁市建设银行网站构站网
  • 门户网站建设需要注意什么找网站推广
  • 怎么分析一个网站北京 公司网站 备案中 开通访问