springcloud python 注册到 eureca/gateway
tornado注册
import tornado.httpserver
import tornado.ioloop
import tornado.options
import tornado.web
import py_eureka_client.eureka_client as eureka_client
from tornado.options import define, options
define("port", default=3333, help="run on the given port", type=int)
class IndexHandler(tornado.web.RequestHandler):
def get(self):
username = self.get_argument("username", "Hello")
self.write(username + ", Administrator User!")
def post(self):
username = self.get_argument("username", "Hello")
self.write(username + ", Administrator User!")
class MainHandler(tornado.web.RequestHandler):
def get(self):
username = self.get_argument("username", "Hello")
self.write(username + ", Coisini User!")
def post(self):
username = self.get_argument("username", "Hello")
self.write(username + ", Coisini User!")
def main():
tornado.options.parse_command_line()
# eureka_client.EurekaClient(eureka_server="http://admin:adminEureka@127.0.0.1:8761/eureka/",instance_port=3333)
client = eureka_client.EurekaClient(eureka_server="http://admin:adminEureka@127.0.0.1:8761/eureka/",
instance_ip='10.13.25.129', app_name="sb-business-statistics",
instance_port=3333)
app = tornado.web.Application(handlers=[(r"/test", IndexHandler), (r"/main", MainHandler)])
http_server = tornado.httpserver.HTTPServer(app)
http_server.listen(options.port)
client.start()
tornado.ioloop.IOLoop.instance().start()
if name == "main":
main()
django注册
注册时注册上电脑名识别不出来,需要注册上ip,只要将instance_host改为ip即可
client = eureka_client.EurekaClient(eureka_server="http://admin:adminEureka@127.0.0.1:8761/eureka/",
# instance_id=options.ip+':'+str(options.port),
# home_page_url=options.ip+':'+str(options.port),
instance_host=options.ip,
instance_ip=options.ip, app_name="sb-business-statistics",
instance_port=options.port)
client.start()
动态获取ip
def get_host_ip():
try:
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(('8.8.8.8', 80))
ip = s.getsockname()[0]
finally:
s.close()
return ip
将项目发布到k8s docker
编写系统镜像
FROM d897172f819b
WORKDIR /app
COPY srofd.zip /app
RUN unzip srofd.zip
RUN rm srofd.zip
WORKDIR /app/srofd
RUN chmod a+x /usr/run.sh
RUN chmod -R 777 /usr/run.sh
EXPOSE 8080
ENTRYPOINT ["sh","/usr/run.sh"]、ENTRYPOINT [ "/run.sh", "run" ]、CMD ["./startup.sh"]
通过脚本启动
错误解决办法
WARNING: IPv4 forwarding is disabled. Networking
执行echo "net.ipv4.ip_forward=1" >>/usr/lib/sysctl.d/00-system.conf
systemctl restart network && systemctl restart docker
java gateway
---配置eureca
eureka:
client:
serviceUrl:
defaultZone: http://admin:adminEureka@${EurekaIp:10.191.231.188}:8080/eureka/
instance:
prefer-ip-address: true
feign:
hystrix:
enabled: true
ribbon
ribbon:
ConnectionTimeout: 10000
ReadTimeout: 10000
Hystrix
hystrix:
command:
default:
execution:
isolation:
thread:
timeoutInMilliseconds: 60000
调整熔断器闭合断开状态
hystrix.command.default.metrics.rollingStats.timeInMilliseconds=50000
前提条件,一定时间内发起一定数量的请求。 也就是5秒钟内(这个5秒对应下面的滚动窗口长度)至少请求1次,熔断器才发挥起作用。 默认20
hystrix.command.default.circuitBreaker.requestVolumeThreshold=1
错误百分比。达到或超过这个百分比,熔断器打开。 比如:5秒内有4个请求,2个请求超时或者失败,就会自动开启熔断
hystrix.command.default.circuitBreaker.errorThresholdPercentage=50 是指50%失败超时达到一半时打开熔断
gateway参数优化
System.setProperty("reactor.netty.pool.leasingStrategy", "lifo");
spring.cloud.gateway.httpclient.pool.max-idle-time=PT1S
spring.cloud.gateway.httpclient.connect-timeout=2000
spring.cloud.gateway.httpclient.response-timeout=PT30S
浙公网安备 33010602011771号