CentOS 7 に Seafile をインストールする方法
導入
Seafile は、Dropbox、Google Drive、OneDrive、Mega と同様のプライベート ファイル ホスティング プラットフォームです。その部分は、特に次の場合にオープン ソース ライセンスの下でリリースされます。
- Seafile iOS クライアント: Apache ライセンス v2
- Seafile Android クライアント: GPLv3
- デスクトップ同期クライアント: GPLv2
- Seafile サーバー コア: AGPLv3
- Seahub (Seafile サーバー Web UI): Apache ライセンス v2
ファイル暗号化とグループ共有をサポートします。
このチュートリアルでは、NGINX を Web サーバーとして、MariaDB をデータベースとして使用して、CentOS 7 に Seafile をインストールする方法について説明します。
はじめる
まず、Seafile は Python で書かれているため、次の依存関係が必要です。
yum install python-imaging MySQL-python python-memcached python-ldap python-urllib3
MariaDB のインストールと構成
MariaDB をインストールします。 EPEL で入手可能:
yum install epel-release
それから :
yum install mariadb mariadb-server
このプロセスの最後に、プログラムを開始して MariaDB ルート アカウントを構成し、次のコマンドを実行します。
systemctl start mysqld
そして
mysql_secure_installation
Set root password? [Y/n]
New password:
Re-enter new password:
Remove anonymous users? [Y/n]
Disallow root login remotely? [Y/n]
Remove test database and access to it? [Y/n]
Reload privilege tables now? [Y/n]
Seafile には 3 つの異なるデータベース (コンポーネントごとに 1 つ) が必要です。
- ccnet-db
- シーファイルデータベース
- シーハブデータベース
したがって、これらのデータベースとユーザーを作成します。
seauser
:
mysql -u root -p
MariaDB シェルで:
mysql> CREATE DATABASE ccnet-db CHARACTER SET = 'utf8';
mysql> CREATE DATABASE seafile-db CHARACTER SET = 'utf8';
mysql> CREATE DATABASE seahub-db CHARACTER SET = 'utf8';
mysql> CREATE USER 'seauser'@'localhost' IDENTIFIED BY 'user_strong_password';
mysql> GRANT ALL PRIVILEGES ON ccnet-db TO seauser@localhost IDENTIFIED BY 'user_strong_password';
mysql> GRANT ALL PRIVILEGES ON seafile-db TO seauser@localhost IDENTIFIED BY 'user_strong_password';
mysql> GRANT ALL PRIVILEGES ON seahub-db TO seauser@localhost IDENTIFIED BY 'user_strong_password';
mysql> FLUSH PRIVILEGES;
mysql> EXIT;
NGINX をインストールする
EPEL リポジトリが利用できるため、yum を使用して NGINX をインストールできます。
yum install nginx
systemd で起動します。
systemctl start nginx.service
ユーザーとグループを作成し、両方の名前を付けます。
nginx
:
adduser --user-group --system --no-create-home nginx
Seafile のインストールと構成
新しいディレクトリを作成します。
mkdir /var/www/seafile
cd /var/www/seafile
そこで、Seafileをダウンロードします
wget
:
wget https://bintray.com/artifact/download/seafile-org/seafile/seafile-server_6.0.8_x86-64.tar.gz
アーカイブを抽出します。
tar xf seafile-server_6.0.8_x86-64.tar.gz
抽出したディレクトリの名前を変更します。
mv seafile-server-6.0.8 seafile-server
cd seafile-server
という名前のスクリプトがあります
setup-seafile-mysql.sh
データベースを設定するには、次のように実行します。
./setup-seafile-mysql.sh
いくつかの情報を要求されます。
- サーバー名: myserver
- サーバーIPまたはドメイン: localhost
- seafile data dir: Enter を押すと、現在のディレクトリが使用されます。
- ファイルサーバー ポート: 8082 を使用する必要があります。
次に、以下が表示されます。
-------------------------------------------------------
Please choose a way to initialize Seafile databases:
-------------------------------------------------------
[1] Create new ccnet/seafile/seahub databases
[2] Use existing ccnet/seafile/seahub databases
オプション 2 を選択し、次の操作を行います。
- デフォルトのホストを使用します: localhost
- デフォルトのポート: 3306
- mysql ユーザー: 「seauser」
- Seafile mysql ユーザーのパスワード: 「user_strong_password」
- ccnet データベース: 「ccnet-db」
- seafile データベース: 「seafile-db」
- seahub データベース: 「seahub-db」
次に、スクリプトは Seafile に必要なテーブルを作成します。
Seafile と Seahub を開始します。
./seafile.sh start
./seahub.sh start
実行中に、seahub.sh は管理者情報、特に電子メールとパスワードを要求します。
この後、Seafile が実行され、Web ブラウザを使用して localhost:8000 にアクセスできるようになります。
次に、NGINX をリバース プロキシとして構成する必要があります。ただし、最初に systemd サービスを作成する必要があります。
サービスの構成
Seafile のインストール ディレクトリとキャッシュ所有者をユーザーに変更します。
nginx
:
chown -R nginx:nginx /var/www/*
chown -R nginx:nginx /tmp/seahub_cache
次にサービスを作成します。
$EDITOR /etc/systemd/system/seafile.service
このファイルに、次の構成を貼り付けます。
[Unit]
Description=Seafile - the open source, self-hosted file sync
Before=seahub.service
After=network.target mariadb.service
[Service]
Type=oneshot
ExecStart=/var/www/seafile/seafile-server/seafile.sh start
ExecStop=/var/www/seafile/seafile-server/seafile.sh stop
RemainAfterExit=yes
User=nginx
Group=nginx
[Install]
WantedBy=multi-user.target
保存して終了し、SeaHub で同じことを行います。
$EDITOR /etc/systemd/system/seahub.service
そしてペーストしてください:
[Unit]
Description=SeaHub
After=network.target seafile.target mariadb.service
[Service]
Type=oneshot
ExecStart=/var/www/seafile/seafile-server/seahub.sh start-fastcgi
ExecStop=/var/www/seafile/seafile-server/seahub.sh stop
RemainAfterExit=yes
User=nginx
Group=nginx
[Install]
WantedBy=multi-user.target
保存して終了し、次の操作を行います。
systemctl daemon-reload
systemctl start seafile
systemctl start seahub
NGINX の構成
Seafile は正しく実行されています。次に、その背後で Seafile を実行するように NGINX を設定します。新しい仮想ホスト ファイルを作成します。
$EDITOR /etc/nginx/conf.d/seafile.conf
そしてそこに:
<span class="hljs-section">server</span> {
<span class="hljs-attribute">listen</span> <span class="hljs-number">80</span>;
<span class="hljs-attribute">server_name</span> seafile.mydomain.com;
<span class="hljs-attribute">proxy_set_header</span> X-Forwarded-For <span class="hljs-variable">$remote_addr</span>;
<span class="hljs-attribute">location</span> / {
<span class="hljs-attribute">fastcgi_pass</span> <span class="hljs-number">127.0.0.1:8000</span>;
<span class="hljs-attribute">fastcgi_param</span> SCRIPT_FILENAME <span class="hljs-variable">$document_root</span><span class="hljs-variable">$fastcgi_script_name</span>;
<span class="hljs-attribute">fastcgi_param</span> PATH_INFO <span class="hljs-variable">$fastcgi_script_name</span>;
<span class="hljs-attribute">fastcgi_param</span> SERVER_PROTOCOL <span class="hljs-variable">$server_protocol</span>;
<span class="hljs-attribute">fastcgi_param</span> QUERY_STRING <span class="hljs-variable">$query_string</span>;
<span class="hljs-attribute">fastcgi_param</span> REQUEST_METHOD <span class="hljs-variable">$request_method</span>;
<span class="hljs-attribute">fastcgi_param</span> CONTENT_TYPE <span class="hljs-variable">$content_type</span>;
<span class="hljs-attribute">fastcgi_param</span> CONTENT_LENGTH <span class="hljs-variable">$content_length</span>;
<span class="hljs-attribute">fastcgi_param</span> SERVER_ADDR <span class="hljs-variable">$server_addr</span>;
<span class="hljs-attribute">fastcgi_param</span> SERVER_PORT <span class="hljs-variable">$server_port</span>;
<span class="hljs-attribute">fastcgi_param</span> SERVER_NAME <span class="hljs-variable">$server_name</span>;
<span class="hljs-attribute">fastcgi_param</span> REMOTE_ADDR <span class="hljs-variable">$remote_addr</span>;
<span class="hljs-attribute">access_log</span> /var/log/nginx/seahub.access.log;
<span class="hljs-attribute">error_log</span> /var/log/nginx/seahub.<span class="hljs-literal">error</span>.log;
<span class="hljs-attribute">fastcgi_read_timeout</span> <span class="hljs-number">36000</span>;
}
<span class="hljs-attribute">location</span> /seafhttp {
<span class="hljs-attribute">rewrite</span><span class="hljs-regexp"> ^/seafhttp(.*)$</span> <span class="hljs-variable">$1</span> <span class="hljs-literal">break</span>;
<span class="hljs-attribute">proxy_pass</span> http://127.0.0.1:8082;
<span class="hljs-attribute">client_max_body_size</span> <span class="hljs-number">0</span>;
<span class="hljs-attribute">proxy_connect_timeout</span> <span class="hljs-number">36000s</span>;
<span class="hljs-attribute">proxy_read_timeout</span> <span class="hljs-number">36000s</span>;
<span class="hljs-attribute">proxy_send_timeout</span> <span class="hljs-number">36000s</span>;
<span class="hljs-attribute">send_timeout</span> <span class="hljs-number">36000s</span>;
}
<span class="hljs-attribute">location</span> /media {
<span class="hljs-attribute">root</span> /path/to/your/directory;
}
}
次のように、NGINX を保存して終了し、テストします。
nginx -t
ccnet.conf および seahub_setting.py でドメインを構成します。
の値を変更します
SERVICE_URL
ccnet.conf で、選択したドメイン、プロトコル、ポートを Seafile に知らせます。
$EDITOR /var/www/seafile/conf/ccnet.conf
そして変更を加えます:
SERVICE_URL = http://seafile.mydomain.com
SeaHub 設定ファイルを保存して終了し、編集します。
$EDITOR /var/www/seafile/conf/seahub_setting.py
そこには :
FILE_SERVER_ROOT = 'http://seafile.mydomain.com/seafhttp'
サービスを保存、終了、再起動します。
systemctl restart seafile
systemctl restart seahub
テストシーファイル
Web ブラウザを使用して、URL: http://seafile.mydomain.com にアクセスします。ログイン フォームが表示され、以前に作成した管理者アカウント情報を入力できます。それだけです!これで、Seafile を他のクラウド ストレージ システムと同じように使用できるようになりました。