第十三周作业
一、ansible-playbook实现MySQL的二进制部署
[root@control ansible]# tree
.
├── ansible.cfg
├── files
│ ├── my.cnf
│ └── mysql-5.7.33-linux-glibc2.12-x86_64.tar.gz
[root@control ansible]# cat files/my.cnf
[mysqld]
server-id=1
log-bin
dadadir=/data/mysql
socket=/data/mysql/mysql.sock
log-error=/data/mysql/mysql.log
pid-file=/data/mysql/mysql.pid
[client]
socket=/data/mysql/mysql.sock
[root@control ansible]# vim install_mysql.yml
- name: install mysql 5.7.33
hosts: test
gather_facts: no
vars:
mysql_version: 5.7.33
mysql_file: mysql-{{mysql_version}}-linux-glibc2.12-x86_64.tar.gz
mysql_root_password: wuhaolam
tasks:
- name: install packages
yum:
name:
- libaio
- numactl-libs
- MYSQL-python
state: latest
- name: create mysql group
group:
name: mysql
gid: 306
- name: create mysql user
user:
name: mysql
uid: 306
group: mysql
shell: /sbin/nologin
system: yes
create_home: no
home: /data/mysql
- name: copy tar to remote host and file mode
unarchive:
src: /data/ansible/files/{{mysql_file}}
dest: /usr/local/
owner: root
group: root
- name: create linkfile
file:
src: /usr/local/mysql-{{mysql_version}}-linux-glibc2.12-x86_64
dest: /usr/local/mysql
state: link
- name: create dir
file:
path: /data/mysql
state: directory
recurse: yes
mode: '0755'
owner: mysql
group: mysql
- name: data dir
shell: /usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/data/mysql
tags: data
- name: config my.cnf
copy:
src: /data/ansible/files/my.cnf
dest: /etc/my.cnf
- name: service script
shell: /bin/cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
- name: PATH variable
copy:
content: 'PATH=/usr/local/mysql/bin:$PATH'
dest: /etc/profile.d/mysql.sh
- name: enable service
shell: chkconfig --add mysqld;/etc/init.d/mysqld start
tags: service
- name: get password
shell: awk '/A temporary password/{print $NF}' /data/mysql/mysql.log
register: password
- name: change password
shell: /usr/local/mysql/bin/mysqladmin -uroot -p'{{password.stdout}}' password {{mysql_root_password}}
二、Ansible playbook实现apache批量部署,并对不同主机提供以各自IP地址为内容的index.html
[root@control ansible]# cd roles/
[root@control roles]#
[root@control roles]# ansible-galaxy init apache
[root@control roles]# cd ..
[root@control ansible]# vim roles/apache/tasks/main.yml
- name: install apache
yum:
name: httpd
state: latest
- name: start service apache
service:
name: httpd
state: started
enabled: yes
- name: template a file
template:
src: index.html.j2
dest: /var/www/html/index.html
[root@control ansible]# vim roles/apache/templates/index.html.j2
{{ ansible_default_ipv4.address }}
[root@control ansible]# vim roles.yml
---
- name: use apache
hosts: all
roles:
- apache
[root@control ansible]# ansible-playbook roles.yml
[root@control ansible]# ansible all -a 'curl 127.0.0.1'
[WARNING]: Consider using the get_url or uri module rather than running 'curl'. If you need to use command because get_url or uri is insufficient you
can add 'warn: false' to this command task or set 'command_warnings=False' in ansible.cfg to get rid of this message.
node5 | CHANGED | rc=0 >>
192.168.119.142 % Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 16 100 16 0 0 18867 0 --:--:-- --:--:-- --:--:-- 16000
node4 | CHANGED | rc=0 >>
192.168.119.146 % Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 16 100 16 0 0 16000 0 --:--:-- --:--:-- --:--:-- 16000
node1 | CHANGED | rc=0 >>
192.168.119.145 % Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 16 100 16 0 0 16000 0 --:--:-- --:--:-- --:--:-- 16000
node3 | CHANGED | rc=0 >>
192.168.119.150 % Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 16 100 16 0 0 16000 0 --:--:-- --:--:-- --:--:-- 16000
三、HTTP的报文结构和状态码
HTTP的两种报文——请求报文和回应报文
(1)请求报文
(2)回应报文
3.1 HTTP的报文结构
Method 方法
version 版本
status 状态码
reason-phrase 原因短语
headers 首部字段头
entity-body 实体
3.2 HTTP的常见状态码
200:成功,请求数据通过响应报文的entity-body部分发送;OK
301:请求的URL指向的资源不存在;但在响应报文中通过首部Location指明了资源现在所处的新位置;Moved Permanently
302:同状态码301;但首部Location指明了资源现在所处的新位置Moved Temporarily
304:客户端发出了条件式请求,但服务器上的资源未曾发生改变,则通过响应此状态码通知客户端;Not Modified
307:浏览器内部重定向
401:需要输入账号和密码认证才能访问资源;Unauthorized
403:请求被禁止;Forbidden
404:服务器无法找到客户端请求的资源;Not Found
500:服务器内部错误;Internal Server Error
502:代理服务器从后端服务器收到一条伪响应,如无法连接到网关;Bad Gateway
503:服务不可用,临时服务器维护或过载,服务器无法处理请求
504:网关超时
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· DeepSeek 开源周回顾「GitHub 热点速览」