nginx-阶段一(安装&负载均衡)

安装

安装相关依赖包
sudo yum -y install openssl openssl-devel pcre pcre-devel zlib zlib-devel gcc gcc-c++

解压安装包

链接:https://pan.baidu.com/s/1r3hiU-9vj1kbx0vg9BN_Xg 
提取码:yyds 

 tar -zxvf nginx-1.12.2.tar.gz

 进入解压缩目录,执行(--prefix表示安装到哪个目录)

./configure --prefix=/home/bigdata/shishishell/nginx/nginx
make && make install

注意:

如果不是root用户想启动1024以下的端口,那么就要执行下面的命令(指定允许启动端口的程序)

sudo setcap cap_net_bind_service=+eip /home/bigdata/shishishell/nginx/nginx/sbin/nginx

启动程序

./nginx

查看执行情况

ps -ef |grep nginx

访问master的80端口(根据自己启动的主机而定)

http://master/

 nginx-阶段一(安装&负载均衡)_第1张图片

重启 Nginx
./nginx -s reload
关闭 Nginx
./nginx -s stop
通过配置文件启动
./nginx -c /usr/local/nginx/conf/nginx.conf

反向代理

 nginx的配置


#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;
	#反向代理的配置
	upstream webservers{
      server  localhost:8080 weight=8;
   }
  
    #gzip  on;

    server {
        listen       80;
        server_name  localhost;
		#负载均衡和上面设置的一样,这里也就是访问到nginx会会访问localhost:8080
		location / {
             #转发到负载服务上
            proxy_pass http://webservers;
         }

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}

你可能感兴趣的:(工具篇,大数据)