N63050第十三周作业
就业和全程班小伙伴本周学习内容:
二十五、Http协议和Web服务器Apache
1、playbook的高级用法(57分钟)
2、playbook的高级用法关于变量(59分钟)
3、playbook的高级用法变量(36分钟)
4、httpd常见配置(49分钟)
5、playbook的高级用法(47分钟)
6、ansible的企业级应用role(80分钟)
7、http和相关技术(43分钟)
二十六、Http协议和Web服务器Apache2
1、Http协议各种版本详解
2、Http协议的工作过程和Httpd的MPM工作模式
3、Httpd安装和配置文件格式介绍
4、Httpd常见配置
5、Httpd常见配置
6、Httpd常见配置
7、http的报文结构和常见响应码
就业和全程班第十三周作业
1、ansible-playbook实现MySQL的二进制部署###
[root@centos8 ~]#ls -l /data/ansible/files
total 650948
-rw-r--r-- 1 root root 250 Mar 14 09:14 my.cnf
-rw-r--r-- 1 root root 666559924 Mar 13 20:37 mysql-5.7.36-linux-glibc2.12-x86_64.tar.gz
-rw-r--r-- 1 root root 93 Mar 13 21:58 secure_mysql.sh
[root@centos8 ~]#cat /data/ansible/files/my.cnf
[mysqld]
socket=/tmp/mysql.sock
user=mysql
symbolic-links=0
datadir=/data/mysql
innodb_file_per_table=1
log-bin
pid-file=/data/mysql/mysqld.pid
skip-grant-tables
[client]
port=3306
socket=/tmp/mysql.sock
[mysqld_safe]
log-error=/var/log/mysqld.log
[root@centos8 ~]#cat /data/ansible/files/secure_mysql.sh
#!/bin/bash
/usr/local/mysql/bin/mysql_secure_installation <<EOF
y
magedu
magedu
y
y
y
y
EOF
[root@centos8 ~]#tree /data/ansible/files/
/data/ansible/files/
├── my.cnf
├── mysql-5.7.36-linux-glibc2.12-x86_64.tar.gz
└── secure_mysql.sh
0 directories, 3 files
[root@centos8 ~]#cat /data/ansible/install_mysql.yml
---
# install mysql-5.7.36-linux-glibc2.12-x86_64.tar.gz
- hosts: dbsrvs
remote_user: root
gather_facts: no
tasks:
- name: install packages
yum: name=libaio,perl-Data-Dumper,perl-Getopt-Long
- 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-5.7.36-linux-glibc2.12-x86_64.tar.gz dest=/usr/local/ owner=root group=root
- name: create linkfile /usr/local/mysql
file: src=/usr/local/mysql-5.7.36-linux-glibc2.12-x86_64 dest=/usr/local/mysql state=link
- name: data dir
shell: "cd /usr/local/mysql/ ./scripts/mysql_install_db --datadir=/data/mysql --user=mysql"
ignore_errors: no
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: enable service
shell: /etc/inti.d/mysqld start:chkconfig --add mysqld;chkconfig mysqld on
tags: service
- name: PATH variable
copy: content='PATH=/usr/local/mysql/bin:$PATH' dest=/etc/profile.d/mysql.sh
- name: secure script
script: /data/ansible/files/secure_mysql.sh
tags: script
[root@centos8 ansible]#ansible-playbook install_mysql.yml
2、Ansible playbook实现apache批量部署,并对不同主机提供以各自IP地址为内容的ind
[root@centos8 ansible]#cat install_httpd.yml
---
# install APACHE
- hosts: dbsrvs
remote_user: root
gather_facts: yes
tasks:
- name: install httpd
yum: name=httpd
- name: Lishen 8080
lineinfile: path=/etc/httpd/conf/httpd.conf regexp='^Listen' line='Listen 8080'
- name: Service enable --now
service: name=httpd state=started enabled=yes
- name: create html
file: path=/var/www/html/index.html state=touch
- name: write IP
shell: "echo {{ ansible_eth0.ipv4.address }} > /var/www/html/index.html"
测试
[root@centos8 ansible]#ansible-playbook install_httpd.yml
PLAY [dbsrvs] **********************************************************************************************************************************************************
TASK [Gathering Facts] *************************************************************************************************************************************************
ok: [10.0.0.18]
ok: [10.0.0.17]
TASK [install httpd] ***************************************************************************************************************************************************
changed: [10.0.0.17]
changed: [10.0.0.18]
TASK [Lishen 8080] *****************************************************************************************************************************************************
changed: [10.0.0.17]
changed: [10.0.0.18]
TASK [Service enable --now] ********************************************************************************************************************************************
changed: [10.0.0.17]
changed: [10.0.0.18]
TASK [create html] *****************************************************************************************************************************************************
changed: [10.0.0.17]
changed: [10.0.0.18]
TASK [write IP] ********************************************************************************************************************************************************
changed: [10.0.0.17]
changed: [10.0.0.18]
PLAY RECAP *************************************************************************************************************************************************************
10.0.0.17 : ok=6 changed=5 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
10.0.0.18 : ok=6 changed=5 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
[root@centos8 ansible]#curl 10.0.0.17:8080
10.0.0.17
[root@centos8 ansible]#curl 10.0.0.18:8080
10.0.0.18
3、http的报文结构和状态码总结
- HTTP的报文结构
-
HTTP状态码结构
参考资料:https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Status
1xx:100-101 信息提示
2xx:200-206 成功
3xx:300-307 重定向
4xx:400-415 错误类信息,客户端错误
5xx:500-505 错误类信息,服务器端错误
- HTTP协议常用的状态码
200: 成功,请求数据通过响应报文的entity-body部分发送;OK
301: 请求的URL指向的资源已经被删除;但在响应报文中通过首部Location指明了资源现在所处的新位
置;Moved Permanently
302: 响应报文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 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义