In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Most people do not understand the knowledge of this article "how to use the open source framework Matrix-Dendrite to build a chat server", so the editor summarizes the following contents, detailed contents, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "how to use the open source framework Matrix-Dendrite to build a chat server" article.
Open source framework Matrix-Dendrite builds chat server about Matrix
Matrix is an open source, interactive, decentralized real-time communication service framework. Matrix can be used to build a secure communication server, and with clients that support Matrix, real-time chat interaction between individuals and teams can be realized.
Compared with ordinary communication services (such as Wechat, QQ and other software services), Matrix is most special in its decentralized architecture. Each server running Matrix is a homeserver. Users can choose to register, connect and communicate freely with other users on the same node. Users' privacy data is stored on the current node in an encrypted form. At the same time, nodes can also communicate with each other through Federation mechanism, so that users on different nodes can communicate with each other. Thanks to the decentralized service architecture, users can build their own node servers to protect their chat data security and privacy.
There are many clients that support Matrix protocol, the more mature ones are Element.io (Riot.IM), voice, video calls, accessories and other functions, and support Windows,Linux,Android and other platforms.
Start building.
There are two kinds of Matrix servers: Synapse and Dendrite.
Synapse is the first generation of Matrix server written in Python. It is a very stable official version with many users and is suitable for use in a production environment. Dendrite is the second generation of Matrix server written by Matrix's development team in the Go language. It aims to provide an efficient, reliable and extensible alternative to Synapse. At present, Dendrite is still in Beta development, and some functions such as push and reminder have not been implemented yet.
If it is a production environment to use, or build Synapse, more stable and related tutorials are also very rich.
This article uses Dendrite to build, in the Unraid system through the Docker container to achieve, mainly want to taste fresh! You can also refer to this article for deployment under other systems.
"things" that need to be prepared
A domain name and a valid TLS certificate for that domain name
A reverse proxy service, such as Nginx
Optional: high performance database engine, recommended PostgreSQL. You can use the built-in SQLite without performance requirements.
PostgreSQL
Matrix does not dictate which database to use, and its built-in SQLite database can be used with a small number of users. If there are already other database engines running in the system, you can also use it directly. This article only uses PostgreSQL as the management engine of the Matrix database as recommended by the government.
01. Create a PostgreSQL profile directory
Before installing PostgreSQL Docker, create the configuration file directory / mnt/user/appdata/PostgreSQL/.
Visit https://github.com/matrix-org/dendrite/tree/main/build/docker/postgres to download the create_db.sh file, open it with a text editor, and change the user name field in the code to your own database user name.
The purpose of this code is to initialize the database, so the Username in the statement must be replaced with your own database administrator user name. For db in userapi_accounts userapi_devices mediaapi syncapi roomserver keyserver federationapi appservice mscs; do createdb-U [Username]-O [Username] dendrite_$db # Note to modify [Username] done
Finally, upload the create_db.sh file to the configuration file directory: / mnt/user/appdata/PostgreSQL/create_db.sh
02. Create a databases folder to store the database
Create a directory to hold the database for PostgreSQL:
/ mnt/user/appdata/PostgreSQL/databases03. Configure the Docker command to create a container
This article uses the Unraid system to build. Enter DOCKER-> ADD CONTAINER to configure the container parameters. You can also use the Unraid plug-in Center for installation. It may be easier for other systems to use the docker create command, so this article also appends the command-line string that creates the container.
The parameters that need to be added / modified to create a container in Unraid are as follows:
[Type] Variable [Name] Administrator user name [Key] POSTGRES_USER [Value] FrozenSky [Type] Variable [Name] Administrator password [Key] POSTGRES_PASSWORD [Value] xxxxxxx [Type] Path [Name] Database Storage path [Container Path] / var/lib/postgresql/data [Host Path] / mnt/user/appdata/PostgreSQL/databases [Access Mode] Read/Write [Type] Path [Name] Database initialization script [Container Path] / docker-entrypoint-initdb.d/20-create_ db.sh [Host Path] / mnt/user/appdata/PostgreSQL/create_ db.sh [Type] Port [Name] Port Mapping [Container Port] 5432 [Host Port] 5432
In addition, it is recommended to enable the container health check feature. Click the Advanced View (ADVANCED VIEW) in the add Container interface, and add the following statement to Post Arguments:
-health-cmd=' ["CMD-SHELL", "pg_isready-U dendrite"]'--health-interval=5s-- health-timeout=5s-- health-retries=5
After the configuration is completed, click APPLY to create the container.
The problem of domestic network access to DockerHub may not be able to connect, which can be solved through Ali Cloud acceleration. There are many tutorials on the network, but most of them need to change the Unraid system files, which is not necessary at all. The Docker command supports custom pull servers. You only need to add an acceleration server in the Repository column of the configuration interface:
For example: dazeaikzq.mirror.aliyuncs.com/library/postgres:14
About HEALTHCHECK
In the official docker-compose file, there is a HEALTHCHECK field, which can be replaced with reference to the following field if you start the container with docker-cli. This field is configured to check the health status of the container. It seems that you don't have to add it.
-health-cmd Command to run to check health--health-interval Time between running the check-- health-retries Consecutive failures needed to report unhealthy-- health-timeout Maximum time to allow one check to run-- health-start-period Start period for the container to initialize before starting health-retries countdown-- no-healthcheck Disable any container-specified HEALTHCHECK
Attached: create Docker by command line
Docker create-- name='PostgreSQL'-- net='bridge'-e TZ= "Asia/Shanghai"-e HOST_OS= "Unraid"-e 'POSTGRES_PASSWORD'='xxxxxxx'-e' POSTGRES_USER'='FrozenSky'-e 'POSTGRES_DB'=''-p' 5432 purse 5432 max TCP'-v'/ mnt/user/appdata/PostgreSQL/databases':'/var/lib/postgresql/ Data':'rw'-v'/ mnt/user/appdata/PostgreSQL/create_db.sh':'/docker-entrypoint-initdb.d/20-create_db.sh':'rw'-- restart=always' postgres:14'-- health-cmd=' ["CMD-SHELL" "pg_isready-U dendrite"]'- health-interval=5s-health-timeout=5s-health-retries=504. Connect to the database to confirm that the initialization is normal
You can use PGAdmin, dbeaver, phpMyAdmin, and other management software to connect to the remote database to see if many data at the beginning of dendrite have been created.
The default connection address for PostgreSQL is: [IP]: 5432
Matrix-Dendrite
The Matrix-Dendrite server is divided into two versions, monolith and polylith. This paper chooses monolith because its components are integrated and easy to configure.
Dendrite's Github warehouse: https://github.com/matrix-org/dendrite
01. Create a Dendrite folder storage profile
Create a directory: / mnt/user/appdata/Dendrite/config
The following files must be included in this directory:
Dendrite.yaml profile
Matrix_key.pem server key (generated by the following command)
Server.crt certificate file (certificate intended to be the domain name of the Matrix server)
Server.key certificate private key
(1) generate matrix_key.pem server key file
Upload your website domain name certificate and private key to the configuration directory:
/ mnt/user/appdata/Dendrite/config/server.key/mnt/user/appdata/Dendrite/config/server.crt
Open the Unraid terminal, enter the configuration file directory, and execute the following Docker command:
# Note: the file names of-tls-cert and-tls-key in the command parameters should be the same as above. Docker run-- rm-- entrypoint= ""\-v $(pwd): / mnt\ matrixdotorg/dendrite-monolith:latest\ / usr/bin/generate-keys\-private-key / mnt/matrix_key.pem\-tls-cert / mnt/server.crt\-tls-key / mnt/server.key
This command will generate the server key matrix_key.pem in the current directory
# Command output Created TLS cert file: / mnt/server.crtCreated TLS key file: / mnt/server.keyCreated private key file: / mnt/matrix_key.pem (2) modify Dendrite configuration file
Download the configuration file dendrite.yaml sample from the Github repository for modification. Download address: profile exampl
The following configuration file will assume that my domain name is frozensky.org and intend to reverse proxy on port 1443 to forward the API request of Matrix; my database user name is FrozenSky password is xxxxxxx, and the database access address is: 192.168.7.9 FrozenSky 5432
The main changes are as follows:
# Domain name (if the operator blocked 443 You need to fill in your custom reverse proxy port) server_name: frozensky.org:1443# server private key path (private key generated above) private_key: / etc/dendrite/matrix_key.pem# Well-known service domain name (same as domain name) well_known_server_name: "frozensky.org:1443" # database connection string for each component connection_string # data of all components in the configuration file Change the library connection URL (not if you use the built-in SQLite) connection_string: postgresql://FrozenSky:xxxxxxxx@192.168.7.9:5432/.# comment out the default server address of JetStream # Configuration for NATS JetStream jetstream: addresses: #-jetstream:4222 # comment the line storage_path: / etc/JetStream_NATS # set a container directory to store data 02. Create a data storage directory
Create some directories to store Dendrite data:
JetStream:/mnt/user/appdata/Dendrite/JetStream
Media: / mnt/user/appdata/Dendrite/media
03. Create a Dendrite container
Use the official image: matrixdotorg/dendrite-monolith
The following is the container configuration:
[Type] Port 1 [Name] Port Mapping [Container Port] 8008 [Host Port] 8008 [Type] Port 2 [Name] Port Mapping [Container Port] 8448 [Host Port] 8448 [Type] Path [Name] profile path [Container Path] / etc/dendrite [Host Path] / mnt/user/appdata/Dendrite/config [Access Mode] Read/Write [Type] Path [Name] Media File path [Container Path] / var/dendrite/media [Host Path] / mnt/user/appdata/Dendrite/media [Type] Path [Name] JetStream path [Container Path] / etc/JetStream_ Nats [Host Path] / mnt/user/appdata/Dendrite/JetStream
Click the Advanced View (ADVANCED VIEW) in the add Container interface, and add the following statement to Post Arguments:
-tls-cert=server.crt-tls-key=server.key
Click APPLY to create the container.
Nginx reverse proxy
After installing Dendrite, the backend of the Matrix service framework is already running, but if we want the client software to communicate with our server, we need to configure Nginx to forward the client's request to the corresponding server port.
Modify Nginx configuration file / etc/nginx/sites-available (different Nginx versions may have different configuration file paths)
Take the environment of this article as an example, because the operator blocked port 443, I forwarded port 1443 to the internal port 443 on the route. The part of the configuration file to be modified has been annotated in this article, so there is no longer too much explanation for the configuration of Nginx. You can search on your own when you encounter problems, and the tutorial is still very detailed.
Server {listen 80; listen 443 ssl; server_name frozensky.org; # Domain name charset utf-8; # ssl on; ssl_certificate / etc/ssl/frozensky.org/fullchain.crt; # Certificate ssl_certificate_key / etc/ssl/frozensky.org/frozensky.org.key; # key ssl_session_timeout 5m; ssl_protocols SSLv2 SSLv3 TLSv1 TLSv1.2 Some settings for ssl_ciphers HIGH _ host; proxy_set_header X-Real-IP _ request _ null _ remote_addr; proxy_read_timeout _ MD5; some settings requested by the ssl_prefer_server_ciphers on; # proxy; server_name in # Dendrite configuration file, notice that the port is an external port! Location / .well-known/matrix/server {return 200' {"m.server": "frozensky.org:1443"}';} # server_name in the Dendrite configuration file, note that the port is an external port! Location / .well-known/matrix/client {return 200' {"m.homeserver": {"base_url": "https://frozensky.org:1443"}}'; # Dendrite backend address. IP is the server IP on which the Dendrite is built, and the port is 8008 location / _ matrix {proxy_pass http://192.168.7.10:8008;}.
Save and exit after the configuration is complete.
Reload configuration files and certificates and restart the Nginx service
Sudo service nginx force-reloadsudo service nginx restart
Test connection
At this point, the Matrix service is all configured. You can visit Federation Tester and enter your own Matrix URL https://frozensky.org:1443 for testing. If all pass, the service is running normally and Federation interlock has been enabled, and you can communicate with partners of other servers. This article recommends installing the Element.io client to use. Although Matrix-Dendrite is still in the development and testing stage, it is found that there is nothing wrong with the main features after using it in the past few days.
The above is about the content of this article on "how to use the open source framework Matrix-Dendrite to build a chat server". I believe we all have some understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 260
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.