linux之nginx服务

一、nginx服务二进制安装nginx包

  yum install epel-release -y (安装扩展源)

  yum install nginx -y    (安装nginx软件)

  vim /etc/nginx/nginx.conf

  

作为web服务修改配置文件  

  cd /usr/share/nginx/html  (进入web文件目录下)

  vim /etc/nginx/nginx.conf 查看配置文件

  mkdir  /usr/share/nginx/html/a/b -p  创建文件

  echo 'hello word 1' > mkdir  /usr/share/nginx/html/a/b/c.txt 编辑内容

  systemctl starts nginx      要想让软件读你刚配置的文件,就需要重新启动软件

  systemctl status nginx  查看状态   

  systemctl stop firewalld     关闭防火墙

让配置生效,验证配置

二、nfs服务二进制安装nfs

安装nfs
[root@localhost ~]#yum install rpcbind nfs-utils -y  
[root@localhost ~]#mkdir /share
[root@localhost ~]#mount /dev/sdb1 /share
[root@localhost ~]# chmod o+w /share
[root@localhost ~]# rpm -qa |grep rpcbind
    rpcbind-0.2.0-38.el7.x86_64
[root@localhost ~]# rpm -qa |grep nfs-utils^C
[root@localhost ~]# rpm -qa |grep nfs-utils
    nfs-utils-1.3.0-0.33.el7_3.x86_64
[root@localhost ~]# touch /share/share.txt
[root@localhost ~]# echo gongxiang > /share/share.txt 
[root@localhost ~]# vim /etc/exports
    /share 192.168.238.0/24(rw,sync,fsid=0)
[root@localhost ~]# systemctl start nfs-server.service
[root@localhost ~]# systemctl enable nfs-server.service
[root@localhost ~]# systemctl restart nfs-server.service
[root@localhost ~]# systemctl status nfs-server.service
[root@localhost ~]# systemctl status nfs-server.service 
[root@localhost ~]# exportfs
[root@localhost ~]# mount -t nfs 192.168.238.15:/share /var/www/html/

  

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

 

[root@localhost ~]# chmod -R o+w /share/
[root@localhost ~]# mount -t nfs 193.168.238.15:/share /var/www/html/
[root@localhost ~]# touch /var/www/html/web1.txt
[root@localhost ~]# echo webasfdasda > /var/www/html/web1.txt
[root@localhost ~]# touch /var/www/html/index.html
[root@localhost ~]# echo hello > /var/www/html/index.html

  

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

 

 

 

作业三:nginx反向代理三台web
实现基于轮询的方式调度三台web,并验证结果

 http{
     upstream pw {
        server 192.168.238.16:80;
        server 192.168.238.17:80;
         }

}


location / {
            proxy_pass http://pw;
        }

  

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

upstream pw {
        ip_hash;
        server 192.168.238.16:80 weight=3;
        server 192.168.238.17:80;
         }

  systemctl restart nginx #重启nginx服务

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

upstream pw {
        ip_hash;
        server 192.168.238.16:80;
        server 192.168.238.17:80;
         }
systemctl reload nginx

作业四:

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

 

[root@localhost ~]# tail -f /var/log/nginx/access.log 
192.168.238.15 - - [21/Mar/2017:07:15:43 +0800] "GET / HTTP/1.0" 200 5 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36" "-"

  

作业五:

源码安装nginx,并按照作业一描述的那样去测试使用

 

[root@localhost ~]# yum remove nginx
[root@localhost ~]# useradd -s /sbin/nologin -M www
[root@localhost ~]# yum -y install  pcre pcre-devel openssl openssl-devel
[root@localhost ~]# wget http://nginx.org/download/nginx-1.10.3.tar.gz
[root@localhost ~]# tar xf nginx-1.10.3.tar.gz
[root@localhost nginx-1.10.3]# cd nginx-1.10.3/
[root@localhost nginx-1.10.3]#./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module --with-http_stub_status_module --with-file-aio --with-stream
[root@localhost ~]# make && make install
[root@localhost ~]# /usr/local/nginx/sbin/nginx -t
[root@localhost ~]# nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
[root@localhost ~]# nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@localhost ~]# echo "123456789" > /usr/local/nginx/html/index.html
[root@localhost ~]# /usr/local/nginx/sbin/nginx
[root@localhost ~]# curl 192.168.238.15
123456789

  

posted @ 2017-03-20 18:05  beiguuu  阅读(127)  评论(0)    收藏  举报