ML/MLOps Engineer
virtualbox ubuntu 22.04์— elastic search ์„ค์น˜ ํ›„ ์›๊ฒฉ ์š”์ฒญ ํ…Œ์ŠคํŠธ

์„ค์น˜ ํ™˜๊ฒฝ) virtual box - ubuntu 22.04 (cpu2, memory 4g)
 

์„ค์น˜ ํŒŒ์ผ ๋‹ค์šด๋กœ๋“œ

Elastic ์„ค์น˜ ํŒŒ์ผ ๋งํฌ๋ฅผ ํ™•์ธํ•˜๊ธฐ ์œ„ํ•ด Elastic Search ๊ณต์‹ ํ™ˆํŽ˜์ด์ง€์— ์ ‘์†ํ•ฉ๋‹ˆ๋‹ค.
https://www.elastic.co/kr/downloads/past-releases#elasticsearch

Past Releases of Elastic Stack Software

Looking for a past release of Elasticsearch, Logstash, Kibana, es-hadoop, Shield, Marvel, or our language clients? You're in the right place....

www.elastic.co

์ €๋Š” 8.13.4 ๋ฒ„์ „ ๋‹ค์šด๋กœ๋“œ๋ฅผ ํด๋ฆญํ•˜๊ณ  deb ํŒŒ์ผ์˜ ๋งํฌ๋ฅผ ๋ณต์‚ฌํ–ˆ์Šต๋‹ˆ๋‹ค. 
https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.13.4-amd64.deb

์šฐ๋ถ„ํˆฌ ์„ค์น˜ํŒŒ์ผ์€ DEB ์‚ฌ์šฉ

 
์ด์ œ ์„œ๋ฒ„์— ์ ‘์†ํ•ด์„œ ๋งํฌ๋ฅผ ์‚ฌ์šฉํ•ด์„œ ํŒŒ์ผ์„ ๋‹ค์šด๋กœ๋“œํ•ฉ๋‹ˆ๋‹ค.

wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.13.4-amd64.deb

์„ค์น˜ ์ง„ํ–‰

sudo dpkg -i elasticsearch-8.13.4-amd64.deb

 
์„ค์น˜๊ฐ€ ์™„๋ฃŒ๋˜๋ฉด ์ดˆ๊ธฐ elastic user์˜ ๋น„๋ฐ€๋ฒˆํ˜ธ๊ฐ€ ์ƒ์„ฑ๋ฉ๋‹ˆ๋‹ค.

elastic(superuser)์˜ ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ๋ฉ”๋ชจํ•ด ๋†“์ง€ ์•Š์€ ๊ฒฝ์šฐ `/usr/share/elasticsearch/bin/elasticsearch-reset-password -u elastic` ๋ช…๋ น์–ด๋กœ ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์ดˆ๊ธฐํ™” ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
 

๋ฐฉํ™”๋ฒฝ ์„ค์ •

๊ธฐ๋ณธ ํฌํŠธ์ธ 9200 ํฌํŠธ๋ฅผ ํ—ˆ์šฉํ•ฉ๋‹ˆ๋‹ค. (`sudo apt install firewalld`๋กœ ์„ค์น˜ ํ›„ ์ง„ํ–‰)

sudo firewall-cmd --permanent --zone=public --add-port=9200/tcp
sudo firewall-cmd --reload
sudo firewall-cmd --list-ports

์„œ๋น„์Šค ์‹คํ–‰

es ์œ ์ € ์ƒ์„ฑ

์„œ๋น„์Šค ์‹คํ–‰์— ์•ž์„œ root ๊ถŒํ•œ์„ ๊ฐ€์ง„ ์œ ์ €๋กœ๋Š” elastic search ์‹คํ–‰์ด ๋ถˆ๊ฐ€๋Šฅํ•˜์—ฌ es๋ผ๋Š” ์œ ์ €๋ฅผ ์ƒ์„ฑํ•˜์—ฌ ์ง„ํ–‰ํ–ˆ์Šต๋‹ˆ๋‹ค.

# root ๊ณ„์ •์œผ๋กœ ์ „ํ™˜ (์ด๋ฏธ root ๊ณ„์ •์ด๋ฉด ๋ถˆํ•„์š”)
sudo su -
# root ๊ณ„์ •์—์„œ ์‹คํ–‰
useradd -m es

elastic search์— ํ•„์š”ํ•œ ํด๋”๋“ค์˜ ๊ถŒํ•œ์„ es๋กœ ๋ณ€๊ฒฝํ•ฉ๋‹ˆ๋‹ค.

# elaticsearch ๊ด€๋ จ ๋””๋ ‰ํ„ฐ๋ฆฌ์˜ ์†Œ์œ ์ž๋ฅผ es๋กœ ๋ณ€๊ฒฝ
chown -R es:es /var/log/elasticsearch
chown -R es:es /var/lib/elasticsearch
chown -R es:es /usr/share/elasticsearch
chown -R es:es /etc/elasticsearch
chown -R es:es /etc/default/elasticsearch

์„œ๋น„์Šค ์ž‘์„ฑ

์„œ๋น„์Šค๋ฅผ es ์‚ฌ์šฉ์ž์—์„œ ์‹คํ–‰๋˜๋„๋ก ์ž‘์„ฑํ•ฉ๋‹ˆ๋‹ค. User์™€ Group ์— es๋ฅผ ํ‘œ๊ธฐํ•ฉ๋‹ˆ๋‹ค.

vi /etc/systemd/system/elasticsearch.service
[Unit]
Description=Elasticsearch
Documentation=https://www.elastic.co
Wants=network-online.target
After=network-online.target

[Service]
Environment=ES_HOME=/usr/share/elasticsearch
Environment=ES_PATH_CONF=/etc/elasticsearch
Environment=PID_DIR=/var/run/elasticsearch
Environment=ES_SD_NOTIFY=true
EnvironmentFile=-/etc/default/elasticsearch

WorkingDirectory=/usr/share/elasticsearch

User=es
Group=es

ExecStart=/usr/share/elasticsearch/bin/elasticsearch -p ${PID_DIR}/elasticsearch.pid --quiet
ExecReload=/bin/kill -HUP $MAINPID

TimeoutStopSec=0
KillMode=process
KillSignal=SIGQUIT
SendSIGKILL=no
SuccessExitStatus=143

LimitNOFILE=65535
LimitNPROC=4096
LimitAS=infinity
LimitFSIZE=infinity
TimeoutStartSec=75
Restart=on-failure
RestartSec=5

[Install]
WantedBy=multi-user.target

์„œ๋น„์Šค ํŒŒ์ผ ๊ถŒํ•œ ์„ค์ • ๋ฐ ์„œ๋น„์Šค ํ™œ์„ฑํ™”

sudo chmod 644 /etc/systemd/system/elasticsearch.service
sudo systemctl daemon-reload
sudo systemctl enable elasticsearch.service

์„œ๋น„์Šค ์‹คํ–‰

sudo systemctl start elasticsearch.service
sudo systemctl status elasticsearch.service

 
์—ฌ๊ธฐ์„œ ๊ฐ„ํ—์ ์œผ๋กœ ์žฌ์‹œ๋™ ๋˜๋Š” ๊ฒฝ์šฐ ๋กœ๊ทธ๋ฅผ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค. (root ๊ณ„์ •์—์„œ ํ™•์ธ)

tail -100 /var/log/elasticsearch/elasticsearch.log
tail -100 /var/log/elasticsearch/gc.log

์ €์˜ ๊ฒฝ์šฐ vm์˜ ์‚ฌ์–‘์ด ๋‚ฎ์•„ Elasticsearch์˜ ํž™ ๋ฉ”๋ชจ๋ฆฌ ์„ค์ •์„ ์กฐ์ •ํ•˜์˜€์Šต๋‹ˆ๋‹ค.
(์ฃผ์„์ฒ˜๋ฆฌ ๋˜์–ด์žˆ๋˜ ๋ถ€๋ถ„ -Xms1g, -Xmx1g ๋กœ ์ˆ˜์ •)

# root ๊ณ„์ •์—์„œ ์‹คํ–‰
systemctl stop elasticsearch
vi /etc/elasticsearch/jvm.options
systemctl start elasticsearch

 
๊ทธ๋Ÿผ์—๋„ ๋ถˆ๊ตฌํ•˜๊ณ  ์—๋Ÿฌ๊ฐ€ ๋‚˜์„œ ๋กœ๊ทธ๋ฅผ ํ™•์ธํ•˜๋‹ˆ /var/run/elasticsearch ํด๋”์— ๊ถŒํ•œ์ด ์—†์–ด์„œ ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค.
์„œ๋น„์Šค๋ฅผ ๋‹ค์‹œ ์ข…๋ฃŒํ•˜๊ณ  ๊ถŒํ•œ์„ ๋ถ€์—ฌํ•ด์„œ ์ •์ƒ์ ์œผ๋กœ ์‹คํ–‰๋˜์—ˆ์Šต๋‹ˆ๋‹ค.

systemctl stop elasticsearch
chown -R es:es /var/run/elasticsearch
systemctl start elasticsearch

์›๊ฒฉ ์ ‘์† ํ…Œ์ŠคํŠธ

์œ„์— ์ž‘์—…๊นŒ์ง€ ํ•˜๋ฉด ์„ค์น˜์™€ ์ •์ƒ ์‹คํ–‰๊นŒ์ง€ ์™„๋ฃŒ๋˜๊ณ , ์ด์ œ ์›๊ฒฉ ํ…Œ์ŠคํŠธ๋ฅผ ํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.
๋กœ์ปฌ ํ„ฐ๋ฏธ๋„์„ ํ•˜๋‚˜ ๋” ์—ด์–ด์„œ localhost๋กœ ์ •์ƒ์ž‘๋™ํ•˜๋Š”์ง€ ํ…Œ์ŠคํŠธํ•ฉ๋‹ˆ๋‹ค.

curl -X GET -k -u elastic:[password] https://localhost:9200

๊ฐ™์€ ๋กœ์ปฌ ๋„คํŠธ์›Œํฌ๊ฐ€ ์•„๋‹Œ ์›๊ฒฉ ์ ‘์†์„ ํ—ˆ์šฉํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” config ํŒŒ์ผ์„ ์ˆ˜์ •ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. 
config ํด๋” ๋‚ด์˜ elasticsearch.yml ํŒŒ์ผ ์ˆ˜์ • - network.host ๋ฅผ 0.0.0.0์œผ๋กœ ์ˆ˜์ •ํ•ฉ๋‹ˆ๋‹ค.

# config ํด๋” ๋‚ด์˜ elasticsearch.yml ํŒŒ์ผ ์ˆ˜์ •
vi /etc/elasticsearch/elasticsearch.yml

์ˆ˜์ • ํ›„ ์„œ๋น„์Šค๋ฅผ ์žฌ๊ธฐ๋™ํ•ฉ๋‹ˆ๋‹ค.

service elasticsearch restart

 
vm ์„œ๋ฒ„ ๋ฐ– (์œˆ๋„์šฐ ๋กœ์ปฌ) ์—์„œ curl ์š”์ฒญ์‹œ ์ •์ƒ์ ์œผ๋กœ ์ž‘๋™ํ•˜๋Š” ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

curl -X GET -k -u elastic:[password] https://[vm ip]:9200

 
์ €๋Š” vm ๋„คํŠธ์›Œํฌ ํฌํŠธํฌ์›Œ๋”ฉ ์„ค์ •์—์„œ 9200 ํฌํŠธ๋ฅผ ์ถ”๊ฐ€ํ•ด์ฃผ์—ˆ์Šต๋‹ˆ๋‹ค. (vm ๋„คํŠธ์›Œํฌ ํฌํŠธํฌ์›Œ๋”ฉ ์œผ๋กœ ๊ฒ€์ƒ‰ํ•˜์—ฌ ๋‚˜์˜จ ๊ฒŒ์‹œ๊ธ€๋“ค์„ ์ฐธ๊ณ ํ•˜์—ฌ ์„ค์ •)

 
์—ฌ๊ธฐ๊นŒ์ง€ elastic search๋ฅผ virtual box์— ์„ค์น˜ํ•ด๋ณด๊ณ  ์™ธ๋ถ€์—์„œ ํ˜ธ์ถœํ•˜๋Š” ํ…Œ์ŠคํŠธ๊นŒ์ง€ ์ˆ˜ํ–‰ํ•ด๋ณด์•˜์Šต๋‹ˆ๋‹ค.
๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค.