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

网站建设ahxkj做的烂的大网站

网站建设ahxkj,做的烂的大网站,加强文化网站建设,企业网站后台模板目录 一、playbook的组成 二、 playbook安装httpd服务 1.编写playbook剧本 2.运行playbook 三、定义、引用变量 四、 指定远程主机sudo切换用户 五、when条件判断 六、迭代 七、Templates 模块 1.先准备一个以 .j2 为后缀的 template 模板文件#xff0c;设置引用的变…目录 一、playbook的组成 二、 playbook安装httpd服务 1.编写playbook剧本 2.运行playbook 三、定义、引用变量 四、 指定远程主机sudo切换用户 五、when条件判断 六、迭代 七、Templates 模块 1.先准备一个以 .j2 为后缀的 template 模板文件设置引用的变量 2.修改主机清单文件使用主机变量定义一个变量名相同而值不同的变量 3.编写 playbook 八、tags 模块 九、利用playbook部署lnmp集群 1.修改nginx配置文件 2.编写lnmp的剧本 3.运行playbook并访问验证 一、playbook的组成 Tasks任务即通过 task 调用 ansible 的模板将多个操作组织在一个 playbook 中运行Variables变量Templates模板Handlers处理器当changed状态条件满足时notify触发执行的操作Roles角色 二、 playbook安装httpd服务 1.编写playbook剧本 vim test1.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从而避免多次重启。 2.运行playbook ansible-playbook test1.yaml//补充参数 -k–ask-pass用来交互输入ssh密码 -K-ask-become-pass用来交互输入sudo密码 -u指定用户 ansible-playbook test1.yaml --syntax-check #检查yaml文件的语法是否正确 ansible-playbook test1.yaml --list-task #检查tasks任务 ansible-playbook test1.yaml --list-hosts #检查生效的主机 ansible-playbook test1.yaml --start-at-taskinstall httpd #指定从某个task开始运行三、定义、引用变量 - name: second playhosts: webserversremote_user: rootvars: #定义变量- groupname: mysql #格式为 key: value- username: nginxtasks:- name: create groupgroup: name{{groupname}} systemyes gid306 #使用 {{key}} 引用变量的值- name: create useruser: name{{username}} uid306 group{{groupname}} - name: copy filecopy: content{{ansible_default_ipv4}} dest/opt/vars.txt #在setup模块中可以获取facts变量信息copy: content{{ansible_default_ipv4.address}} dest/opt/vars.txt #在setup模块中可以获取facts变量信息下子字段address字段值IP地址 - name: second playhosts: webserversremote_user: roottasks:- name: create groupgroup: name{{groupname}} systemyes gid306- name: create useruser: name{{username}} uid306 group{{groupname}}- name: copy filecopy: content{{ansible_default_ipv4}} dest/opt/vars.txtcopy: content{{ansible_default_ipv4.address}} dest/opt/vars.txt 四、 指定远程主机sudo切换用户 - hosts: dbserversremote_user: zhangsan become: yes #2.6版本以后的参数之前是sudo意思为切换用户运行become_user: root #指定sudo用户为root 执行playbook时ansible-playbook test3.yml -k -K 五、when条件判断 在Ansible中提供的唯一一个通用的条件判断是when指令当when指令的值为true时则该任务执行否则不执行该任务。 #when一个比较常见的应用场景是实现跳过某个主机不执行任务或者只有满足条件的主机执行任务 vim test3.yaml --- - hosts: allremote_user: roottasks:- name: shutdown host command: /sbin/shutdown -r nowwhen: ansible_default_ipv4.address 192.168.88.20 #when指令中的变量名不需要手动加上 {{}} #when: inventory_hostname 主机名ansible-playbook test4.yaml 六、迭代 Ansible提供了很多种循环结构一般都命名为with_items作用等同于 loop 循环。 - name: play1hosts: dbserversgather_facts: falsetasks: - name: create filefile:path: {{item}}state: touchwith_items: [ /opt/a, /opt/b, /opt/c, /opt/d ]- name: play2hosts: dbserversgather_facts: false vars:test:- /tmp/test1- /tmp/test2- /tmp/test3- /tmp/test4tasks: - name: create directoriesfile:path: {{item}}state: directorywith_items: {{test}} #循环引用变量- name: play3hosts: dbserversgather_facts: falsetasks:- name: add usersuser: name{{item.name}} statepresent groups{{item.groups}}with_items: #多参数循环- name: test1groups: wheel- name: test2groups: root 或with_items:- {name: test1, groups: wheel}- {name: test2, groups: root} 七、Templates 模块 Jinja是基于Python的模板引擎。Template类是Jinja的一个重要组件可以看作是一个编译过的模板文件用来产生目标文本传递Python的变量给模板去替换模板中的标记。 1.先准备一个以 .j2 为后缀的 template 模板文件设置引用的变量 cp /etc/httpd/conf/httpd.conf /opt/httpd.conf.j2vim /opt/httpd.conf.j2 Listen {{http_port}} #42行修改 ServerName {{server_name}} #95行修改 DocumentRoot {{root_dir}} #119行修改 2.修改主机清单文件使用主机变量定义一个变量名相同而值不同的变量 vim /etc/ansible/hosts [webservers] 192.168.88.20 http_port192.168.88.20:8080 server_namewww.accp.com:8080 root_dir/var/www/html/accp[dbservers] 192.168.88.30 http_port192.168.88.30:80 server_namewww.benet.com:80 root_dir/var/www/html/benet 3.编写 playbook vim apache.yaml --- - hosts: allremote_user: rootvars:- package: httpd- service: httpdtasks:- name: install httpd packageyum: name{{package}} statelatest- name: install configure filetemplate: src/opt/httpd.conf.j2 dest/etc/httpd/conf/httpd.conf #使用template模板notify:- restart httpd- name: create accp dirfile: path/var/www/html/accp statedirectorywhen: inventory_hostname 192.168.88.20- name: create accp dirfile: path/var/www/html/benet statedirectorywhen: inventory_hostname 192.168.88.30- name: start httpd serverservice: name{{service}} enabledtrue statestartedhandlers:- name: restart httpdservice: name{{service}} staterestartedansible-playbook apache.yaml 八、tags 模块 可以在一个playbook中为某个或某些任务定义“标签”在执行此playbook时通过ansible-playbook命令使用--tags选项能实现仅运行指定的tasks。 playbook还提供了一个特殊的tags为always。作用就是当使用always作为tags的task时无论执行哪一个tags时定义有always的tags都会执行。 vim webhosts.yaml --- - hosts: webserversremote_user: roottasks:- name: Copy hosts filecopy: src/etc/hosts dest/opt/hoststags:- only #可自定义- name: touch filefile: path/opt/testhost statetouchtags:- always #表示始终要运行的代码ansible-playbook webhosts.yaml --tagsonly九、利用playbook部署lnmp集群 1.修改nginx配置文件 /配置 nginx 支持 PHP 解析 vim default.conf ......location ~ \.php$ {root html;fastcgi_pass 127.0.0.1:9000;fastcgi_index index.php;fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name; #将 /scripts 修改为nginx的工作目录include fastcgi_params;} 2.编写lnmp的剧本 vim lnmp.yml - name: nginxgather_facts: falsehosts: webserversremote_user: roottasks: #yum安装nginx- name: create nginx yumcopy: src/etc/yum.repos.d/nginx.repo dest/etc/yum.repos.d/nginx.repo- name: install nginxyum: namenginx #将编辑好的nginx配置文件复制到远程主机 - name: nginx congruation filecopy: src/opt/default.conf dest/etc/nginx/conf.d/default.conf- name: start nginxservice: namenginx statestarted enabledyes- name: wordpresscopy: src/opt/lnmp/nginx/www/wordpress dest/usr/share/nginx/html/- name: mysqlhosts: webserversremote_user: roottasks: #安装mysql- name: remove mariadbshell: yum -y remove mariadb*ignore_errors: true- name: wegtcommand: wget https://repo.mysql.com/mysql57-community-release-el7-11.noarch.rpm- name: inatsll mysqlrpmcommand: rpm -ivh mysql57-community-release-el7-11.noarch.rpm- name: change mysql-community.rpmshell: sed -i s/gpgcheck1/gpgcheck0/ /etc/yum.repos.d/mysql-community.repo- name: install mysqlyum: namemysql-server- name: start mysqldservice: namemysqld.service statestarted enabledyes- name: echo passwordshell: grep password /var/log/mysqld.log | awk NR1{print $NF} #在日志文件中找出root用户的初始密码register: mysql_password #将初始密码导入到mysql_password的变量中- name: echodebug: msg: {{ mysql_password }} #输出变量mysql_password的值 #登录mysql修改MySQL登录密码 - name: grant locationshell: mysql --connect-expired-password -uroot -p{{ mysql_password[stdout] }} -e ALTER USER rootlocalhost IDENTIFIED BY Admin123; #修改权限 - name: grant optionshell: mysql --connect-expired-password -uroot -pAdmin123 -e grant all privileges on *.* to root% identified by Admin123456 with grant option; #创建wordpress数据库- name: create databaseshell: mysql --connect-expired-password -uroot -pAdmin123 -e create database wordpress; #赋予admin用户访问wordpress的权限- name: grantshell: mysql --connect-expired-password -uroot -pAdmin123 -e grant all on wordpress.* to admin% identified by Admin123456;- name: grantshell: mysql --connect-expired-password -uroot -pAdmin123 -e grant all on wordpress.* to adminlocalhost identified by Admin123456;- name: flushshell: mysql --connect-expired-password -uroot -pAdmin123 -e flush privileges; #为了防止每次yum操作都会自动更新卸载这个软件- name: yumcommand: yum -y remove mysql57-community-release-el7-11.noarch#安装php及其依赖包 - name: phphosts: webserversremote_user: roottasks:- name: yum rpmcommand: yum -y install https://rpms.remirepo.net/enterprise/remi-release-7.rpm- name: yumyum: nameyum-utils- name: yum-configcommand: yum-config-manager --enable remi-php74- name: install yilaibaocommand: yum -y install php php-cli php-fpm php-mysqlnd php-zip php-devel php-gd php-mcrypt php-mbstring php-curl php-xml php-pear php-bcmath php-json php-redis- name: start phpservice: namephp-fpm statestarted enabledyes3.运行playbook并访问验证 ansible-playbook lnmp.yml#验证 浏览器访问http://192.168.88.30/wordpress/index.php
http://www.w-s-a.com/news/68292/

相关文章:

  • 优化一个网站多少钱网站开发北京
  • html教学关键词优化价格
  • 黄冈论坛网站有哪些给wordpress首页添加公告栏
  • 初中做数学题的网站做淘宝必备网站
  • 买拆车件上什么网站谁有那种手机网站
  • 一家专做有机蔬菜的网站万户网络是干嘛的
  • 十堰百度网站建设八宝山做网站公司
  • 地区电商网站系统建筑施工图纸培训班
  • 网站外包维护一年多少钱医院网站 功能
  • 电子商务市场的发展前景seo推广平台服务
  • 乐清网页设计公司哪家好seo推广任务小结
  • 360建筑网是什么pc优化工具
  • 越秀免费网站建设风景区网站建设项目建设可行性
  • 网站建站公司一站式服务学校网站开发招标
  • asp.net mvc 5 网站开发之美电商网站 流程图
  • 室内设计素材网站推荐郑州专业做淘宝网站建设
  • 新建的网站怎么做seo优化模板规格尺寸及价格
  • 平湖网站设计做电子元器件销售什么网站好
  • 可视化网站模板我想建个网站网站怎么建域名
  • 达州网站建设qinsanw南京市建设发展集团有限公司网站
  • django 网站开发实例公司排行榜
  • 韩国做美食网站阳江网站建设 公司价格
  • 网站开发哪里接业务长春高端模板建站
  • 深圳网站制作公司方案dw一个完整网页的代码
  • asp手机网站源码下载做seo推广网站
  • 网站优化建议怎么写网站维护主要有哪些内容和方法
  • 建设网站需要钱吗网络推广加盟
  • 高清素材图片的网站泰安网签备案查询
  • 自助网站建设怎么建设房地产的最新政策
  • 企业网站 生成html网站侵权怎么做公证或证据保存