金子邦彦研究室インストールUbuntu サーバ,リモート接続discourse を使ってみる

discourse を使ってみる

Ubuntu で Discourse のダウンロードとインストールとテスト実行を行ないます

事前に決めておく事項

Discourse のダウンロードとインストール (Download and Install Discourse)

  1. Discourse の前提ソフトウェア
    1. redis server のインストール (Install redis server)
      sudo apt -y update
      sudo apt -y install redis-server 
      
    2. ruby 1.9.3 のインストール (Install ruby 1.9.3)
      sudo apt-get -y --purge remove ruby1.8
      sudo apt-get -y --purge remove ruby1.8-dev 
      sudo apt-get -y  install  ruby1.9.3
      sudo apt-get -y  install  ruby1.9.1-dev
      
    3. gem update --system の実行 (Execute 'gem update --system')

      rubygems をインストールしたいので実行する.

      sudo REALLY_GEM_UPDATE_SYSTEM=YES gem update --system
      
    4. 'sudo gem install bundler' の実行 (Execute 'sudo gem install bundler')

      bundler が必要なので実行する.

      dpkg -l | grep bundle
      sudo gem install bundler 
      
  2. Discourse ユーザの設定

    このときにDiscourse ユーザの パスワードを設定する.

    sudo adduser --shell /bin/bash --gecos 'Discourse application' discourse
    
  3. /etc/sudoers に Discourse ユーザの設定
    discourse    ALL=(ALL:ALL) ALL
    
  4. Discourse のダウンロード (Download Discourse)

    「sudo su - discourse 」は、Discourse ユーザとして操作を行うためのコマンド. これ以降の操作は、Discourse ユーザで行う.

    sudo rm -rf /var/www/discourse
    sudo install -d -m 755 -o discourse -g discourse /var/www/discourse
    sudo su - discourse 
    git clone https://github.com/discourse/discourse.git /var/www/discourse
    

    この後の操作も、Discourse ユーザで行う.

  5. bundle の実行 (Execute bundle)

    Discourse の動作に必要な gem をインストールする操作.

    エラーメッセージが出ていないことを確認すること.

    cd /var/www/discourse
    bundle install --deployment --without test 
    
  6. sudo gem update の実行 (Execute 'sudo gem update')
    sudo gem update
    gem list
    
  7. 次の3つのファイルの先頭に「#encoding: utf-8」を追加
  8. Discouse の設定開始
    cd /var/www/discourse/config
    cp discourse_quickstart.conf discourse.conf
    cp discourse.pill.sample discourse.pill
    
  9. /var/www/discourse/config/discourse.conf の設定 (Edit /var/www/discourse/config/discourse.conf)

    ◆ 設定例

  10. Discouse ユーザから元のユーザに戻る操作
    exit 
    

Web サーバ nginx のインストール (Install a Web Server nginx)

  1. 旧版の nginx のアンインストール (Remove existing version of ngginx)
    sudo apt-get remove '^nginx.*$'
    
  2. sources.list.d ファイルの設定 (Setup a sources.list.d file)
    sudo rm -f /etc/apt/sources.list.d/nginx.list
    touch /etc/apt/sources.list.d/nginx.list
    echo "deb http://nginx.org/packages/ubuntu/ `lsb_release -sc` nginx" | sudo tee -a /etc/apt/sources.list.d/nginx.list
    echo "deb-src http://nginx.org/packages/ubuntu/ `lsb_release -sc` nginx" | sudo tee -a /etc/apt/sources.list.d/nginx.list
    sudo apt -y update
    sudo apt -y install nginx 
    
    # Add nginx key sudo apt -y install curl curl http://nginx.org/keys/nginx_signing.key | sudo apt-key add - # install nginx sudo apt -y update && sudo apt -y install nginx

PostgreSQL のインストールとデータベースファイルの生成 (Install PostgreSQL and Create Database Files)

インストール手順

  1. システムのアップデート操作
    sudo apt -y update
    sudo apt-get -y upgrade
    sudo shutdown -r now
    
  2. PostgreSQL と関連パッケージのインストール (Install PostgreSQL and related packages)
    sudo apt -y update
    sudo apt -y install postgresql
    sudo apt -y install postgresql-client-common
    sudo apt -y install postgresql-common 
    sudo apt -y install postgresql-contrib
    sudo apt -y install postgresql-9.1-postgis
    sudo apt -y install postgresql-9.1-plr
    
  3. pgAdmin IIIのインストール (Install pgAdmin III)
    sudo apt -y update
    sudo apt -y install pgadmin3
    
  4. postgreSQL サーバの起動チェック (Try to Start and Stop postgreSQL server)
    sudo pg_ctlcluster 12 main restart
    sudo pg_ctlcluster 12 main status
    
  5. Postgres 用アカウントが存在することの確認 (print the postgreSQL account)

    パッケージを使って PostgreSQL をインストールすると,Postgres 用アカウント(ユーザ名は「postgres」)が自動的に作成される.

    sudo cat /etc/passwd | grep postgres
    

    ※ 「x」は no password という意味(パスワードがないという意味ではない)

  6. データベースディレクトリの作成と権限の設定 (create a database directory)

    ここでは,データベースディレクトリは /var/lib/postgresql/data とする.好きに決めていいが,日本語を含まないディレクトリ名にすること.

    sudo mkdir /var/lib/postgresql/data
    sudo chown -R postgres:postgres /var/lib/postgresql/data
    
  7. データベースファイルの生成 (create database files)

    「sudo su - postgres」は,postgres ユーザに切り替える操作. 元のユーザに戻るには「exit」と操作する.

    sudo su - postgres
    /usr/lib/postgresql/9.1/bin/initdb --encoding='UTF-8' -D /var/lib/postgresql/data
    exit
    

discourse データベースの新規作成

  1. postgreSQL のログインに関する設定 (Settings of postgreSQL login)

    discourse で PostgreSQL にログインできるように, /etc/postgresql/9.1/main/pg_hba.conf を編集

    local all discourse peer
    
  2. postgreSQL サーバの再起動 (Restart postgreSQL server)

    /etc/postgresql/9.1/main/pg_hba.conf を書き換えたので再起動.

    sudo pg_ctlcluster 12 main status 
    
  3. ロールの新規作成 (Create a new role)

    /var/www/discourse/config/discourse.conf で設定したユーザ名(ここでは「discourse」)とパスワード(ここでは「sH2160」)を正しく設定する.

    sudo su - postgres
    psql -U postgres
    create role discourse with superuser login password 'sH2160';
    \q
    exit
    

    ※ 「間違えたので、ロールを削除したい」というときは「drop role discourse;」のように操作する

  4. 試しに、いま作成したロールを使って PostgreSQL に接続してみる.

    「sudo su - discourse 」は、Discourse ユーザとして操作を行うためのコマンド. これ以降の操作は、Discourse ユーザで行う.

    sudo su - discourse 
    psql -U discourse -d postgres 
    \q
    
  5. /var/www/discourse/config/database.yml の設定

    database: discourse_prod のように設定する.

    ◆ 設定例

  6. Discourse 用データベースの新規作成 (Create a database)

    関連する外部ページhttps://github.com/discourse/discourse/blob/main/docs/INSTALL.md

    cd /var/www/discourse
    createdb discourse_prod
    RUBY_GC_MALLOC_LIMIT=90000000 RAILS_ENV=production bundle exec rake db:migrate
    RUBY_GC_MALLOC_LIMIT=90000000 RAILS_ENV=production bundle exec rake assets:precompile
    
  7. データのベースの一覧表示 (List Databases)
    psql -U discourse -l 
    
  8. サーバの起動

    bundle exec rails s 
    
  9. http://localhost:3000 をWebブラウザで開いてみる