Skip to content

Commit

Permalink
配置说明
Browse files Browse the repository at this point in the history
  • Loading branch information
codingmiao committed Feb 11, 2018
1 parent 66ae378 commit 681287b
Show file tree
Hide file tree
Showing 3 changed files with 147 additions and 1 deletion.
38 changes: 37 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,38 @@
# ngineureka
ngineureka,一个监控spring boot注册中心(eureka),并将服务映射到nginx负载均衡的工具
一个监控spring cloud注册中心(eureka),并将服务映射到nginx负载均衡的工具

![][1]

当我们用spring cloud部署一套微服务集群后,想要把集群中的服务以rest api的形式给用户使用,显然,我们不可能把所有的application用到的ip和端口暴露给用户。这时候,我们就可以用ngineureka来帮助我们把服务将application服务映射给nginx,然后只需把nginx的端口暴露给用户即可。

ngineureka定期查询注册中心内可用的application,并将它们转换成nginx的配置并reload,这样,便可以通过nginx的反向代理,负载均衡地访问各服务了。

## 修改现有application的配置
使用ngineureka,需要对您application的配置做少量约定,例如:
```
eureka:
client:
serviceUrl:
defaultZone: http://192.168.1.1:10000/eureka/
server:
tomcat:
uri-encoding: UTF-8
port: 11000
context-path: /esrielevation
spring:
application:
name: esrielevation
```
application name必须全小写,context-path需要与application name相同,这也意味着,您application中所有的Controller,都将被加上application name前缀


## 配置和启动ngineureka

[windows下配置和启动][2]

[linux下配置和启动][2]


[1]: http://7xlvcv.com1.z0.glb.clouddn.com/01bbc543-059f-4f2a-8364-dd95a7505deb
[2]: https://github.com/codingmiao/ngineureka/blob/master/wincfg.md "windows下配置和启动"
[3]: https://github.com/codingmiao/ngineureka/blob/master/linuxcfg.md "linux下配置和启动"
55 changes: 55 additions & 0 deletions linuxcfg.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# linux下的配置和使用

## 1、修改config.properties配置信息
一个配置的例子如下:
eurekaUrl为您的eureka注册中心地址
confPath指定一个文件夹,用于存放生成的nginx配置信息
heartbeatCycle指定查询注册中心的周期(秒)
```
eurekaUrl=http://192.168.1.1:10000/eureka
confPath=/usr/local/nginx/conf/apps
heartbeatCycle=300
```

## 2、修改nginx.conf
在相应的位置添加 “include {confPath}/ngineureka_upstream.conf;” “include {confPath}/ngineureka_upstream.conf;”两行,引入ngineureka启动后生成的配置
一个配置的例子如下(仅演示http块):

```
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
#gzip on;
include apps/ngineureka_upstream.conf;
server {
listen 7082;
server_name localhost;
proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
default_type 'text/html';
charset utf-8;
include apps/ngineureka_location.conf;
}
}
```

## 3、修改reload.sh文件
reload.sh文件如下:
```
cd /usr/local/nginx/sbin
./nginx -s reload
```
修改第一行,使得sh命令能够切换到您的nginx根目录
通过chmod命令,赋予reload.sh文件执行权限

## 4、启动
./startup.sh启动服务
您可以通过查看{confPath}/ngineureka_upstream.conf文件,检查配置信息是否正确地添加到nginx

然后,就能通过nginx,访问到您的rest服务了~
55 changes: 55 additions & 0 deletions wincfg.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# windows下的配置和使用

## 1、修改config.properties配置信息
一个配置的例子如下:
eurekaUrl为您的eureka注册中心地址
confPath指定一个文件夹,用于存放生成的nginx配置信息
heartbeatCycle指定查询注册中心的周期(秒)
```
eurekaUrl=http://192.168.1.1:10000/eureka
confPath=D:/nginx-1.8.1/conf/apps
heartbeatCycle=300
```

## 2、修改nginx.conf
在相应的位置添加 “include {confPath}/ngineureka_upstream.conf;” “include {confPath}/ngineureka_upstream.conf;”两行,引入ngineureka启动后生成的配置
一个配置的例子如下(仅演示http块):

```
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
#gzip on;
include apps/ngineureka_upstream.conf;
server {
listen 7082;
server_name localhost;
proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
default_type 'text/html';
charset utf-8;
include apps/ngineureka_location.conf;
}
}
```

## 3、修改reload.bat文件
reload.bat文件如下:
```
D:
cd D:/nginx-1.8.1/
nginx -s reload
```
修改前两行,使得cmd命令能够切换到您的nginx根目录

## 4、启动
双击startup.bat启动服务
您可以通过查看{confPath}/ngineureka_upstream.conf文件,检查配置信息是否正确地添加到nginx

然后,就能通过nginx,访问到您的rest服务了~

0 comments on commit 681287b

Please sign in to comment.