0662.html 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <!DOCTYPE html>
  2. <html lang="en" xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <title>Running Matrix Synapse Home Server in Docker on Ubuntu Server</title>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  6. <meta charset="UTF-8">
  7. <meta name="keywords" content="Home Lab,Home Lab Ideas,Docker Made Easy,Install Guide,Self-Hosted,Chat,Container,Containerization,Docker,Docker How To,Docker Installation Tutorial,Docker Simplified,Docker Tutorial,Element,Encrypted Communication,Free Software,Getting Started With Docker,Encryption,End To End Encrpytion,Ubuntu,Synapse,Self-hosted,Secure Communication Server,Secure Communication,Secure Chat,Instant Messaging,How To,Tutorial,i12bretro">
  8. <meta name="author" content="i12bretro">
  9. <meta name="description" content="Running Matrix Synapse Home Server in Docker on Ubuntu Server">
  10. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  11. <meta name="revised" content="04/18/2023 08:39:05 PM" />
  12. <link rel="icon" type="image/x-icon" href="includes/favicon.ico">
  13. <script type="text/javascript" src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
  14. <script type="text/javascript" src="includes/js/steps.js"></script>
  15. <link href="css/steps.css" rel="stylesheet" type="text/css" />
  16. </head>
  17. <body>
  18. <div id="gridContainer">
  19. <div class="topMargin"></div>
  20. <div id="listName" class="topMargin">
  21. <h1>Running Matrix Synapse Home Server in Docker on Ubuntu Server</h1>
  22. </div>
  23. <div></div>
  24. <div id="content">
  25. <h2>What is Matrix?</h2>
  26. <blockquote><em>Matrix is an open source project that publishes the Matrix open standard for secure, decentralised, real-time communication, and its Apache licensed reference implementations. -<a href="https://matrix.org" target="_blank">https://matrix.org</a></em></blockquote>
  27. <h2>Installing Docker</h2>
  28. <ol>
  29. <li>Log into the Linux host</li>
  30. <li>Run the following commands in a terminal window
  31. <div class="codeBlock"># install prerequisites<br />
  32. sudo apt install apt-transport-https ca-certificates curl software-properties-common gnupg-agent -y<br />
  33. # add docker gpg key<br />
  34. curl -fsSL https://download.docker.com/linux/$(awk -F&#39;=&#39; &#39;/^ID=/{ print $NF }&#39; /etc/os-release)/gpg | sudo apt-key add -<br />
  35. # add docker software repository<br />
  36. sudo add-apt-repository &quot;deb [arch=$(dpkg --print-architecture)] https://download.docker.com/linux/$(awk -F&#39;=&#39; &#39;/^ID=/{ print $NF }&#39; /etc/os-release) $(lsb_release -cs) stable&quot;<br />
  37. # install docker<br />
  38. sudo apt install docker-ce docker-compose containerd.io -y<br />
  39. # enable and start docker service<br />
  40. sudo systemctl enable docker &amp;&amp; sudo systemctl start docker<br />
  41. # add the current user to the docker group<br />
  42. sudo usermod -aG docker $USER<br />
  43. # reauthenticate for the new group membership to take effect<br />
  44. su - $USER</div>
  45. </li>
  46. </ol>
  47. <h2>Running Matrix Synapse</h2>
  48. <ol>
  49. <li>Continue with the following commands in terminal to setup and run Matrix Synapse
  50. <div class="codeBlock"># create working directories<br />
  51. sudo mkdir ~/docker/matrix-synapse -p &amp;&amp; sudo mkdir ~/docker/postgresql -p<br />
  52. # set owner of docker directory<br />
  53. sudo chown &quot;$USER&quot;:&quot;$USER&quot; ~/docker -R<br />
  54. # run the postgesql docker container<br />
  55. docker run -d --name postgres -e POSTGRES_USER=matrix_synapse_rw -e POSTGRES_PASSWORD=m@trix! -e POSTGRES_DB=matrix_synapse -e LC_COLLATE=&#39;C&#39; -e LC_CTYPE=&#39;C&#39; -e POSTGRES_INITDB_ARGS=&quot;--encoding=UTF-8&quot; -v ~/docker/postgresql:/var/lib/postgresql/data --restart=unless-stopped postgres:latest<br />
  56. # generate synapse homeserver.yaml<br />
  57. docker run -it --rm -v ~/docker/matrix-synapse:/data -e SYNAPSE_SERVER_NAME=my.matrix.host -e SYNAPSE_REPORT_STATS=no matrixdotorg/synapse:latest generate<br />
  58. # edit the homeserver.yaml file<br />
  59. sudo nano ~/docker/matrix-synapse/homeserver.yaml</div>
  60. </li>
  61. <li>Press CTRL+W and search for name: server_name
  62. <p>server_name: &quot;YOUR.MATRIX.DNS&quot;</p>
  63. </li>
  64. <li>Press CTRL+W and search for name: sqlite3</li>
  65. <li>Comment out the sqlite database parameters by adding a # to the beginning of each of the lines</li>
  66. <li>Add the following database connection below the commented out lines to connect to the Postgres container:
  67. <p>database:<br />
  68. &emsp;name: psycopg2<br />
  69. &emsp;txn_limit: 10000<br />
  70. &emsp;args:<br />
  71. &emsp;&emsp;user: matrix_synapse_rw<br />
  72. &emsp;&emsp;password: m@trix!<br />
  73. &emsp;&emsp;database: matrix_synapse<br />
  74. &emsp;&emsp;host: postgres<br />
  75. &emsp;&emsp;port: 5432<br />
  76. &emsp;&emsp;cp_min: 5<br />
  77. &emsp;&emsp;cp_max: 10</p>
  78. </li>
  79. <li>Add the following line at the bottom of the file
  80. <p>suppress_key_server_warning: true</p>
  81. </li>
  82. <li>Press CTRL+O, Enter, CTRL+X to write the changes</li>
  83. <li>Continue with the following commands in terminal
  84. <div class="codeBlock"># generate a random string<br />
  85. RANDOMSTRING=$(openssl rand -base64 30)<br />
  86. # write the random string as registration_shared_secret<br />
  87. echo &quot;registration_shared_secret: $RANDOMSTRING&quot; | sudo tee -a ~/docker/matrix-synapse/homeserver.yaml &gt; /dev/null<br />
  88. # run the matrix synapse container<br />
  89. docker run -d --name matrix-synapse --link postgres -v ~/docker/matrix-synapse:/data -p 8008:8008 --restart=unless-stopped matrixdotorg/synapse:latest<br />
  90. # create a new synapse user<br />
  91. docker exec -it matrix-synapse register_new_matrix_user http://DNSorIP:8008 -c /data/homeserver.yaml</div>
  92. </li>
  93. <li>Enter a username, enter and confirm the password and choose if the user is an admin</li>
  94. <li>At this point the Matrix Synapse server is running over http</li>
  95. <li>Open a web browser and navigate to the http://DNSorIP:8008</li>
  96. <li>A message stating It works! Synapse is running should be displayed</li>
  97. <li>Navigate to https://element.io/get-started#download</li>
  98. <li>Download and install Element</li>
  99. <li>Run the Element application</li>
  100. <li>Click Sign In</li>
  101. <li>Click the Edit link next to matrix.org</li>
  102. <li>Select Other homeserver &gt; type http://DNSorIP:8008 &gt; Click Continue</li>
  103. <li>Login using the Synapse username and password created earlier</li>
  104. </ol>
  105. <p>Documentation: <a href="https://registry.hub.docker.com/r/matrixdotorg/synapse/" target="_blank">https://registry.hub.docker.com/r/matrixdotorg/synapse/</a></p> </div>
  106. </div>
  107. </body>
  108. </html>