作业一:nginx服务
1.二进制安装nginx
2.作为web服务修改配置文件
3.让配置生效,验证配置
[root@localhost ~]# systemctl stop firewalld.service[root@localhost ~]# setenforce 0 [root@localhost ~]# sed -i ‘s#SELINUX=enforcing#SELINUX=disabled#g‘ /etc/sysconfig/selinux [root@localhost ~]# yum install -y epel-release[root@localhost ~]# yum install -y nginx 作为web服务修改配置文件在server中location中加(更改网站根目录) location / { root /var/www/html; index index.html; }[root@localhost nginx]# mkdir /var/www/html -p[root@localhost nginx]# echo web1 > /var/www/html/index.html [root@localhost nginx]# systemctl start nginx.service [root@localhost nginx]# systemctl reload nginx.service [root@localhost nginx]# netstat -lntup |grep nginx [root@localhost nginx]# systemctl enable nginx.service 让配置生效,验证配置浏览器访问
http://192.168.2.2或[root@localhost nginx]# curl http://127.0.0.1web1[root@localhost nginx]# curl
http://192.168.2.2web1
作业二:nfs服务
二进制安装nfs
作为共享存储挂载在三台web的网站根目录下
实现,在任意一台web上修改的结果,其余两台都可以看到
nfs服务器:
192.168.2.2yum -y install rpcbind nfs-utils[root@bogon ~]# systemctl enable rpcbind.service[root@bogon ~]# systemctl start rpcbind.service[root@bogon ~]# cat /etc/exports/share
192.168.2.0/24(rw,sync)[root@bogon ~]# chmod -R o+rwx /share[root@bogon ~]# systemctl enable nfs-server.service[root@bogon ~]# systemctl start nfs-server.service[root@bogon ~]# showmount -e 127.0.0.1Export list for 127.0.0.1:/share
192.168.2.0/24[root@bogon ~]# exportfs/share
192.168.2.0/24web1服务器:
192.168.2.3yum -y install rpcbind nfs-utils[root@bogon ~]# systemctl enable rpcbind.service[root@bogon ~]# systemctl start rpcbind.service[root@bogon ~]# showmount -e
192.168.2.2Export list for
192.168.2.2:/share
192.168.2.0/24[root@bogon ~]# mkdir /var/www/html/share -p[root@bogon ~]# mount -t nfs
192.168.2.2:/share /var/www/html/share/[root@bogon ~]# df -h 文件系统 容量 已用 可用 已用% 挂载点/dev/mapper/centos-root 18G 4.8G 13G 28% /devtmpfs 222M 0 222M 0% /devtmpfs 237M 0 237M 0% /dev/shmtmpfs 237M 5.0M 233M 3% /runtmpfs 237M 0 237M 0% /sys/fs/cgroup/dev/sda1 497M 159M 339M 32% /boottmpfs 48M 0 48M 0% /run/user/0tmpfs 48M 0 48M 0% /run/user/1000
192.168.2.2:/share 18G 4.8G 13G 28% /var/www/html/shareweb2服务器:
192.168.2.4yum -y install rpcbind nfs-utils[root@bogon ~]# systemctl enable rpcbind.service[root@bogon ~]# systemctl start rpcbind.service[root@bogon ~]# showmount -e
192.168.2.2Export list for
192.168.2.2:/share
192.168.2.0/24[root@bogon ~]# mkdir /var/www/html/share -p[root@bogon ~]# mount -t nfs
192.168.2.2:/share /var/www/html/share/[root@bogon ~]# df -h 文件系统 容量 已用 可用 已用% 挂载点/dev/mapper/centos-root 18G 4.8G 13G 28% /devtmpfs 222M 0 222M 0% /devtmpfs 237M 0 237M 0% /dev/shmtmpfs 237M 5.0M 233M 3% /runtmpfs 237M 0 237M 0% /sys/fs/cgroup/dev/sda1 497M 159M 339M 32% /boottmpfs 48M 0 48M 0% /run/user/0tmpfs 48M 0 48M 0% /run/user/1000
192.168.2.2:/share 18G 4.8G 13G 28% /var/www/html/shareweb3服务器:
192.168.2.5yum -y install rpcbind nfs-utils[root@bogon ~]# systemctl enable rpcbind.service[root@bogon ~]# systemctl start rpcbind.service[root@bogon ~]# showmount -e
192.168.2.2Export list for
192.168.2.2:/share
192.168.2.0/24[root@bogon ~]# mkdir /var/www/html/share -p[root@bogon ~]# mount -t nfs
192.168.2.2:/share /var/www/html/share/[root@bogon ~]# df -h 文件系统 容量 已用 可用 已用% 挂载点/dev/mapper/centos-root 18G 4.8G 13G 28% /devtmpfs 222M 0 222M 0% /devtmpfs 237M 0 237M 0% /dev/shmtmpfs 237M 5.0M 233M 3% /runtmpfs 237M 0 237M 0% /sys/fs/cgroup/dev/sda1 497M 159M 339M 32% /boottmpfs 48M 0 48M 0% /run/user/0tmpfs 48M 0 48M 0% /run/user/1000
192.168.2.2:/share 18G 4.8G 13G 28% /var/www/html/share测试:web1:[root@bogon share]# echo "123" > /var/www/html/share/1.txtweb2:[root@bogon ~]# cat /var/www//html/share/1.txt 123web3:[root@bogon ~]# cat /var/www//html/share/1.txt 123
作业三:nginx反向代理三台web
实现基于轮询的方式调度三台web,并验证结果
实现基于权重的方式调度三台web,并验证结果
实现基于hash的方式调用三台web,并验证结果
(1)Nginx反向代理:实现基于轮询的方式http { upstream pythonweb{ server
192.168.2.3:80; server
192.168.2.4:80; server
192.168.2.5:80; } server{ location / { proxy_pass
http://pythonweb; } }[root@bogon ~]# systemctl reload nginx.service [root@bogon ~]# systemctl restart nginx.service (2)Nginx反向代理:实现基于权重的方式http { upstream pythonweb{ server
192.168.2.3:80 weight=3; server
192.168.2.4:80; server
192.168.2.5:80; } server{ location / { proxy_pass
http://pythonweb; } }[root@bogon ~]# systemctl reload nginx.service [root@bogon ~]# systemctl restart nginx.service (2)Nginx反向代理:实现基于权重的方式http { upstream pythonweb{ ip_hash; server
192.168.2.3:80; server
192.168.2.4:80; server
192.168.2.5:80; } server{ location / { proxy_pass
http://pythonweb; } }[root@bogon ~]# systemctl reload nginx.service [root@bogon ~]# systemctl restart nginx.service
作业四:nginx反向代理+三台web+nfs共享存储实现集群配置
作业2中nfs共享的目录是/var/www/html/share
作业3中nginx反向代理+3台web发布的目录是/var/www/html
将3台web的发布目录修改即可:
作为web服务修改配置文件
在server中location中加(更改网站根目录)
location / {
root /var/www/html/share;
index index.html;
}
[root@bogon share]# cat /var/www/html/share/index.html
web123
[root@bogon html]# systemctl restart nginx.service
浏览器测试
作业五:源码安装nginx,并按照作业一描述的那样去测试使用
[root@bogon ~]# mkdir /application[root@bogon ~]# yum erase nginx -y[root@bogon ~]# yum install gcc-* glibc-* openssl openssl-devel pcre pcre-devel zlib zlib-devel -y[root@bogon ~]# wget
http://nginx.org/download/nginx-1.11.10.tar.gz[root@bogon ~]# tar xf nginx-1.11.10.tar.gz [root@bogon ~]#cd nginx-1.11.10/[root@bogon nginx-1.11.10]# ls -l 总用量 704drwxr-xr-x. 6 1001 1001 4096 3月 20 19:34 auto-rw-r--r--. 1 1001 1001 274992 2月 14 23:36 CHANGES-rw-r--r--. 1 1001 1001 419007 2月 14 23:36
CHANGES.rudrwxr-xr-x. 2 1001 1001 4096 3月 20 19:34 conf-rwxr-xr-x. 1 1001 1001 2481 2月 14 23:36 configuredrwxr-xr-x. 4 1001 1001 68 3月 20 19:34 contribdrwxr-xr-x. 2 1001 1001 38 3月 20 19:34 html-rw-r--r--. 1 1001 1001 1397 2月 14 23:36 LICENSEdrwxr-xr-x. 2 1001 1001 20 3月 20 19:34 man-rw-r--r--. 1 1001 1001 49 2月 14 23:36 READMEdrwxr-xr-x. 9 1001 1001 84 3月 20 19:34 src./configure --sbin-path=/application/nginx/nginx --conf-path=/application/nginx/nginx.conf --pid-path=/application/nginx/nginx.pid --with-http_ssl_modulemakemake install启动:/application/nginx/nginx检测:/application/nginx/nginx -t停止:/application/nginx/nginx -s stop重载:/application/nginx/nginx -s reload 配置文件:/application/nginx/nginx.conf vim /application/nginx/nginx.conf location / { root /var/www/html/share; index index.html index.htm; }重载:/application/nginx/nginx -s reload
NFS, web,负载均衡,Nginx yum 源码安装
原文:http://www.cnblogs.com/Baby-Lady/p/6588747.html