ウェブサイト検索

Seafile サーバーを Ubuntu 22.04|20.04|18.04 にインストールする方法 |


このブログ投稿では、Ubuntu 22.04|20.04|18.04 に Seafile Server をインストールする方法を説明します。 Seafile Server は、パフォーマンスと高い信頼性を実現するために構築された、オープンソースのエンタープライズ型自己ホスト型ファイル ホスティング プラットフォームです。 Seafile を使用すると、自分のサーバーにファイルを置き、他のユーザーやさまざまなデバイスがファイルを同期してアクセスできるようになります。すべてのファイルに仮想ディスクとしてアクセスすることもできます。

シーファイルの特徴

  • 組み込みのファイル暗号化: ファイルはサーバーと同期する前に暗号化されます。システム管理者でもファイルを表示することはできません。
  • ドライブ クライアント: ドライブ クライアントを使用して、クラウド上の ローカル S: ドライブ 内のファイルに同期せずにアクセスします。
  • 信頼性の高いファイル同期: 信頼性が高く効率的なファイル同期により、生産性が向上します。
  • アップグレードが簡単: アップグレードは、数秒以内に簡単なスクリプトを実行するだけで実行できます。
  • エンタープライズ対応: Seafile は、AD/LDAP 統合、グループ同期、きめ細かい権限制御をサポートしており、ツールをエンタープライズ環境に簡単に適用できます。

Seafile サーバーの要件

  • HTTP サーバー – Nginx または Apache
  • データベースサーバー – MySQL または MariaDB
  • Python ツール

インストール手順は、Seafile サーバーをダウンロードして設定する前に、上記のソフトウェア要件をインストールすることから始まります。 Seafile Server を Ubuntu 22.04|20.04|18.04 にインストールするには、以下の手順に従ってください。

ステップ 1: MariaDB データベースサーバーをインストールする

以下の手順に従って、MariaDB データベース サーバーのインストールを開始します。

sudo apt update
sudo apt install mariadb-server

安全な MariaDB データベース サーバー:

sudo mysql_secure_installation

MariaDB データベース サーバーのインストール後、Seafile のユーザーとデータベースを作成します。

まず、root ユーザーとして MySQL シェルにログインします。

$ sudo mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 42
Server version: 10.6.11-MariaDB-0ubuntu0.22.04.1 Ubuntu 22.04

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>

Seafile Server の 3 つのコンポーネントには独自のデータベースが必要です。

  • ccnetサーバー
  • シーファイルサーバー
  • シーハブサーバー

これらのサーバー コンポーネントごとにデータベースを作成します。

CREATE DATABASE seafile_server;
CREATE DATABASE ccnet_server;
CREATE DATABASE seahub_server;

データベース ユーザーを作成し、作成したデータベースに対する権限を付与します。

CREATE USER 'seafile'@'localhost' IDENTIFIED BY 'StrongPassword';
GRANT ALL ON seafile_server.* TO 'seafile'@'localhost';
GRANT ALL ON ccnet_server.* TO 'seafile'@'localhost';
GRANT ALL ON seahub_server.* TO 'seafile'@'localhost';
QUIT;

seafile ユーザーとしてデータベースにログインして、アクセスを確認します。

$ sudo mysql -u seafile -p
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 44
Server version: 10.6.11-MariaDB-0ubuntu0.22.04.1 Ubuntu 22.04

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| ccnet_server       |
| information_schema |
| seafile_server     |
| seahub_server      |
+--------------------+
4 rows in set (0.001 sec)

MariaDB [(none)]> QUIT
Bye

ステップ 2: Python の依存関係をインストールする

Seafile は Python とそのモジュールに大きく依存しています。ターミナルで次のコマンドを実行して、必要な Python 依存関係を Ubuntu にインストールします。

sudo apt update
sudo apt install ffmpeg memcached libmemcached-dev python3 python3-{pip,pil,ldap,urllib3,setuptools,mysqldb,memcache,requests}
sudo pip3 install --upgrade pip
sudo pip3 install Pillow pylibmc captcha jinja2 sqlalchemy django-pylibmc django-simple-captcha python3-ldap mysqlclient

ステップ 3: Seafile サーバーをダウンロードしてインストールする

ダウンロードする前に、Seafile サーバーの最新リリースを確認してください。この記事は、インストール時点では古くなっている可能性があります。

sudo apt -y install wget
export VER="9.0.10"
wget https://s3.eu-central-1.amazonaws.com/download.seadrive.org/seafile-server_${VER}_x86-64.tar.gz

ファイルをダウンロードしたら、アーカイブを /srv ディレクトリに抽出します。

sudo tar -xvf  seafile-server_${VER}_x86-64.tar.gz -C /srv
sudo mv /srv/seafile-server-${VER} /srv/seafile

インストールは必要なく、セットアップ スクリプトを実行するだけです。

cd /srv/seafile/
sudo ./setup-seafile-mysql.sh

このスクリプトでは、MySQL を使用して Seafile サーバーをセットアップする方法を説明します。

$ sudo ./setup-seafile-mysql.sh 
Checking python on this machine ...
  Checking python module: setuptools ... Done.
  Checking python module: python-imaging ... Done.
  Checking python module: python-mysqldb ... Done.

-----------------------------------------------------------------
This script will guide you to setup your seafile server using MySQL.
Make sure you have read seafile server manual at

        https://github.com/haiwen/seafile/wiki

Press ENTER to continue
-----------------------------------------------------------------


What is the name of the server? It will be displayed on the client.
3 - 15 letters or digits
[ server name ] Seafile-Server

What is the ip or domain of the server?
For example: www.mycompany.com, 192.168.1.101
[ This server's ip or domain ] fileserver.example.com

Where do you want to put your seafile data?
Please use a volume with enough free space
[ default "/srv/seafile-data" ] 

Which port do you want to use for the seafile fileserver?
[ default "8082" ] 

-------------------------------------------------------
Please choose a way to initialize seafile databases:
-------------------------------------------------------

[1] Create new ccnet/seafile/seahub databases
[2] Use existing ccnet/seafile/seahub databases

[ 1 or 2 ] 2

What is the host of mysql server?
[ default "%" ] localhost

What is the port of mysql server?
[ default "3306" ] <Enter>

Which mysql user to use for seafile?
[ mysql user for seafile ] seafile

What is the password for mysql user "seafile"?
[ password for seafile ] StrongPassword

verifying password of user seafile ...  done

Enter the existing database name for ccnet:
[ ccnet database ] ccnet_server

verifying user "seafile" access to database ccnet_server ...  done

Enter the existing database name for seafile:
[ seafile database ] seafile_server

verifying user "seafile" access to database seafile_server ...  done

Enter the existing database name for seahub:
[ seahub database ] seahub_server

verifying user "seafile" access to database seahub_server ...  done

---------------------------------
This is your configuration
---------------------------------

    server name:            Seafile-Server
    server ip/domain:       fileserver.example.com

    seafile data dir:       /srv/seafile-data
    fileserver port:        8082

    database:               use existing
    ccnet database:         ccnet_server
    seafile database:       seafile_server
    seahub database:        seahub_server
    database user:          seafile

---------------------------------
Press ENTER to continue, or Ctrl-C to abort
---------------------------------

Generating ccnet configuration ...

done
Successly create configuration dir /srv/ccnet.
Generating seafile configuration ...

Done.
done
Generating seahub configuration ...

----------------------------------------
Now creating seahub database tables ...

----------------------------------------
creating seafile symbolic link ...  done

-----------------------------------------------------------------
Your seafile server configuration has been finished successfully.
-----------------------------------------------------------------

run seafile server:     ./seafile.sh { start | stop | restart }
run seahub  server:     ./seahub.sh  { start <port> | stop | restart <port> }

-----------------------------------------------------------------
If you are behind a firewall, remember to allow input/output of these tcp ports:
-----------------------------------------------------------------

port of seafile fileserver:   8082
port of seahub:               8000

When problems occur, Refer to
        https://github.com/haiwen/seafile/wiki for information.

Seafile サーバーはポート 8082 で実行され、Seafile Web UI はポート 8000 で利用可能になります。

Seafile サービスを開始する

未加工ファイルのアップロード、ダウンロード、同期を処理する Seafile サーバー デーモンを起動します。

$ cd /srv/seafile
$ sudo ./seafile.sh start 

[12/15/18 05:08:27] ../common/session.c(132): using config file /srv/conf/ccnet.conf
Starting seafile server, please wait ...
Seafile server started

Done.

次に、Seahub (Django) ウェブ フロントエンド サービスを開始します。

$ sudo ./seahub.sh start 

LC_ALL is not set in ENV, set to en_US.UTF-8
Starting seahub at port 8000 ...

----------------------------------------
It's the first time you start the seafile server. Now let's create the admin account
----------------------------------------

What is the email for the admin account?
[ admin email ] [email 

What is the password for the admin account?
[ admin password ] <ENTER ADMIN PASSWORD>

Enter the password again: <CONFIRM ADMIN PASSWORD>
[ admin password again ] 

----------------------------------------
Successfully created seafile admin
----------------------------------------
Seahub is started
Done.

ロケール設定で問題が発生した場合は、以下のように設定してください。

echo "export LC_ALL=en_US.UTF-8" >>~/.bashrc
echo "export LANG=en_US.UTF-8" >>~/.bashrc
echo "export LANGUAGE=en_US.UTF-8" >>~/.bashrc
source ~/.bashrc

LC 設定を永続的にするには、~/.bashrc ファイルに行を追加します。

ステップ 4: Seafile Systemd サービスを作成する

私は、Seafile を systemd で管理することを好みます。 Seafile バックエンド サーバーの systemd ユニット ファイルを作成します。

sudo tee  /etc/systemd/system/seafile.service<<EOF
[Unit]
Description=Seafile
After= mysql.service
After=network.target

[Service]
Type=forking
ExecStart=/srv/seafile/seafile.sh start
ExecStop=/srv/seafile/seafile.sh stop

[Install]
WantedBy=multi-user.target
EOF

Seahub 用も作成します

sudo tee  /etc/systemd/system/seahub.service<<EOF
[Unit]
Description=Seafile
After= mysql.service
After=network.target

[Service]
Type=forking
ExecStart=/srv/seafile/seahub.sh start
ExecStop=/srv/seafile/seahub.sh stop

[Install]
WantedBy=multi-user.target
EOF

サービスを開始し、起動時に開始できるようにします。

sudo systemctl daemon-reload
sudo systemctl start seafile && sudo systemctl enable seafile
sudo systemctl start seahub && sudo systemctl enable seahub

サービスのステータスを確認します。

$ systemctl status  seafile
● seafile.service - Seafile
   Loaded: loaded (/etc/systemd/system/seafile.service; disabled; vendor preset: enabled)
   Active: active (running) since Sat 2018-12-15 06:01:19 PST; 14s ago
  Process: 26437 ExecStart=/srv/seafile/seafile.sh start (code=exited, status=0/SUCCESS)
    Tasks: 14 (limit: 2319)
   CGroup: /system.slice/seafile.service
           ├─26476 /srv/seafile/seafile/bin/seafile-controller -c /srv/ccnet -d /srv/seafile-data -F /srv/conf
           ├─26478 ccnet-server -F /srv/conf -c /srv/ccnet -f /srv/logs/ccnet.log -d -P /srv/pids/ccnet.pid
           └─26482 seaf-server -F /srv/conf -c /srv/ccnet -d /srv/seafile-data -l /srv/logs/seafile.log -P /srv/pids/seaf-server.pid

Dec 15 06:01:16 ubuntu-01 systemd[1]: Starting Seafile...
Dec 15 06:01:16 ubuntu-01 seafile.sh[26437]: [12/15/18 06:01:16] ../common/session.c(132): using config file /srv/conf/ccnet.conf
Dec 15 06:01:16 ubuntu-01 seafile.sh[26437]: Starting seafile server, please wait ...
Dec 15 06:01:19 ubuntu-01 seafile.sh[26437]: Seafile server started
Dec 15 06:01:19 ubuntu-01 seafile.sh[26437]: Done.
Dec 15 06:01:19 ubuntu-01 systemd[1]: Started Seafile.

$ systemctl status  seahub
● seahub.service - Seafile
   Loaded: loaded (/etc/systemd/system/seahub.service; disabled; vendor preset: enabled)
   Active: active (running) since Sat 2018-12-15 06:02:43 PST; 4s ago
  Process: 26572 ExecStart=/srv/seafile/seahub.sh start (code=exited, status=0/SUCCESS)
 Main PID: 26600 (python2.7)
    Tasks: 6 (limit: 2319)
   CGroup: /system.slice/seahub.service
           ├─26600 python2.7 /srv/seafile/seahub/thirdpart/gunicorn seahub.wsgi:application -c /srv/conf/gunicorn.conf --preload
           ├─26607 python2.7 /srv/seafile/seahub/thirdpart/gunicorn seahub.wsgi:application -c /srv/conf/gunicorn.conf --preload
           ├─26608 python2.7 /srv/seafile/seahub/thirdpart/gunicorn seahub.wsgi:application -c /srv/conf/gunicorn.conf --preload
           ├─26609 python2.7 /srv/seafile/seahub/thirdpart/gunicorn seahub.wsgi:application -c /srv/conf/gunicorn.conf --preload
           ├─26610 python2.7 /srv/seafile/seahub/thirdpart/gunicorn seahub.wsgi:application -c /srv/conf/gunicorn.conf --preload
           └─26611 python2.7 /srv/seafile/seahub/thirdpart/gunicorn seahub.wsgi:application -c /srv/conf/gunicorn.conf --preload

Dec 15 06:02:38 ubuntu-01 systemd[1]: Starting Seafile...
Dec 15 06:02:38 ubuntu-01 seahub.sh[26572]: LC_ALL is not set in ENV, set to en_US.UTF-8
Dec 15 06:02:38 ubuntu-01 seahub.sh[26572]: Starting seahub at port 8000 ...
Dec 15 06:02:43 ubuntu-01 seahub.sh[26572]: Seahub is started
Dec 15 06:02:43 ubuntu-01 seahub.sh[26572]: Done.
Dec 15 06:02:43 ubuntu-01 systemd[1]: Started Seafile.

ステップ 5: Nginx リバースプロキシを構成する

サービスを実行したので、次は nginx を Seafile サーバーへのリバース プロキシとして構成します。

sudo apt -y install nginx

/etc/nginx/conf.d/seafile.conf の下に次の内容の新しい設定ファイルを作成します。

server {
    listen 80;
    listen [::]:80;
    server_name  fileserver.example.com;
    autoindex off;
    client_max_body_size 100M;
    access_log /var/log/nginx/seafile.com.access.log;
    error_log /var/log/nginx/seafile.com.error.log;

     location / {
            proxy_pass         http://127.0.0.1:8000;
            proxy_set_header   Host $host;
            proxy_set_header   X-Real-IP $remote_addr;
            proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header   X-Forwarded-Host $server_name;
            proxy_read_timeout  1200s;
        }

     location /seafhttp {
            rewrite ^/seafhttp(.*)$ $1 break;
            proxy_pass http://127.0.0.1:8082;
            proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_connect_timeout  36000s;
            proxy_read_timeout  36000s;
            proxy_send_timeout  36000s;
            send_timeout  36000s;
        }

    location /media {
            root /srv/seafile/seahub;
        }
}

http://example.com で Seafile サーバーのドメイン名にアクセスします。

管理者ユーザーのメールアドレスとパスワードを入力してログインします。以下のような Seafile ダッシュボードが表示されるはずです。

Seafile Server を Ubuntu LTS に正常にインストールして構成しました。

類似の記事:

  • Ubuntu に Pydio ファイル共有サーバーをインストールして構成する
  • NextcloudをUbuntuにインストールする方法

関連記事: