二十五、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 ~]#vim mysql_install.yaml
---
- hosts: dbsrvs
vars:
password: 123456
tasks:
- name: download mysql-package
get_url:
url: http://mirrors.163.com/mysql/Downloads/MySQL-5.7/mysql-5.7.35-linux-glibc2.12-x86_64.tar.gz
dest: /opt/mysql-5.7.35-linux-glibc2.12-x86_64.tar.gz
force: yes
- name: tar mysql-package
unarchive:
src: /opt/mysql-5.7.35-linux-glibc2.12-x86_64.tar.gz
dest: /usr/local
owner: root
group: root
mode: 0755
copy: no
- name: create linkfile /usr/local/mysql
file:
src: /usr/local/mysql-5.7.35-linux-glibc2.12-x86_64
dest: /usr/local/mysql
state: link
- name: create bin link
shell: "ln -s /usr/local/mysql/bin/* /usr/bin/"
ignore_errors: yes
- name: copy my.cnf #需提前准备
copy:
src: my.cnf
dest: /etc/my.cnf
- name: install packages
yum:
name: libaio,numactl-libs,ncurses-compat-libs,ncurses-c++-libs
state: present
- 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
- name: crate work directory
file:
path: /data/mysql
state: directory
mode: 0755
owner: mysql
group: mysql
- name: Initialization mysql
shell: "mysqld --initialize --user=mysql --datadir=/data/mysql"
ignore_errors: yes
- name: serivce script
shell: "/bin/cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld;chkconfig --add mysqld;chkconfig mysqld on"
- name: start service
service:
name: mysqld
state: started
enabled: yes
- name: set root passwork
shell: mysqladmin -uroot -p"`awk '/A temporary password/ {print $NF}' /data/mysql/mysql.log`" password {{ password }}
ignore_errors: yes
2、Ansible playbook实现apache批量部署,并对不同主机提供以各自IP地址为内容的index.html
[root@centos8 ansible]#vim templates/index.html.j2
worker_processes {{ ansible_all_ipv4_addresses }};
[root@centos8 ansible]#vim install_apache.yml
---
- hosts: websrvs
remote_user: root
gather_facts: yes
tasks:
- name: "安装apache"
yum: name=httpd
- name: "复制配置文件"
template: src=index.html.j2 dest=/var/www/html/index.html
- name: "启动Apache,并设置开机启动"
service: name=httpd state=started enabled=yes
3、http的报文结构和状态码总结
http协议状态码分类:
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: 网关超时