我的 Elastic Beanstalk 環境的運行狀況為severe. 我相信這是因為我沒有處理健康檢查。這可以在我的日志中看到:
/var/log/nginx/access.log
----------------------------------------
172.31.75.161 - - [08/Nov/2021:13:21:41 0000] "GET / HTTP/1.1" 404 116 "-" "ELB-HealthChecker/2.0" "-"
172.31.75.161 - - [08/Nov/2021:13:21:41 0000] "GET / HTTP/1.1" 404 116 "-" "ELB-HealthChecker/2.0" "-"
...
43 connect() failed (111: Connection refused) while connecting to upstream, client: 172.XX.XX.XX, server: , request: "GET / HTTP/1.1", upstream: "http://172.XX.XX.XX:8080/"
這是我的 Docker 檔案:
# Build stage
#
FROM maven:3.8.1-jdk-8
ADD src /tmp/src
ADD pom.xml /tmp/pom.xml
RUN mvn -f /tmp/pom.xml clean package
#
# Package stage
#
FROM openjdk:8
COPY --from=0 /tmp/target/para-host-0.0.1-SNAPSHOT.jar /usr/local/lib/para.jar
EXPOSE 5000
ENTRYPOINT ["java","-jar","/usr/local/lib/para.jar"]
所以我的 Spring Boot 應用程式在埠 5000 上運行。這可以在本地和 Elastic Beanstalk 中運行。
到目前為止, 我已經嘗試過使用此依賴項來添加運行狀況檢查功能:
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-actuator
</artifactId>
</dependency>
之后,我能夠在本地運行服務器并像這樣點擊端點:
http://localhost:5000/actuator/health并得到回應:
{
"status": "UP"
}
(這甚至是狀態代碼嗎?)
This is where its broken
In my load balancer in my Elastic Beanstalk environment, it says that my health check path is /. If I edit that value to /actuator/health/, then it simply reverts back to /. I have tried numerous times, even tried deleting it and creating a new one. Nothing. So I gave up on that. Instead, I figured, I would just make the path / return the status code for the health check.
So I made this:
@GetMapping("/")
public ResponseEntity<String> dummyMethod() {
return new ResponseEntity<>("Hello from Dummy-Root-Method", HttpStatus.OK);
}
thinking that now when the health check gets called, it will be successful, but this ALSO does not work. I am able to hit the / endpoint if I run the server locally, but when it is in Elastic Beanstalk, then it thinks the path does not exist. However, my other endpoints DO work. Here is a snippet of the working endpoint (getGroupResults) and then non-working endpoint (dummyMethod):
@GetMapping("/get-group-results")
public ResponseEntity<String> getGroupResults(@RequestBody ObjectNode objectNode)
throws IOException, AddressException, MessagingException {
String groupFolder = objectNode.get("group").asText();
String sendToEmail = objectNode.get("email").asText();
logger.info("Attempting to get results from folder: {}", groupFolder);
String attachmentPath = Test.getMapFromGroupFolder(groupFolder).getAbsolutePath();
String subject = "Results from parallenium";
MailService.sendEmailWithAttachment(sendToEmail, attachmentPath, subject);
return new ResponseEntity<>("Successfully sent results email", HttpStatus.OK);
}
/**
* Dummy response for ELB so we do not receive errors
*
* @return
*/
@GetMapping("/")
public ResponseEntity<String> dummyMethod() {
return new ResponseEntity<>("Hello from Dummy-Root-Method", HttpStatus.OK);
}
This is the response I get when trying to hit the /actuator/health/ endpoint in Elastic Beanstalk used like this http://para-server.us-east-1.elasticbeanstalk.com/actuator/health:
{
"timestamp": "2021-11-08T16:56:20.785 00:00",
"status": 404,
"error": "Not Found",
"path": "/"
}
Again, this works locally. Why?
Summary. What can I do?
- Why can I not change the path to the health check in Elastic Beanstalk console?
- Why does the root path
/work locally, but not in my Elastic Beanstalk environment?
我只是希望我的環境不是紅色的。它作業正常,但有健康檢查錯誤。
uj5u.com熱心網友回復:
驗證 Beanstalk 是否正在運行最新版本的代碼。可能仍在使用添加新映射之前啟動的容器。
uj5u.com熱心網友回復:
問題是,即使我通過 EBS CLI 部署了一個新版本,它實際上并沒有部署我的最新更改。如果您在專案中設定了 git,那么它只會部署最后一次提交。所以我不得不提交我的更改,然后重新部署它并作業。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/354344.html
標籤:爪哇 亚马逊网络服务 弹簧靴 nginx 亚马逊弹性豆茎
上一篇:awsapi網關api密鑰訪問
