Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Elasticsearch 설치 가이드 #6

Open
kimkeunhyeong opened this issue Jan 4, 2023 · 0 comments
Open

Elasticsearch 설치 가이드 #6

kimkeunhyeong opened this issue Jan 4, 2023 · 0 comments
Labels
documentation Improvements or additions to documentation

Comments

@kimkeunhyeong
Copy link
Contributor

kimkeunhyeong commented Jan 4, 2023

설치

Elasticsearch

1. 다운로드

wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.15.1-linux-x86_64.tar.gz
tar tar -xvf elasticsearch-7.15.1-linux-x86_64.tar.gz

elasticsearch 홈페이지에서 파일을 다운받은 뒤, 압축을 해제해 줍니다.
이 예시에서는 7.15.1 버전을 사용하고 있으며, 다른 버전을 사용해도 무방합니다.

2. 계정 생성 및 소유권 변경

useradd elastic
chown -R elastic:elastic elasticsearch-7.15.1

useradd 명령어로 elastic이라는 계정을 생성한 뒤, chown 명령어로 압축 해제한 폴더 및 파일의 소유권을 해당 계정으로 변경해줍니다.

3. Port 설정

elasticsearch-7.15.1/config/elasticsearch.yml

http.port: 30001

Elasticsearch에 접속할 포트를 위 파일(elasticsearch.yml)에서 설정할 수 있습니다.
파일의 맨 밑에 위와 같이 추가하거나, 중간에 주석 처리되어있는 http.port: 9200 의 주석을 해제한 뒤, 원하는 포트로 변경해줍니다.
포트 번호는 방화벽 등에 의해 차단되지 않은, 접근 가능한 포트 번호 로 설정해 주셔야 합니다.

Python

pip install elasticsearch==7.15.1

pip 명령어를 통해 위에서 설치한 elasticsearch를 파이썬에서 사용할 수 있도록 패키지를 설치해 줍니다.
위에서 다운받은 elasticsearch 버전과 동일하게 맞춰주기 위해 7.15.1 버전을 지정하였습니다.

* 다운받은 elasticsearch의 버전과 pip로 설치한 elasticsearch 패키지의 버전이 다른 경우, 사용 중 오류가 발생할 수 있으므로 동일한 버전으로 설치해주세요.

실행

su elastic
nohup ./elasticsearch-7.15.1/bin/elasticsearch &

su elastic 명령어를 통해 elastic 계정으로 전환한 뒤, elasticsearch파일을 실행해줍니다.
처음에는 에러가 발생하는지 확인하기 위해 nohup과 & 없이 실행하는 것을 추천합니다.

from elasticsearch import Elasticsearch
client = Elasticsearch("http://localhost:30001")
client.info()

elasticsearch가 정상적으로 접근 가능한지 확인하기 위해 위 코드를 실행해 줍니다.

Output

{'name': '7ffb304d581e',
 'cluster_name': 'elasticsearch',
 'cluster_uuid': '6q1yxxwgQi-6Ixl0KWphlw',
 'version': {'number': '7.15.1',
  'build_flavor': 'default',
  'build_type': 'tar',
  'build_hash': '83c34f456ae29d60e94d886e455e6a3409bba9ed',
  'build_date': '2021-10-07T21:56:19.031608185Z',
  'build_snapshot': False,
  'lucene_version': '8.9.0',
  'minimum_wire_compatibility_version': '6.8.0',
  'minimum_index_compatibility_version': '6.0.0-beta1'},
 'tagline': 'You Know, for Search'}

잘 동작하는 것을 확인할 수 있습니다.

Troubleshooting

Connection refused

ConnectionError: ConnectionError(<urllib3.connection.HTTPConnection object at 0x7f43c2b79580>:Failed to establish a new connection: [Errno 111] Connection refused) caused by:NewConnectionError(<urllib3.connection.HTTPConnection object at 0x7f43c2b79580>:Failed to establish a new connection: [Errno 111] Connection refused)

위 오류는 Elasticsearch에 접속하려고 할 때 일어날 수 있는 오류입니다.
Elsaticsearch 연결할 수 없는 상태로, 아래 사항들을 확인해보면 좋습니다.

  • config 파일 내의 포트 번호 설정 여부
    • config 파일 내의 http.port: [포트 번호] 가 지정되어 있는지 확인해주세요.
  • client 생성 시 Port번호와 config 내의 포트 번호 일치 여부
    • client = Elasticsearch("http://localhost:[포트 번호]") 의 포트 번호가 config 파일 내의 포트 번호일치하는지 확인해주세요.
  • 지정한 Port의 접속 가능 여부
    • 위 두 가지를 모두 확인했다면, 접속하고자 하는 포트 번호가 방화벽 등에 의해 차단되지 않는, 접속 가능한 포트인지 확인 해주세요.
  • Elasticsearch 실행 여부
    • Elasticsearch가 실행 중이지 않은 경우에도 이 오류가 발생할 수 있습니다.
      ps -ef | grep elasticsearch를 실행하여 java, controller 프로세스가 실행 중인지 확인해줍니다.

실행결과 예시
elastic 12530 12040 24 09:10 pts/13 00:01:17 /opt/ml/elasticsearch-7.15.1/jdk/bin/java -Xshare:auto -Des.networkaddress.cache.ttl=60 -Des.networkaddress.cache.negative.ttl=10 (이하 생략)
elastic 12764 12530 0 09:10 pts/13 00:00:00 /opt/ml/elasticsearch-7.15.1/modules/x-pack-ml/platform/linux-x86_64/bin/controller


can not run elasticsearch as root

WARNING: A terminally deprecated method in java.lang.System has been called
WARNING: System::setSecurityManager has been called by org.elasticsearch.bootstrap.Elasticsearch (file:/opt/ml/elasticsearch-7.15.1/lib/elasticsearch-7.15.1.jar)
WARNING: Please consider reporting this to the maintainers of org.elasticsearch.bootstrap.Elasticsearch
WARNING: System::setSecurityManager will be removed in a future release
[2023-01-04T08:57:25,455][ERROR][o.e.b.ElasticsearchUncaughtExceptionHandler] [7ffb304d581e] uncaught exception in thread [main]
org.elasticsearch.bootstrap.StartupException: java.lang.RuntimeException: can not run elasticsearch as root
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:171) ~[elasticsearch-7.15.1.jar:7.15.1]
at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:158) ~[elasticsearch-7.15.1.jar:7.15.1]
at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:75) ~[elasticsearch-
(생략)
java.lang.RuntimeException: can not run elasticsearch as root
at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:103)
at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:170)
(생략)
For complete error details, refer to the log at /opt/ml/elasticsearch-7.15.1/logs/elasticsearch.log
2023-01-04 08:57:27,240579 UTC [11414] INFO Main.cc@111 Parent process died - ML controller exiting

위 오류는 터미널에서 elasticsearch를 실행할 때 일어날 수 있는 오류입니다.
강조한 부분에서 알 수 있듯, elasticsearch는 root 권한으로 실행할 수 없는데, root로 실행하려고 해서 생기는 오류입니다.

  • su elastic 으로 elastic 계정으로 전환한 뒤, elasticsearch를 다시 실행하면 정상적으로 실행됩니다.
@kimkeunhyeong kimkeunhyeong added the documentation Improvements or additions to documentation label Jan 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

1 participant