CentOS 6.10 基于nginx搭载负载均衡服务器过程记录

CentOS 6.10 基于nginx搭载负载均衡服务器过程记录

总体来说比较顺利,比配置Jupyter时坑少很多

1、基本环境配置

共创建了三台服务器:

1、负载均衡服务器

2、实际系统的服务器1

3、实际系统的服务器2

2、安装Nginx

我的服务也是运行在Nginx上,所以三台服务都需要安装Nginx

1、安装wget、gcc工具

yum -y install wget gcc

2、安装pcre,openssl的devel包

yum -y install openssl-devel pcre-devel

3、下载nginx

mkdir /usr/mytools
cd /usr/mytools
wget http://nginx.org/download/nginx-1.19.1.tar.gz

4、安装nginx

cd nginx-1.19.1
./congigure --prefix=/usr/local/nginx;
make && make install;

5、启动服务

/usr/local/nginx/sbin/nginx

6、把nginx设置为service,可以使用 service nginx进行操作

a)安装service命令

yum install initscripts -y

b)操作nginx的服务

cd /etc/init.d

# 如果没有vim,运行  yum -y install vim
vim nginx

在打开的文件中,粘贴如下内容

#!/bin/bash
#Startup script for the nginx Web Server
#chkconfig: 2345 85 15
nginx=/usr/local/nginx/sbin/nginx
conf=/usr/local/nginx/conf/nginx.conf
case $1 in
start)
echo -n "Starting Nginx"
$nginx -c $conf
echo " done."
;;
stop)
echo -n "Stopping Nginx"
killall -9 nginx
echo " done."
;;
test)
$nginx -t -c $conf
echo "Success."
;;
reload)
echo -n "Reloading Nginx"
ps auxww | grep nginx | grep master | awk '{print $2}' | xargs kill -HUP
echo " done."
;;
restart)
$nginx -s reload
echo "reload done."
;;
*)
echo "Usage: $0 {start|restart|reload|stop|test|show}"
;;
esac

c)执行以下语句

chmod 755 nginx
chkconfig --add nginx
chkconfig nginx on

d) 测试

service nginx reload

3、配置负载均衡

打开/usr/local/nginx/conf/nginx.conf

vim /usr/local/nginx/conf/nginx.conf

在http{}内添加:

# 注意:centoslvs名称为自定义名称,下面配置Server时会用到
    upstream centoslvs {                                                        
        #server IP/HostName:Port;                                           
        server www.baidu.com;
        server 39.107.254.46:8090;                                           
    }

修改Server相关配置

   server {                                                                    
        listen       80;                                                        
        server_name  localhost;                                                 
                                                                                
        #charset koi8-r;                                                        
                                                                                
        #access_log  logs/host.access.log  main;                                
        
        # 此处名称centoslvs为上面定义的Upstream的名称                                                                        
        location / {                                                            
            proxy_pass http://centoslvs;                                        
        }                                                                       
                                                                                
        #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;    
        }
    }
service nginx reload

测试,通过

 

 

 

 

EOF

 

你可能感兴趣的:(CentOS 6.10 基于nginx搭载负载均衡服务器过程记录)