웹사이트 검색

Ubuntu 22.04에 Matrix Synapse 채팅 서버를 설치하는 방법


이 튜토리얼은 다음 OS 버전에 대해 존재합니다.

  • Ubuntu 22.04(Jammy Jellyfish)
  • Ubuntu 18.04(Bionic Beaver)

이 페이지에서

  1. 전제 조건
  2. 시작하기\n
  3. Ubuntu 22.04에 Matrix Synapse 설치
  4. 매트릭스 시냅스 구성
  5. Nginx를 Matrix Synapse용 역방향 프록시로 구성\n
  6. 슈퍼 사용자 계정 만들기
  7. Lets Encrypt를 사용한 Secure Matrix Synapse\n
  8. 액세스 매트릭스 시냅스
  9. 결론

Matrix는 메시징 및 VoIP 서비스에 사용되는 무료 오픈 소스 웹 기반 솔루션입니다. VoIP 및 채팅을 통해 다른 서비스 공급자의 다른 사용자와 통신할 수 있는 개방형 표준 VOIP 프로토콜입니다. 단일 제어 및 장애 지점이 없는 분산 및 연합 채팅 서버를 구축하기 위한 RESTful HTTP JSON API를 제공하고 API에 대한 모든 참조를 제공합니다. Python으로 작성되었으며 홈 서버를 만들고 모든 사용자 개인 정보와 채팅 기록을 저장할 수 있습니다.

이 게시물에서는 Ubuntu 22.04에 Matrix Synapse를 설치하는 방법을 보여줍니다.

전제 조건

  • Ubuntu 22.04를 실행하는 서버.\n
  • 서버 IP를 가리키는 유효한 도메인 이름입니다.\n
  • 루트 암호는 서버에서 구성됩니다.\n

시작하기

먼저 시스템 패키지를 업데이트된 버전으로 업데이트해야 합니다. 다음 명령으로 수행할 수 있습니다.

apt update -y

모든 패키지 인덱스가 업데이트되면 다음 명령을 사용하여 다른 필수 종속성을 설치합니다.

apt install curl wget gnupg2 apt-transport-https -y

모든 종속성이 설치되면 다음 단계로 진행할 수 있습니다.

Ubuntu 22.04에 Matrix Synapse 설치

기본적으로 Matrix Synapse 패키지는 Ubuntu 22.04 기본 리포지토리에 포함되어 있지 않습니다. 따라서 Matrix Synapse 공식 리포지토리를 APT에 추가해야 합니다.

먼저 다음 명령을 사용하여 Matrix Synapse GPG 키를 다운로드하고 추가합니다.

wget -qO /usr/share/keyrings/matrix-org-archive-keyring.gpg https://packages.matrix.org/debian/matrix-org-archive-keyring.gpg

다음으로 다음 명령을 사용하여 Matrix Synapse 리포지토리를 APT에 추가합니다.

echo "deb [signed-by=/usr/share/keyrings/matrix-org-archive-keyring.gpg] https://packages.matrix.org/debian/ $(lsb_release -cs) main" | tee /etc/apt/sources.list.d/matrix-org.list

그런 다음 리포지토리를 업데이트하고 다음 명령을 사용하여 Matrix Synapse 패키지를 설치합니다.

apt-get update -y
apt-get install matrix-synapse-py3 -y

설치하는 동안 아래와 같이 도메인 이름을 정의하라는 메시지가 표시됩니다.

도메인 이름을 입력하고 Enter 키를 누릅니다. 익명 통계를 보고하라는 요청을 받게 됩니다.

계속하려면 예를 선택하고 Enter 키를 누르십시오.

설치가 완료되면 Matrix 서비스를 시작하고 아래 명령을 사용하여 시스템 재부팅 시 시작되도록 활성화합니다.

systemctl start matrix-synapse
systemctl enable matrix-synapse

다음 명령을 사용하여 Matrix Synapse의 상태를 확인할 수도 있습니다.

systemctl status matrix-synapse

다음과 같은 결과가 표시됩니다.

? matrix-synapse.service - Synapse Matrix homeserver
     Loaded: loaded (/lib/systemd/system/matrix-synapse.service; enabled; vendor preset: enabled)
     Active: active (running) since Sat 2022-06-04 08:01:22 UTC; 3s ago
    Process: 1916 ExecStartPre=/opt/venvs/matrix-synapse/bin/python -m synapse.app.homeserver --config-path=/etc/matrix-synapse/homeserver.ya>
   Main PID: 1923 (python)
      Tasks: 8 (limit: 9460)
     Memory: 78.6M
        CPU: 4.911s
     CGroup: /system.slice/matrix-synapse.service
             ??1923 /opt/venvs/matrix-synapse/bin/python -m synapse.app.homeserver --config-path=/etc/matrix-synapse/homeserver.yaml --config>

Jun 04 08:01:17 ubuntu2204 systemd[1]: Starting Synapse Matrix homeserver...
Jun 04 08:01:22 ubuntu2204 matrix-synapse[1923]: This server is configured to use 'matrix.org' as its trusted key server via the
Jun 04 08:01:22 ubuntu2204 matrix-synapse[1923]: 'trusted_key_servers' config option. 'matrix.org' is a good choice for a key
Jun 04 08:01:22 ubuntu2204 matrix-synapse[1923]: server since it is long-lived, stable and trusted. However, some admins may
Jun 04 08:01:22 ubuntu2204 matrix-synapse[1923]: wish to use another server for this purpose.
Jun 04 08:01:22 ubuntu2204 matrix-synapse[1923]: To suppress this warning and continue using 'matrix.org', admins should set
Jun 04 08:01:22 ubuntu2204 matrix-synapse[1923]: 'suppress_key_server_warning' to 'true' in homeserver.yaml.
Jun 04 08:01:22 ubuntu2204 matrix-synapse[1923]: --------------------------------------------------------------------------------
Jun 04 08:01:22 ubuntu2204 matrix-synapse[1923]: Config is missing macaroon_secret_key

이 시점에서 Matrix Synapse 서비스가 시작되고 포트 8008에서 수신 대기합니다. 다음 명령으로 확인할 수 있습니다.

ss -antpl | grep python

다음과 같은 결과가 표시됩니다.

LISTEN 0      50         127.0.0.1:8008      0.0.0.0:*    users:(("python",pid=1950,fd=12))        
LISTEN 0      50             [::1]:8008         [::]:*    users:(("python",pid=1950,fd=11))   

매트릭스 시냅스 구성

Matrix Synapse를 설치한 후 구성해야 합니다. 먼저 다음 명령을 사용하여 암호를 생성합니다.

cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1

다음과 같은 결과가 표시됩니다.

R3jvgiDYyhh5XgduDPsgtwxPDiar8q2s

다음으로 Matrix Synapse 기본 구성 파일을 편집합니다.

nano /etc/matrix-synapse/homeserver.yaml

바인드 주소를 정의하고 등록을 비활성화하고 아래와 같이 비밀을 정의하십시오.

    bind_addresses: ['127.0.0.1']
    enable_registration: false
    registration_shared_secret: "R3jvgiDYyhh5XgduDPsgtwxPDiar8q2s"

파일을 저장하고 닫은 다음 Matrix Synapse 서비스를 다시 시작하여 변경 사항을 적용합니다.

systemctl restart matrix-synapse

Nginx를 Matrix Synapse의 역방향 프록시로 구성

Nginx를 Matix Synapse의 리버스 프록시로 구성하는 것이 좋습니다. 먼저 다음 명령을 사용하여 Nginx 웹 서버 패키지를 설치합니다.

apt-get install nginx -y

Nginx가 설치되면 Nginx 가상 호스트 구성 파일을 만듭니다.

nano /etc/nginx/conf.d/matrix.conf

다음 구성을 추가합니다.

server {
listen 80;
server_name matrix.linuxbuz.com;
location / {
proxy_pass http://localhost:8008;
proxy_set_header X-Forwarded-For $remote_addr;
}
}

파일을 저장하고 닫고 다음 명령을 사용하여 Nginx 구성을 확인합니다.

nginx -t

다음과 같은 결과가 표시됩니다.

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

그런 다음 Nginx 서비스를 다시 시작하여 변경 사항을 적용합니다.

systemctl restart nginx

다음 명령을 사용하여 Nginx 서비스의 상태를 확인할 수도 있습니다.

systemctl status nginx

다음 출력이 표시되어야 합니다.

? nginx.service - A high performance web server and a reverse proxy server
     Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
     Active: active (running) since Sat 2022-06-04 08:06:22 UTC; 26s ago
       Docs: man:nginx(8)
    Process: 2433 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
    Process: 2434 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
   Main PID: 2436 (nginx)
      Tasks: 5 (limit: 9460)
     Memory: 4.8M
        CPU: 58ms
     CGroup: /system.slice/nginx.service
             ??2436 "nginx: master process /usr/sbin/nginx -g daemon on; master_process on;"
             ??2437 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""
             ??2438 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""
             ??2439 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""
             ??2440 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""

Jun 04 08:06:22 ubuntu2204 systemd[1]: Starting A high performance web server and a reverse proxy server...
Jun 04 08:06:22 ubuntu2204 systemd[1]: Started A high performance web server and a reverse proxy server.

슈퍼 사용자 계정 만들기

다음으로 관리 사용자 계정을 만들고 Matrix Synapse에 액세스하기 위한 암호를 설정해야 합니다.

register_new_matrix_user -c /etc/matrix-synapse/homeserver.yaml http://localhost:8008

관리자 사용자 계정을 제공하고 아래와 같이 비밀번호를 설정하십시오.

New user localpart [root]: matrixadmin
Password: 
Confirm password: 
Make admin [no]: yes
Sending registration request...
Success!

Lets Encrypt를 사용한 Secure Matrix Synapse

또한 Lets Encrypt SSL로 Matrix Synapse를 보호하는 것이 좋습니다. 먼저 다음 명령을 사용하여 Certbot 클라이언트 패키지를 설치합니다.

apt-get install certbot python3-certbot-nginx -y

Certbot 패키지가 설치되면 다음 명령을 실행하여 Lets Encrypt SSL을 설치합니다.

certbot

이메일 주소를 제공하고 서비스 약관에 동의하라는 메시지가 표시됩니다.

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Enter email address (used for urgent renewal and security notices)
 (Enter 'c' to cancel): 

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server. Do you agree?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing, once your first certificate is successfully issued, to
share your email address with the Electronic Frontier Foundation, a founding
partner of the Let's Encrypt project and the non-profit organization that
develops Certbot? We'd like to send you email about our work encrypting the web,
EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y
Account registered.

SSL을 설치할 웹사이트를 선택하라는 메시지가 표시됩니다.

Which names would you like to activate HTTPS for?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: matrix.linuxbuz.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate numbers separated by commas and/or spaces, or leave input
blank to select all options shown (Enter 'c' to cancel): 1

1을 입력하고 Enter 키를 눌러 Lets Encrypt SSL을 웹사이트에 설치합니다.

Requesting a certificate for matrix.linuxbuz.com

Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/matrix.linuxbuz.com/fullchain.pem
Key is saved at:         /etc/letsencrypt/live/matrix.linuxbuz.com/privkey.pem
This certificate expires on 2022-09-02.
These files will be updated when the certificate renews.
Certbot has set up a scheduled task to automatically renew this certificate in the background.

Deploying certificate
Successfully deployed certificate for matrix.linuxbuz.com to /etc/nginx/conf.d/matrix.conf
Congratulations! You have successfully enabled HTTPS on https://matrix.linuxbuz.com
We were unable to subscribe you the EFF mailing list because your e-mail address appears to be invalid. You can try again later by visiting https://act.eff.org.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

액세스 매트릭스 시냅스

이제 웹 브라우저에서 URL https://matrix.linuxbuz.com을 사용하여 Matrix Synapse 설치를 확인할 수 있습니다. 다음 화면이 표시됩니다.

Riot 웹 기반 클라이언트 https://riot.im/app/#/login을 사용하여 Matrix Synapse를 확인할 수도 있습니다. 다음 화면이 표시됩니다.

편집 버튼을 클릭합니다. 다음 화면이 표시됩니다.

Matrix 서버 URL을 제공하고 계속 버튼을 클릭합니다. Matrix 로그인 페이지가 표시되어야 합니다.

관리자 사용자 이름, 비밀번호를 제공하고 로그인 버튼을 클릭합니다. Matrix Synapse 서버에 연결되면. 다음 화면이 표시됩니다.

결론

이 게시물에서는 Ubuntu 22.04 서버에서 역방향 프록시로 Nginx와 함께 Matrix Synapse를 설치하는 방법을 배웠습니다. 또한 Riot 웹 기반 클라이언트를 사용하여 Matrix Synapse를 확인합니다. 이제 Matrix Synapse를 사용하여 자신만의 VOIP 서버를 구축할 수 있습니다.