Python之路-Linux命令基础(5)

作业一:nginx服务 二进制安装nginx包

1.使用网络yum源

Image[1]

2.使用yum安装epel-release扩展源

[root@localhost html]# yum install epel-release -y  

3.使用yum安装nginx服务。

[root@localhost html]# yum install nginx -y  

4.作为web服务修改配置文件

[root@localhost html]# vim /etc/nginx/nginx.conf

Image(1)[1]

5.进入网络根目录下,创建文件index.html,作为我们要访问的内容

[root@localhost html]# vim /usr/share/nginx/html/index.html

Image(2)[1]

6.关闭防火墙

[root@localhost html]# systemctl stop firewalld

7.让配置生效,

[root@localhost html]# systemctl restart nginx

[root@localhost html]# systemctl status nginx

 

Image(3)[1]

8.验证配

Image(4)[1]

作业二:nfs服务

1.二进制安装nfs

nfs是网络文件系统的缩写

[root@localhost nginx]# yum install rpcbind nfs-utils -y 

2.修改配置文件

[root@localhost nginx]# vim /etc/exports

3.服务端配置

[root@localhost /]# mkdir /share

[root@localhost /]# cd /share

[root@localhost share]# touch share.txt

[root@localhost share]# echo welcome to beijing > share.txt

[root@localhost share]# cat share.txt

welcome to beijing

4.启动服务,验证共享文件( 必须先启动rpcbind服务)

[root@localhost share]# systemctl enable nfs-server.service

Created symlink from /etc/systemd/system/multi-user.target.wants/nfs-server.service to /usr/lib/systemd/system/nfs-server.service.

[root@localhost share]# systemctl enable rpcbind.service

[root@localhost share]# systemctl start rpcbind.service

[root@localhost share]# systemctl start nfs-server.service

[root@localhost share]# exportfs

/share            192.168.0.0/24

[root@localhost share]# showmount -e

Export list for localhost:

/share 192.168.0.0/24

5.作为共享存储挂载在三台web的网站根目录下

[root@localhost html]# showmount -e 192.168.0.107

Export list for 192.168.0.107:

/share 192.168.0.0/24

  

[root@localhost html]# mkdir -p /var/www/html

[root@localhost html]# mount -t nfs 192.168.0.107:/share /var/www/html

[root@localhost html]# ls /var/www/html/

share.txt

 

6.在服务端修改读写权限

[root@localhost ~]# chmod -R o+w /share

7.实现,在任意一台web上修改的结果,其余两台都可以看到

例如:web2上新建aaa.txt  在web3上立刻可以查看

Image(5)[1]

Image(6)[1]

作业三:nginx反向代理三台web

1.官方文档网址 http://nginx.org/en/docs/http/load_balancing.html

2.克隆出来三台web,在不同的服务器上创建的index.html内容不一样,依然创建在网站的根目录,因为我们未修改location中的root,所以采用全局的网站根目录

vim /usr/share/nginx/html/index.html

3.在代理的服务端的配置文件中,参照官网文档进行修改。

Image(7)[1]

Image(8)[1]

4.重新加载配置文件

systemctl reload nginx

5.实现基于轮询的方式调度三台web,并验证结果

默认是轮询方式

Image(9)[1]

Image(10)[1]

Image(11)[1]

6.实现基于权重的方式调度三台web,并验证结果

Image(12)[1]

7.实现基于hash的方式调用三台web,并验证结果

Image(13)[1]

 

作业四:nginx反向代理+三台web+nfs共享存储实现集群配置

实现方式:我们同时拥有一台nginx反向代理服务器和三台web服务器,以及一台存储服务器。客户端发来的请求由反向代理服务端分给三台web服务器去处理数据,而作为客户端的用户,我们只是将请求递交给了反向代理服务器,并感受不到这种处理。而三台服务器上所使用的数据又是通过NFS共享存储技术共享在了一台存储的服务器上,导致不同的web服务器获取到的数据都是实时更新的,保证数据的有效可靠。等到处理完成,由nginx反向代理服务器把处理得到的数据传递回用户。

Image(14)[1]

作业五:源码安装nginx

1.安装nginx所需要的包

 

[root@ym /]# yum install gcc-* glibc-* openssl openssl-devel pcre pcre-devel zlib zlib-devel -y

 

2.拖入文件后,解压缩

3.执行配置的可执行文件

4.配置相关参数

[root@ym nginx-1.10.3]# ./configure --sbin-path=/usr/local/nginx/nginx --conf-path=/usr/local/nginx/nginx.conf --pid-path=/usr/local/nginx/nginx.pid --with-http_ssl_module

5.编译和编译安装  

[root@ym nginx-1.10.3]# make && make install

  

 

posted @ 2017-03-22 01:19  silver|bullet  阅读(208)  评论(0)    收藏  举报