Ubuntu 20.04에 Discourse 설치 관련 참고 사항

bundle install 단계에서 문제가 발생하고 있습니다. 이 오류가 계속 나타납니다.

(...)
Installing sassc-rails 2.1.2
Installing discourse-ember-rails 0.18.6
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /home/archie/gems/gems/openssl-2.2.1/ext/openssl
/usr/bin/ruby3.0 -I /usr/lib/ruby/vendor_ruby -r
./siteconf20220430-16096-soaves.rb extconf.rb
checking for t_open() in -lnsl... no
checking for socket() in -lsocket... no
checking for openssl/ssl.h... yes
checking for CRYPTO_malloc() in -lcrypto... yes
checking for SSL_new() in -lssl... yes
checking for LIBRESSL_VERSION_NUMBER in openssl/opensslv.h... no
checking for OpenSSL version >= 1.0.1 and < 3.0.0... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
	--with-opt-dir
	--without-opt-dir
	--with-opt-include
	--without-opt-include=${opt-dir}/include
	--with-opt-lib
	--without-opt-lib=${opt-dir}/lib
	--with-make-prog
	--without-make-prog
	--srcdir=.
	--curdir
	--ruby=/usr/bin/$(RUBY_BASE_NAME)3.0
	--with-openssl-dir
	--without-openssl-dir
	--with-openssl-include
	--without-openssl-include=${openssl-dir}/include
	--with-openssl-lib
	--without-openssl-lib=${openssl-dir}/lib
	--with-kerberos-dir
	--without-kerberos-dir
	--with-kerberos-include
	--without-kerberos-include=${kerberos-dir}/include
	--with-kerberos-lib
	--without-kerberos-lib=${kerberos-dir}/lib
	--with-debug
	--without-debug
	--enable-debug
	--disable-debug
	--with-nsl-dir
	--without-nsl-dir
	--with-nsl-include
	--without-nsl-include=${nsl-dir}/include
	--with-nsl-lib
	--without-nsl-lib=${nsl-dir}/lib
	--with-nsllib
	--without-nsllib
	--with-socket-dir
	--without-socket-dir
	--with-socket-include
	--without-socket-include=${socket-dir}/include
	--with-socket-lib
	--without-socket-lib=${socket-dir}/lib
	--with-socketlib
	--without-socketlib
	--with-openssl-config
	--without-openssl-config
	--with-pkg-config
	--without-pkg-config
	--with-crypto-dir
	--without-crypto-dir
	--with-crypto-include
	--without-crypto-include=${crypto-dir}/include
	--with-crypto-lib
	--without-crypto-lib=${crypto-dir}/lib
	--with-cryptolib
	--without-cryptolib
	--with-ssl-dir
	--without-ssl-dir
	--with-ssl-include
	--without-ssl-include=${ssl-dir}/include
	--with-ssl-lib
	--without-ssl-lib=${ssl-dir}/lib
	--with-ssllib
	--without-ssllib
extconf.rb:113:in `<main>': OpenSSL >= 1.0.1, < 3.0.0 or LibreSSL >= 2.5.0 is
required (RuntimeError)

To see why this extension failed to compile, please check the mkmf.log which can
be found here:

  /home/archie/gems/extensions/x86_64-linux/3.0.0/openssl-2.2.1/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /home/archie/gems/gems/openssl-2.2.1 for
inspection.
Results logged to
/home/archie/gems/extensions/x86_64-linux/3.0.0/openssl-2.2.1/gem_make.out

  /usr/lib/ruby/vendor_ruby/rubygems/ext/builder.rb:95:in `run'
/usr/lib/ruby/vendor_ruby/rubygems/ext/ext_conf_builder.rb:47:in `block in
build'
  /usr/lib/ruby/3.0.0/tempfile.rb:317:in `open'
  /usr/lib/ruby/vendor_ruby/rubygems/ext/ext_conf_builder.rb:26:in `build'
  /usr/lib/ruby/vendor_ruby/rubygems/ext/builder.rb:161:in `build_extension'
/usr/lib/ruby/vendor_ruby/rubygems/ext/builder.rb:195:in `block in
build_extensions'
  /usr/lib/ruby/vendor_ruby/rubygems/ext/builder.rb:192:in `each'
  /usr/lib/ruby/vendor_ruby/rubygems/ext/builder.rb:192:in `build_extensions'
  /usr/lib/ruby/vendor_ruby/rubygems/installer.rb:847:in `build_extensions'
/usr/share/rubygems-integration/all/gems/bundler-2.3.5/lib/bundler/rubygems_gem_installer.rb:71:in
`build_extensions'
/usr/share/rubygems-integration/all/gems/bundler-2.3.5/lib/bundler/rubygems_gem_installer.rb:28:in
`install'
/usr/share/rubygems-integration/all/gems/bundler-2.3.5/lib/bundler/source/rubygems.rb:204:in
`install'
/usr/share/rubygems-integration/all/gems/bundler-2.3.5/lib/bundler/installer/gem_installer.rb:54:in
`install'
/usr/share/rubygems-integration/all/gems/bundler-2.3.5/lib/bundler/installer/gem_installer.rb:16:in
`install_from_spec'
/usr/share/rubygems-integration/all/gems/bundler-2.3.5/lib/bundler/installer/parallel_installer.rb:186:in
`do_install'
/usr/share/rubygems-integration/all/gems/bundler-2.3.5/lib/bundler/installer/parallel_installer.rb:177:in
`block in worker_pool'
/usr/share/rubygems-integration/all/gems/bundler-2.3.5/lib/bundler/worker.rb:62:in
`apply_func'
/usr/share/rubygems-integration/all/gems/bundler-2.3.5/lib/bundler/worker.rb:57:in
`block in process_queue'
/usr/share/rubygems-integration/all/gems/bundler-2.3.5/lib/bundler/worker.rb:54:in
`loop'
/usr/share/rubygems-integration/all/gems/bundler-2.3.5/lib/bundler/worker.rb:54:in
`process_queue'
/usr/share/rubygems-integration/all/gems/bundler-2.3.5/lib/bundler/worker.rb:91:in
`block (2 levels) in create_threads'

An error occurred while installing openssl (2.2.1), and Bundler cannot
continue.

In Gemfile:
  cose was resolved to 1.2.0, which depends on
    openssl-signature_algorithm was resolved to 1.1.1, which depends on
      openssl

저도 최근 @Sonosus와 비슷한 문제에 직면했는데, 최신 버전의 Ubuntu(20.04)에 OpenSSL 3.0.2가 기본 설치되어 있기 때문인 것으로 확인되었습니다. OpenSSL이 기본 설치된 다른 Ubuntu/Debian 버전에서도 이러한 상황이 발생할 수 있습니다. 이 문제를 겪고 있다면 소스에서 이전 버전의 OpenSSL(저는 OpenSSL-1.1.1n을 사용했습니다)을 컴파일한 후 bundle install 명령을 다시 실행해야 합니다. 기본적으로 이 오류 메시지는 OpenSSL >= 1.0.1, < 3.0.0에 관한 것이며, 결국 1.1 버전이 유일한 대안인 것으로 밝혀졌습니다.

ruby --version으로 사용 중인 Ruby 버전을 확인하는 것도 좋습니다. Discourse는 여전히 Ruby 2를 사용하므로, Ruby 3.x 이상을 사용하고 있다면 이전 버전으로 전환해야 합니다. Ruby를 설치하는 방법에 따라 이전 버전 설치 시 비슷한 OpenSSL 문제가 발생할 수 있으므로, 여기서는 Ruby 버전 관리자를 사용하는 것을 권장합니다. 저는 현재 Discourse와 함께 사용할 때 가장 좋은 버전이 Ruby 2.7.6이라고 판단했습니다.

Ubuntu 20.04를 새로 설치한 후, bundle install이 올바르게 실행되도록 제가 취한 조치는 다음과 같습니다:

Discourse 의존성, asdf 설치 및 Discourse 클론

bash <(wget -qO- https://raw.githubusercontent.com/discourse/install-rails/master/linux)
sudo apt install build-essential checkinstall zlib1g-dev
git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.10.0
git clone https://github.com/discourse/discourse.git ~/discourse

데이터베이스 설정

Ubuntu 시스템 사용자 이름과 동일한 이름으로 역할을 생성합니다:

sudo -u postgres createuser -s "$USER"

소스에서 OpenSSL-1.1.1n 설치

wget https://www.openssl.org/source/openssl-1.1.1n.tar.gz
tar -zxf openssl-1.1.1n.tar.gz && cd openssl-1.1.1n
./config --prefix=/opt/openssl-1.1.1n --openssldir=/opt/openssl-1.1.1n shared zlib
make
make test
make install
sudo rm -rf /opt/openssl-1.1.1n/certs
sudo ln -s /etc/ssl/certs /opt/openssl-1.1.1n

그 후 .bashrc 파일에 다음 줄을 추가했습니다.

export RUBY_CONFIGURE_OPTS="--with-openssl-dir=/opt/openssl-1.1.1n/"

여기서 asdf를 위해 다음 줄들도 추가했습니다.

. $HOME/.asdf/asdf.sh
. $HOME/.asdf/completions/asdf.bash

저장하고 나간 후 다음을 실행합니다.

source ~/.bashrc

Ruby 2.7.6 설치

asdf plugin add ruby
asdf install ruby 2.7.6

이제 bundle install을 실행하면 문제가 없을 수 있지만, Discourse 설치 과정에서 제가 겪은 몇 가지 다른 문제를 참고를 위해 여기서 언급하겠습니다. 다른 사람들도 이 문제를 겪을 수 있으므로요.

mini_racer 설치 중 오류 발생

OpenSSL-1.1.1n과 Ruby 2.7.6을 설치한 후에도 bundle install을 실행할 때 계속 다음과 같은 오류가 발생했습니다.

An error occurred while installing mini_racer (0.6.1), and Bundler cannot continue.

이것은 로컬 discourse/Gemfile의 다음 줄을 편집하여 해결할 수 있습니다:

그리고 다음으로 대체합니다.

gem 'mini_racer', github: 'rubyjs/mini_racer', branch: 'refs/pull/186/head'

이 단계 이후로 bundle install을 성공적으로 실행할 수 있었습니다.

이것은 MacOS에서 발생하는 문제와 유사하며, 더 자세한 내용은 여기에서 읽을 수 있습니다.

No such file or directory - convert

Discourse 설치의 후속 단계에서 bundle exec rake autospec을 실행할 때 다음과 같은 문제도 발생했습니다.

Failures: 
  1. AboutController.index should display the about page for logged in user when login_required is true
    Failure/Error: expect(response.status).to eq(200)

    expected: 200
    got: 500

      (comparted using ==)
    #./spec/requests/about_controller_spec.rb:27:in 'block (3 levels) in <main>'
    #./spec/rails_helper.rb:277:in 'block (2 levels) in <top (required)>
    #---------------------
    #---Caused by:---
    # Errno::ENOENT
    #  No such file or directory - convert
    # ./lib/letter_avatar.rb:105:inc ``'

이 오류는 ImageMagick 패키지가 설치되어 있지 않음을 의미합니다(convert 바이너리를 제공합니다).

아마도 Discourse 설치 과정의 시작 부분에 있는 이 스크립트에는 필요한 모든 패키지가 포함되어 있어야 하지만, 이 패키지는 제외된 것으로 보입니다.

마지막으로, sudo apt install imagemagick으로 ImageMagick을 설치한 후 제 Discourse 서버를 성공적으로 실행할 수 있었습니다!

이 정보가 이 과정을 거치며 어려움을 겪고 있는 분들에게 도움이 되기를 바랍니다. :smile:

이건 정말 고마워요. 나중에 한번 시도해 보고 어떻게 되는지 확인해 볼게요.