手動インストールしたnginxを維持しながらowncloudをupgrade

前提

apache2は2.4で設定が変わった折に捨てた.
nginxはwebdavを使うためやhttp2を使うためなどの理由でdebianのパッケージでは不足であったため公式サイトの安定リリースを手動コンパイルしインストールしている.
owncloudは公式のドキュメント(Install package owncloud, owncloud-files)にあるリポジトリを使用する.

手順

owncloudをリポジトリからapt-getで入れる場合,httpdセクションのパッケージが入っていないと依存関係が問題になる.
owncloud-filesで依存関係を無視して入れるか,ダミーパッケージを作成して依存関係を解決させるかが必要となる.
今回は後者を選択した.

リポジトリ修正
owncloudはメジャーアップデートをスキップすることはできない.
例えば8.1が入っている場合,8.1->8.2->9.0->9.1とアップデートしなければならない.
なので8.2を入れる.
なんかリポジトリのアドレスが変わってたっぽいのでついでに対応する.

@@ -1 +1 @@
-deb http://download.opensuse.org/repositories/isv:/ownCloud:/desktop/Debian_8.0/ /
+deb http://download.owncloud.org/download/repositories/8.2/Debian_8.0/ /
更新準備(ダミーパッケージインストール)
まず,
equivsでダミーパッケージを作って入れる.

  1. equivsを入れて
    $ sudo apt-get update && sudo apt-get install equivs
    
  2. 適当なディレクトリでダミーパッケージ作り.
    $ mkdir nginx-dummy && cd nginx-dummy
    $ equivs-control nginx-dummy
    
  3. 設定ファイルの編集
    ただし,php5-cgiは8.2のみ依存関係のため入れている.8.2のアンインストール後,つまり9.0インストール後はphp5-cgiを抜いてインストールし直して良い.(9.0~は依存関係は「php5-cgi | php5-fpm」となっているので)

    @@ -6,14 +6,14 @@
     # Homepage: 
     Standards-Version: 3.9.2
    
    -Package: 
    +Package: nginx-dummy
     # Version: 
     # Maintainer: Your Name 
     # Pre-Depends: 
     # Depends: 
     # Recommends: 
     # Suggests: 
    -# Provides: 
    +Provides: httpd,php5-cgi
     # Replaces: 
     # Architecture: all
     # Copyright: 
    @@ -22,7 +22,7 @@
     # Extra-Files: 
     # Files: 
     #  
    -Description: 
    - long description and info
    +Description: dummy package for nginx
    + dummy package for nginx installed manually.
      .
    - second paragraph
    + nginx-dummy provides httpd and php5-cgi
    
  4. ダミーパッケージを作ってインストール
    $ equivs-build nginx-dummy; sudo dpkg -i nginx-dummy_1.0_all.deb
    
パッケージ更新
で,やっとownCloudを更新する.

$ sudo apt-get update && sudo apt-get install owncloud=8.2
ファイル更新
展開済のowncloudを更新する.

$ cd /var/www/owncloud
$ sudo -u www-data ./occ upgrade
メンテナンスモード終了
動作確認は設定ファイルでmaintenanceをfalseにしないとできない.

@@ -21,3 +21,3 @@
   'updatechecker' => false,
-  'maintenance' => true,
+  'maintenance' => false,
   'theme' => '',
繰り返す
8.2->9.0
9.0->9.1

10.0も出てるけど,9.1はまだサポートされてるし,今回はパス.
と思ったら,9.0もまだサポートされてた.アップデートしすぎた.でもダウングレードはサポートされてないので,9.1で行く.
Maintenance and Release Schedule · owncloud/core Wiki

debian で systemctl で自動起動

あらすじ

systemctl で start とか stop とかできるように /etc/systemd/system/ 以下にサービス定義を置いて安心していたら,自動起動しなかったよ!

それからどーした

sudo systemctl list-unit-files --type=service

nginx.service            disabled

とか出てきたら,サービス定義は生きてるけど自動起動が無効なので,

sudo systemctl enable nginx.service

とかする.

他にも mask/unmask とかハマりポイントなんで,systemctl の man を見て対処する.

dovecotを入れてメールのローカル配信をする

インストール

sudo apt-get install dovecot-pop3d dovecot-lmtpd heirloom-mailx postfix
maildirmake.dovecot /var/mail/USERNAME  # Maildir形式の場合

設定

  • /etc/dovecot
    • dovecot.conf
    • conf.d/10-mail.conf
    • conf.d/10-master.conf
    • conf.d/10-ssl.conf
  • /etc/postfix
    • main.cf
  • /etc/aliases
    • 書いたら newaliases を走らせる./etc/aliases のオーナーが /etc/aliases.db と一緒でないとエラーを吐く
  • /etc/mailname

テスト

送信テスト
行中に「.」のみの行が末尾のしるし.

mail USERNAME@HOSTNAME
Subject: Test
this is test
.

受信テスト

mail

debian jessie に owncloud 8.1 を導入する

方法

owncloudの入れ方には,大きく分けて2種類

  • apt-getで入れる
    • 普通に入れる
    • backportsから入れる
  • ソースからコンパイル

ついでに,owncloudはwebdavが必要になるので,httpdも入れる.

  • apache2
  • nginx

で,本記事では

  • apt-get で backportsから owncloudを入れる (apache2を使いたくないから)
  • nginx で運用する

手順

  1. nginxと,mysql or mariadbは使える前提
  2. owncloudを入れてみる
    1. sudo apt-get install owncloud
    2. なんか apache2 が入ってきたものの,nginx で十分なので backports で入れることにする
      echo 'deb http://ftp.jp.debian.org/debian/ jessie-backports main contrib non-free' | sudo tee -a /etc/apt/sources.list
      sudo apt-get update; sudo apt-get upgrade
      sudo apt-get -t jessie-backports install owncloud
  3. apache2とかを消す
    1. 普通に消そうとすると,php5-cgiが入ろうとする.これも要らない.php5-cgiも消そうとしたら,php5-fpmが入ろうとする.これは使う.
      sudo apt-get remove apache2 php5-cgi
    2. 他に一緒に入ったものをまとめて消す
      sudo apt-get autoremove
    3. spdyでも良ければ,これでOK
      http2を使う場合は,nginxとopensslもbackportsで入れる
  4. mysqlの設定
    • DB作成.owncloudにログインする時に初期設定するので,何でもOK.ユーザも別で作って良い.
  5. nginxの設定
    • 基本はnginx Example Configurations — ownCloud 9.2 Server Administration Manual 9.2 documentationに従いつつ,Generate Mozilla Security Recommended Web Server Configuration Filesあたりを参照して,自分の環境に直す.
      私の場合,

      -upstream php-handler {
      -    server 127.0.0.1:9000;
      -    #server unix:/var/run/php5-fpm.sock;
      -}
      -
       server {
           listen 80;
      -    server_name cloud.example.com;
           # enforce https
           return 301 https://$server_name$request_uri;
       }
      
       server {
      -    listen 443 ssl;
      -    server_name cloud.example.com;
      +    listen 443 http2;
      +    server_name YOURDOMAINNAME;
      
      -    ssl_certificate /etc/ssl/nginx/cloud.example.com.crt;
      -    ssl_certificate_key /etc/ssl/nginx/cloud.example.com.key;
      +    ssl on;
      +
      +    # certs sent to the client in SERVER HELLO are concatenated in ssl_certificate
      +    ssl_certificate /path/to/certificate/file;
      +    ssl_certificate_key /path/to/certificate/key/file;
      +    ssl_session_timeout 1d;
      +    ssl_session_cache shared:SSL:50m;
      +    ssl_session_tickets off;
      +
      +
      +    # modern configuration. tweak to your needs.
      +    ssl_protocols TLSv1.2;
      +    ssl_ciphers 'ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256';
      +    ssl_prefer_server_ciphers on;
      +
      +    # HSTS (ngx_http_headers_module is required) (15768000 seconds = 6 months)
      +    add_header Strict-Transport-Security max-age=15768000;
      +
      +    # OCSP Stapling ---
      +    # fetch OCSP records from URL in ssl_certificate and cache them
      +    ssl_stapling on;
      +    ssl_stapling_verify on;
      
           # Add headers to serve security related headers
           # Before enabling Strict-Transport-Security headers please read into this topic first.
      @@ -83,7 +97,9 @@
               fastcgi_param HTTPS on;
               fastcgi_param modHeadersAvailable true; #Avoid sending the security headers twice
               fastcgi_param front_controller_active true;
      -        fastcgi_pass php-handler;
      +        fastcgi_pass unix:/var/run/php5-fpm.sock;
      +        fastcgi_index index.php;
               fastcgi_intercept_errors on;
               fastcgi_request_buffering off; #Available since nginx 1.7.11
           }
      
  6. あと,この辺も設定しておかないとwebdavで大容量ファイルの転送に失敗すると思われる. nginx + php-fpmでphpを動かす - Qiita
    要するにファイルサイズの上限解除.

python3 で seaborn を使うまで

python3系でvenvを使う想定.

ubuntuとかだとpython3は入っているので,他にいりそうなものを入れる.

$ sudo apt-get install python3-dev python3-venv python3-tk tk-dev

python3-devはnumpyとかのコンパイルに,venvはpipとかをローカルで使うために,tk系はmatplotlibでプロットするウィンドウをコンソールから起こすために使う.

venvで環境を整える.
どこでもいいけど,私は ~/.py3 に環境を作っている.

$ cd
$ pyvenv-3.4 .py3
$ source ~/.py3/bin/activate

source ~/.py3/bin/activateはaliasにしといた方が良いと思う.
以降,source ~/.py3/bin/activateした状態を,(.py3) $と表記する.

必要なパッケージをインストールする
pipでパッケージを入れるが,もしかしたらディストリのパッケージのうち,必要なものが抜けているかも知れない.
build-essentialとかgfortranとか…エラーが出るはずなので,その時に検索すること.
ともかく,以下でpython上の依存関係は入る.

$ pip install seaborn
matplotlibの設定ファイルを変更
(.py3) $ python -c 'import matplotlib;print(matplotlib.matplotlib_fname())'
/home/USERNAME/.py3/lib/python3.4/site-packages/matplotlib/mpl-data/matplotlibrc

で場所を見付けて,backend と書かれた行が agg だったら,tkaggに変更する.