[Kafka] Kafka 대용 오픈소스 redpanda 설치 및 설정

Ubuntu 24.04 에 repository 방식으로 설치할 때 다음과 같이 한다.

curl -1sLf \\
  '<https://dl.redpanda.com/public/redpanda/setup.deb.sh>' | sudo -E bash
sudo apt-get install -y redpanda-rpk
sudo apt update
sudo apt install redpanda

broker.dasomoli.org 로 사용한다면, /etc/redpanda/redpanda.yaml 설정 파일 편집. 다음 부분을 고침.

  - address: "broker.dasomoli.org"
    port: 9092

서비스 시작

sudo systemctl enable --now redpanda

서비스 상태 확인

sudo systemctl status redpanda
rpk cluster info --brokers broker.dasomoli.org:9092

사용 중인 토픽 리스트 확인

rpk topic list --brokers broker.dasomoli.org:9092

위의 절차는 인증 없이 사용하게 된다.

[ssh] config 파일에 IP와 Hostname을 함께 지정

~/.ssh/config 파일 안에 hostname을 지정한다면, 그 뒤에 IP 주소를 함께 지정하면 hostname이나 IP 둘 중 어느 하나로 접속해도 같은 설정이 적용된다. 항목을 여러개 만들 필요 없다. 공백으로 구분하면 다 같이 적용된다. 예를 들면 다음과 같다.

Host nas.dasomoli.org 112.145.250.152 192.168.0.204
    HostName nas.dasomoli.org
    User dasomoli
    Port 2048
    IdentityFile ~/.ssh/id_rsa_dasomoli_nas

[Ubuntu] hostname 변경

hostname 또는 cat /etc/hostname 을 입력하면 기존 호스트네임을 볼 수 있다. 새로 셋팅하고 싶다면 다음과 같이 한다.

sudo hostnamectl set-hostname my-new-hostname

그리고 빼먹기 쉬운 게 /etc/hosts 이다.

sudo vi /etc/hosts
127.0.0.1    localhost
127.0.1.1    my-old-hostname  # 기존 호스트네임

이전 호스트 네임 부분을 새 호스트 네임으로 바꿔준다.

127.0.0.1    localhost
127.0.1.1    my-new-hostname

이제 reboot 해주자.

sudo reboot

[Ethereum] 우분투에 node 설치

execution layer client로 geth를, consensus layer client로 Prysm을 사용한다.

geth 설치

sudo add-apt-repository -y ppa:ethereum/ethereum
sudo apt update
sudo apt install -y geth

확인

geth version

부팅 시 자동 실행

sudo vi /etc/systemd/system/geth.service

[Unit]
Description=Ethereum Geth Node
After=network.target

[Service]
Type=simple
User=dasomoli
ExecStart=/usr/bin/geth --mainnet --syncmode "snap" --datadir "/home/dasomoli/geth/data" --http --http.api web3,eth,txpool --http.addr 0.0.0.0
Restart=always
RestartSec=5
LimitNOFILE=8192

[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl start geth
sudo systemctl enable geth
sudo systemctl status geth

위에서는 “snap” 방식을 사용했다. sync mode로 “full”도 가능.

도메인을 연결한다면 설정에 다음 설정을 포함해야 한다.

	--http.corsdomain "*" \
	--http.vhosts "*"

IPC로 geth console 연결

geth attach ipc:/home/dasomoli/geth/data/geth.ipc

로그 확인

journalctl -u geth -f

Prysm 설치

mkdir prysm
cd prysm/
sudo apt update
sudo apt install -y wget
wget <https://raw.githubusercontent.com/prysmaticlabs/prysm/master/prysm.sh>
chmod +x prysm.sh

부팅 시 자동 실행

sudo vi /etc/systemd/system/prysm-beacon.service

[Unit]
Description=Prysm Beacon Chain Client
After=network.target

[Service]
Type=simple
User=dasomoli
ExecStart=/home/dasomoli/prysm/prysm.sh beacon-chain \
    --execution-endpoint=http://localhost:8551 \
    --datadir=/home/dasomoli/prysm/data \
    --jwt-secret=/home/dasomoli/geth/data/geth/jwtsecret \
    --accept-terms-of-use \
    --mainnet \
    --checkpoint-sync-url=https://beaconstate.info --genesis-beacon-api-url=https://beaconstate.info
Restart=always
RestartSec=5
LimitNOFILE=8192

[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl start prysm-beacon
sudo systemctl enable prysm-beacon
sudo systemctl status prysm-beacon

로그 확인

journalctl -u prysm-beacon -f

[Ubuntu] 자동 업데이트 설정

Unattended Upgrade 설치

sudo apt update
sudo apt install unattended-upgrades

자동 업데이트 활성화

sudo dpkg-reconfigure --priority=low unattended-upgrades

설정 파일 편집: sudo vi /etc/apt/apt.conf.d/50unattended-upgrades

Unattended-Upgrade::Allowed-Origins {
    "Ubuntu stable";
    "Ubuntu ${distro_codename}-security";
    "Ubuntu ${distro_codename}-updates";
};

업데이트 주기 설정: sudo vi /etc/apt/apt.conf.d/20auto-upgrades

다음은 패키지 목록 업데이트 간격(1 = 매일), 자동 업데이트 실행 간격 (1 = 매일)

APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Unattended-Upgrade "1";

로그는 다음에서 확인 가능

less /var/log/unattended-upgrades/unattended-upgrades.log

자동 재부팅 설정: sudo vi /etc/apt/apt.conf.d/50unattended-upgrades

다음은 새벽 2시에 자동 리부팅.

Unattended-Upgrade::Automatic-Reboot "true";
Unattended-Upgrade::Automatic-Reboot-Time "02:00";

Transmission SSL 설정하기

토렌트 머신으로 사용할 때 Transmission을 설치해서 사용한다. 우분투에서도 https://blog.dasomoli.org/raspberrypi-torrent-%eb%a8%b8%ec%8b%a0-%eb%a7%8c%eb%93%a4%ea%b8%b0/ 의 내용을 그대로 설정하면 된다. 이대로 설정하면 http 프로토콜을 이용하게 되는데, 여기서 한 단계 더 나아가서 SSL 설정을 통해 https를 쓰도록 설정하자. letsencrypt 인증서를 사용하는 certbot을 사용하면, 설정은 매우 간단하다.

# certbot --apache

실행 예제 화면은 다음과 같다.

root@bamtol:/etc/letsencrypt# certbot --apache
Saving debug log to /var/log/letsencrypt/letsencrypt.log

Which names would you like to activate HTTPS for?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: blog.dasomoli.org
2: torrent.dasomoli.org
3: www.dasomoli.org
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate numbers separated by commas and/or spaces, or leave input
blank to select all options shown (Enter 'c' to cancel): 2

Requesting a certificate for torrent.dasomoli.org

Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/torrent.dasomoli.org/fullchain.pem
Key is saved at:         /etc/letsencrypt/live/torrent.dasomoli.org/privkey.pem
This certificate expires on 2023-06-07.
These files will be updated when the certificate renews.

Deploying certificate
Successfully deployed certificate for torrent.dasomoli.org to /etc/apache2/sites-available/torrent.dasomoli.org-le-ssl.conf
Congratulations! You have successfully enabled HTTPS on https://torrent.dasomoli.org

NEXT STEPS:
- The certificate will need to be renewed before it expires. Certbot can automatically renew the certificate in the background, but you may need to take steps to enable that functionality. See https://certbot.org/renewal-setup for instructions.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
If you like Certbot, please consider supporting our work by:
 * Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
 * Donating to EFF:                    https://eff.org/donate-le
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

그럼 /etc/apache2/sites-enabled/torrent.dasomoli.org-le-ssl.conf 파일이 생성되는데 여기에 SSLProxyEngine on 옵션을 추가해준다. 그럼 이렇게 된다.

<IfModule mod_ssl.c>
<VirtualHost *:443>
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.
        ServerName torrent.dasomoli.org
        ServerAdmin dasomoli@gmail.com

        ProxyPass / http://localhost:9000/
        ProxyPassReverse / http://localhost:9000/

        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn

        ErrorLog ${APACHE_LOG_DIR}/torrent.log
        CustomLog ${APACHE_LOG_DIR}/torrent.access.log combined

        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf


SSLCertificateFile /etc/letsencrypt/live/torrent.dasomoli.org/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/torrent.dasomoli.org/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
SSLProxyEngine on
</VirtualHost>
</IfModule>

이게 끝. apache2 서비스를 재시작한 후 https로 접근한다.

우분투 24.04도 위와 같은 방식으로 설치 가능한데, workaround가 필요하다. appamor가 Nofity에 대해 잘 작동하지 않는 모양이다.

$ sudo systemctl edit --full transmission-daemon.service

Type=Simple로 바꾼다.

[Unit]
Description=Transmission BitTorrent Daemon
Wants=network-online.target
After=network-online.target

[Service]
User=debian-transmission
Type=Simple
ExecStart=/usr/bin/transmission-daemon -f --log-level=error
ExecReload=/bin/kill -s HUP $MAINPID
NoNewPrivileges=true
MemoryDenyWriteExecute=true
ProtectSystem=true
PrivateTmp=true

[Install]
WantedBy=multi-user.target