马哥博客作业第十二周

1、通过ansible Roles编排实现 httpd 角色的部署
1)设置SSH免密码登陆
[root@localhost ~]# cat ssh_nopass.sh
#!/bin/bash
#ssh nopassword

[ -f ~/.ssh/id_rsa ] || ssh-keygen -f ~/.ssh/id_rsa -P "" -q
rpm -q sshpass &> /dev/null || yum -y install sshpass &> /dev/null
passwd=123456
prefix=10.0.0.

for i in {10..12};do
{
sshpass -p $passwd ssh-copy-id -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa root@$prefix${i} &> /dev/null
}&
done
wait

[root@localhost ~]# bash ssh_nopass.sh
2)安装ansible
[root@localhost ~]# yum -y install ansible
[root@localhost ~]# vim /etc/ansible/hosts
文件末尾添加以下内容
[webserv]
10.0.0.10
10.0.0.11
10.0.0.12

3)创建ansible任务
[root@localhost ~]# mkdir -pv /root/ansible/roles/httpd/{tasks,handlers}
[root@localhost ~]# cd /root/ansible/roles/httpd/tasks
[root@cento7 ~/ansible/roles/httpd/tasks]# cat main.yml
- include: install.yml
- include: config.yml
- include: mkdir.yml
- include: index.yml
- include: service.yml

[root@cento7 ~/ansible/roles/httpd/tasks]# cat install.yml
- name: install httpd
  yum: name=httpd

[root@cento7 ~/ansible/roles/httpd/tasks]# cat config.yml
- name: config Document
  lineinfile: path=/etc/httpd/conf/httpd.conf regexp="^DocumentRoot" line="DocumentRoot" /data/html""
- name: config Directory
  lineinfile: path=/etc/httpd/conf/httpd.conf regexp="^<Directory .*html" line="<Directory "/data/html">"

[root@cento7 ~/ansible/roles/httpd/tasks]# cat mkdir.yml
- name: create DocumentRoot
  file: name=/data/html state=directory

[root@cento7 ~/ansible/roles/httpd/tasks]# cat index.yml
- name: httpd index.html
  shell: echo "HTTP Server is Ansible" > /data/html/index.html
  notify: restart httpd service

[root@cento7 ~/ansible/roles/httpd/tasks]# cat service.yml
- name: start httpd service
  service: name=httpd state=started enabled=yes

[root@localhost ~]# cd /root/ansible/roles/httpd/handlers/
[root@cento7 ~/ansible/roles/httpd/handlers]# cat main.yml
- name: restart httpd service
  service: name=httpd state=restarted

#注意:role_httpd.yml和roles在同一级目录
[root@cento7 ~/ansible/roles/httpd/handlers]# cat main.yml
- name: restart httpd service
  service: name=httpd state=restarted

[root@cento7 ~/ansible]# cat role_httpd.yml
---
# httpd role
- hosts: webserv
  remote_user: root

  roles:
    - httpd
4)执行ansible-playbook文件
[root@cento7 ~/ansible]# ansible-playbook role_httpd.yml

5)测试
[root@cento7 ~/ansible]# curl 10.0.0.10
[root@cento7 ~/ansible]# curl 10.0.0.11
[root@cento7 ~/ansible]# curl 10.0.0.12

2、简述 MySQL 数据库访问的执行过程
客户端连接MySQL服务器Connection Handing,然后发布查询,如果缓存中有结果,则直接返回结果,如果结果没有被缓存,MySQL解析查询Parser将通过优化器Optimizer生成执行计划,然后运行执行计划通过Pluggable Storage Engine API从存储引擎中获取数据,并返回给客户端。

3、S E L E C T 语句的完整语法较复杂,但至少包括的部分是 ( B )
A.仅 S E L E C T
B.S E L E C T ,F R O M
C.S E L E C T ,G R O U P
D.S E L E C T ,I N T O

4、一张表的主键个数为 ( C )
A.至多 3 个 B.没有限制
C.至多 1 个 D.至多 2 个

原文地址:https://www.cnblogs.com/xuanlv-0413/p/13522833.html