第十二周作业

1、通过ansible Roles编排实现 httpd 角色的部署
设置SSH免密码登陆
vim ssh_nopass.sh
#!/bin/bash
#ssh nopassword authentication

[ -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=192.168.1.

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

bash ssh_nopass.sh
安装ansible
yum -y install ansible
vim /etc/ansible/hosts
文件末尾添加以下内容
[webservers]
192.168.1.12
192.168.1.13
创建ansible任务
mkdir -p ansible/roles/httpd/{tasks,handlers} #注:当前目录为/root
cd ansible/roles/httpd/tasks
vim main.yml
内容如下
- include: install.yml
- include: config.yml
- include: mkdir.yml
- include: index.yml
- include: service.yml
- include: firewalld.yml

vim install.yml
内容如下
- name: install httpd
  yum: name=httpd

vim config.yml
内容如下
- name: config DocumentRoot
  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">"

vim mkdir.yml
内容如下
- name: create DocumentRoot
  file: name=/data/html state=directory

vim index.yml
内容如下
- name: httpd index.html
  shell: echo "HTTP server based on Ansible" > /data/html/index.html
  notify: restart httpd service

vim service.yml
内容如下
- name: start httpd service
  service: name=httpd state=started enabled=yes

vim firewalld.yml
内容如下
- name: config firewalld
  shell: firewall-cmd --permanent --add-service=http;firewall-cmd --reload

cd ansible/roles/httpd/handlers/
vim main.yml
内容如下
- name: restart httpd service
  service: name=httpd state=restarted

cd /root/ansible/
vim role_httpd.yml #注意:role_httpd.yml和roles在同一级目录
内容如下
---
# httpd role
- hosts: webservers
  remote_user: root

  roles:
    - httpd
注:- httpd对应ansible/roles/httpd
执行playbook
ansible-playbook role_httpd.yml
测试
curl 192.168.1.12
curl 192.168.1.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 个

posted @ 2020-08-16 22:19  小余518  阅读(101)  评论(0)    收藏  举报