Jongmo-kim / Personal-NAS

0 stars 0 forks source link

홈서버의 포트를 정리합니다. #16

Closed Jongmo-kim closed 2 years ago

Jongmo-kim commented 2 years ago

현재 postgres : 19621, jenkins : 8080, sonarqube : 9000, ssh : 19620 과 같이 포트가 할당되어 있고 각 서버들이 부가적으로 사용하는 포트또한 사용되어지고 있습니다.

(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:19620           0.0.0.0:*               LISTEN      -
tcp        0      0 0.0.0.0:19621           0.0.0.0:*               LISTEN      -
tcp6       0      0 :::9090                 :::*                    LISTEN      -
tcp6       0      0 127.0.0.1:38883         :::*                    LISTEN      3751/java
tcp6       0      0 127.0.0.1:9092          :::*                    LISTEN      3596/java
tcp6       0      0 :::19621                :::*                    LISTEN      -
tcp6       0      0 :::9000                 :::*                    LISTEN      3596/java
tcp6       0      0 127.0.0.1:9001          :::*                    LISTEN      3487/java
tcp6       0      0 127.0.0.1:42991         :::*                    LISTEN      3487/java
tcp6       0      0 :::50000                :::*                    LISTEN      5462/java
tcp6       0      0 :::8080                 :::*                    LISTEN      5462/java
tcp6       0      0 127.0.0.1:38357         :::*                    LISTEN      5751/java
udp6       0      0 :::45258                :::*                                5751/java

이는 도커의 네트워크를 bridge가 아닌 host로 설정해서 발생하는 문제입니다.

도커의 네트워크 구조를 파악하여 원하는 포트만 밖으로 할당되게 합니다 도커 컨테이너 내부에서 로컬 네트워크가 필요한경우 포트만 할당할수 있도록 네트워크를 구성합니다.

Jongmo-kim commented 2 years ago

https://stackoverflow.com/questions/24319662/from-inside-of-a-docker-container-how-do-i-connect-to-the-localhost-of-the-mach

해당 링크를 참고하여 도커 컨테이너에서 로컬 DB에 접속하는 방법을 찾았습니다.

도커 실행시 다음과 같은 명령어를 추가합니다. --add-host=host.docker.internal:172.17.0.1 그러면 도커 컨테이너 내부에서 ping host.docker.internal을 실행시 172.17.0.1로 변환되어 ping 명령어가 실행됩니다.

Jongmo-kim commented 2 years ago
이름 포트
SSH 19620
postgresql 19621
docker 19622
WAS 19623
sonarqube 19624

와 같이 포트를 설정했습니다.

모든 도커 컨테이너의 network를 bridge로 설정했습니다.

Jongmo-kim commented 2 years ago

서버 재부팅시 실행해야하는 명령어들입니다.

sudo service ssh restart
sudo dockerd
sudo /etc/init.d/postgresql restart
sudo chmod 666 /var/run/docker.sock
docker run -d --restart always --name jenkins --add-host=host.docker.internal:172.17.0.1 -p 19622:8080 -v $PWD/jenkins_home:/var/jenkins_home -v /usr/bin/docker:/usr/bin/docker -v /var/run/docker.sock:/var/run/docker.sock jenkins/jenkins
docker run -d --name sonarqube -p 19624:9000 --add-host=host.docker.internal:172.17.0.1 -e sonar.jdbc.url=jdbc:postgresql://host.docker.internal:19621/postgres -e sonar.jdbc.username=sonarqube -e sonar.jdbc.password=sonar-pass --ulimit nofile=65536:65536 sonarqube
docker run -d --name server -p 9090:19623 --add-host=host.docker.internal:172.17.0.1 docker-example:0.0.1

docker run -d --name sonarqube -p 19624:9000 --add-host=host.docker.internal:172.17.0.1 -e sonar.jdbc.url=jdbc:postgresql://host.docker.internal:19621/postgres -e sonar.jdbc.username=sonarqube -e sonar.jdbc.password=sonar-pass --ulimit nofile=65536:65536 sonarqube 에서 --ulimit nofile=65536:65536는 다음 링크를 참고하여 적용했습니다.https://stackoverflow.com/a/58024178

Jongmo-kim commented 2 years ago

포트가 정리되었으므로 이슈를 닫습니다.