Ubuntu 12.04 への HTTPS およびサブディレクトリでの GitLab セットアップメモ

設定した環境 フロントの Nginx は https である。 URL は<ドメイン>/gitlab で受ける. さくらの VPS Ruby 1.9, MySQL で Redmine 2.3 が既に動いている。 gitユーザを追加 $ sudo adduser --disabled-login --gecos 'GitLab' git GitLab shell のセットアップ インストール $ sudo -u git -i $ cd /home/git $ git clone https://github.com/gitlabhq/gitlab-shell.git $ cd gitlab-shell $ git checkout v1.5.0 $ cp config.yml.example config.yml ※バージョンは最新のものにチェックアウト 設定 config.yml config.yml の gitlab_url を外から見えるURLに変更する。 gitlab_url: “https://<ドメイン>/gitlab/” ライブラリのインストール $ sudo apt-get install libicu-dev $ sudo gem install charlock_holmes --version '0.6.9.4' データベースのセットアップ MySQL を使う https://github.com/gitlabhq/gitlabhq/blob/master/doc/install/databases.md に従う。 ※gitlab ユーザのパスワードを控える。 ...

2013年6月19日 · Toshimitsu Takahashi

Redmine を Nginx + Unicorn へ移行

Apache + Passenger で動かしていた Redmine を Nginx + Unicorn に移行したのでそのメモ。 設定した環境 フロントの Nginx は https である。 Redmine は /var/redmine にインストールされている。 URL はドメイン/redmine で受ける. VPS 環境でUbuntu でスペックは低め。 Unicorn のインストール Redmine ディレクトリのルートに Gemfile.local を作る。 # Gemfile.local gem “unicorn” bundler で Unicorn をインストール $ bundle install Unicorn の設定スクリプト Redmine ディレクトリの config に unicorn.rb を下記のとおり作成する。 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 worker_processes 1 timeout 60 listen File.expand_path("tmp/sockets/unicorn.sock", ENV['RAILS_ROOT']) pid File.expand_path("tmp/pids/unicorn.pid", ENV['RAILS_ROOT']) preload_app true stderr_path File.expand_path("log/unicorn.stderr.log", ENV['RAILS_ROOT']) stdout_path File.expand_path("log/unicorn.stdout.log", ENV['RAILS_ROOT']) GC.respond_to?(:copy_on_write_friendly=) and GC.copy_on_write_friendly = true before_fork do |server, worker| defined?(ActiveRecord::Base) and ActiveRecord::Base.connection.disconnect! old_pid = "#{server.config[:pid]}.oldbin" if old_pid != server.pid begin sig = (worker.nr + 1) >= server.worker_processes ? :QUIT : :TTOU Process.kill(sig, File.read(old_pid).to_i) rescue Errno::ENOENT, Errno::ESRCH end end sleep 1 end after_fork do |server, worker| defined?(ActiveRecord::Base) and ActiveRecord::Base.establish_connection end 初回アクセス時にタイムアウトしないように 60 秒に増やす。 数人しかアクセスしないのでワーカーは 1 つにする。 Nginx の設定 upstream redmine { server unix:/var/redmine/tmp/sockets/unicorn.sock; } … location /redmine { root /var/redmine/public; if ( -f $request_filename ) { break; } proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header Host $http_host; proxy_pass http://redmine; } … Unicorn 起動 Unicorn で Redmine を起動 ...

2013年6月17日 · Toshimitsu Takahashi

Ubuntu 12.04 でメールサーバを立てずに sSMTP で CRON メールを送信するには

CRON などでメールを送信する際に、ざっくりと Postfix などを入れてしまっていた。 しかし、そもそも既にメールサーバが立っていれば、そこを経由して送信すれば MTA デーモンを動かす必要はない。 MSPに何を使うか探したところ、sSMTP が一番良さそうなのでこれを使うことに。 Ubuntu 12.04 で CRON の MAILTO でメール送信をするまでの設定のメモ。 インストール $ sudo apt-get install mailutils $ sudo apt-get install ssmtp 設定 /etc/ssmtp/ssmtp.conf # # Config file for sSMTP sendmail # # The person who gets all mail for userids < 1000 # Make this empty to disable rewriting. root=postmaster # The place where the mail goes. The actual machine name is required no # MX records are consulted. Commonly mailhosts are named mail.domain.com mailhub=<送信に使う SMTP サーバ> # Where will the mail seem to come from? rewriteDomain=<上書きするドメイン> # The full hostname hostname=<このホストの FQDN> # Are users allowed to set their own From: address? # YES - Allow the user to specify their own From: address # NO - Use the system generated From: address FromLineOverride=NO mailhub はその名のとおり経由するメールサーバを指定する。 rewriteDomain は経由先のメールサーバのドメインを指定する。設定しないとドメインが不正と判断され、迷惑メール扱いになる可能性が高い。 ...

2013年6月2日 · Toshimitsu Takahashi

bash シンプルなデーモンプログラムの制御スクリプト

Linuxなどで動かすデーモンプログラムを起動(start)・停止(stop)・再起動(restart)・状態確認(status)するための制御スクリプトを書いたのでメモしておく。 実装のポイント 一般的なプロセスIDファイルによるプロセス確認をしている。 停止時に3秒おきにシグナル0を送り、プロセスが終了するまで見届ける。 statusでプロセスIDファイルだけ残ってプロセスが無いときはクラッシュの可能性が示す。 スクリプト 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 #!/bin/bash prgfile=<Program Script filepath> pidfile=<PID filepath> start() { if [ -f $pidfile ]; then pid=`cat $pidfile` kill -0 $pid >& /dev/null if [ $? -eq 0 ]; then echo "Daemon has started." return 1 fi fi $prgfile if [ $? -eq 0 ]; then echo "Daemon started." return 0 else echo "Failed to start daemon." return 1 fi } stop() { if [ ! -f $pidfile ]; then echo "Daemon not started." return 1 fi pid=`cat $pidfile` kill $pid >& /dev/null if [ $? -ne 0 ]; then echo "Operation not permitted." return 1 fi echo -n "Stopping daemon..." while true do kill -0 $pid >& /dev/null if [ $? -ne 0 ]; then break fi sleep 3 echo -n "." done echo -e "\nDaemon stopped." return 0 } status() { if [ -f $pidfile ]; then pid=`cat $pidfile` kill -0 $pid >& /dev/null if [ $? -eq 0 ]; then echo "Daemon running. (PID: ${pid})" return 0 else echo "Daemon might crash. (PID: ${pid} file remains)" return 1 fi else echo "Daemon not started." return 0 fi } restart() { stop if [ $? -ne 0 ]; then return 1 fi sleep 2 start return $? } case "$1" in start | stop | status | restart) $1 ;; *) echo "Usage: $0 {start|stop|status|restart}" exit 2 esac exit $? 実行プログラムのファイルパス プロセスIDファイルのパス 停止部分は実行プログラムの性質によって適宜変更すると良い。 ...

2013年2月21日 · Toshimitsu Takahashi

Ubuntu で Apache 2.2 でマルチドメイン SSL を設定するには

マルチドメインSSL証明書は本来IPアドレスごとに1FQDNだった SSL ホストを、1IPアドレスで複数のFQDNに対応させるものです。 要するにhttpsでも名前ベースのバーチャルホストが使えるようになります。 Apache 2.2.12 以降で SNI(Server Name Indication)という SSLプロトコルに対する拡張機能がサポートされ、そのモジュールが mod_gnutls になります。 ただ Server Name Indication - Wikipedia, the free encyclopedia にある通り、SNI は Windows XP の IE ではサポートされないなど、まだまだ一般的使うには早そうです。 今回、さくら VPS サーバの Ubuntu 上でセットアップしたのでまとめておきます。 mod_gnutls をインストール・適用 # apt-get install libapache2-mod-gnutls # a2enmod gnutls /etc/apache2/ports.conf を編集 mod_ssl は一応コメントアウト、mod_gnutil を有効にする。SSLStrictSNIVHostCheck はSNIに未対応のブラウザがデフォルトのCommon Nameを参照するように off にする。 #<IfModule mod_ssl.c> # # If you add NameVirtualHost *:443 here, you will also have to change # # the VirtualHost statement in /etc/apache2/sites-available/default-ssl # # to <VirtualHost *:443> # # Server Name Indication for SSL named virtual hosts is currently not # # supported by MSIE on Windows XP. # NameVirtualHost *:443 # Listen 443 #</IfModule> <IfModule mod_gnutls.c> Listen 443 NameVirtualHost *:443 SSLStrictSNIVHostCheck off </IfModule> サイトの設定 デフォルトを無効にして、それぞれのサイト定義ファイルを作りSSLの設定を各VirtualHost内に定義します。パスは共通の証明書なので同じなります。 ...

2011年2月24日 · Toshimitsu Takahashi

CentOS 5.5 にアップグレードしたら lighttpd が起動しなくなったので対処

先日、CentOS 5.5 が出たため、yum upgrade をしたところ openssl のバージョンアップによって、lighttpd の起動時に network.c でエラーが出るようになってしまいました。 SSL: error:00000000:lib(0):func(0):reason(0). RPMForgeの最新の lighttpd 1.4.22 ではダメで、lighttpd 1.4.26-2 に上げるため別途 rpm を落としてきました。 Redhat 5 系の RPM パッケージでよさそうなのが下記にありました。 ftp://ftp.univie.ac.at/systems/linux/fedora/epel/5/i386/ 上記サイトから下記のパッケージを順にインストールします。 lua-5.1.2-1.el5.i386.rpm spawn-fcgi-1.6.2-1.el5.1.i386.rpm lighttpd-1.4.26-2.el5.i386.rpm lighttpd-fastcgi-1.4.26-2.el5.i386.rpm /etc/lighttpd/ を予め tar などしてバックアップしておきます。 yum remove で RPMForge から落として入れていた lighttpd, lighttpd-fastcgi を削除します。 上記のパッケージを rpm -ivh 〜 コマンドでインストール。 /etc/lighttpd/lighttpd.conf を lighttpd.conf.rpmsave から復帰させて無事起動するようになりました。

2010年5月25日 · Toshimitsu Takahashi

WordPress の wp-content に SELinux で httpd に書き込み生成権限を与えるには

WordPress のテーマファイルやプラグイン、アップロードしたファイルの置き場所は wp-content ディレクトリ以下になる。 ここに対して、httpd (Apache) で書き込み生成権限を付加する必要がある。その SELinux の設定についてのメモ。 権限の確認 httpd_t のエントリーを見てみると、タイプ httpd_cache_t がファイル、ディレクトリ、シンボリックリンクともに読み書き作成権限が付加されている。 # sesearch --allow -s httpd_t allow httpd_t httpd_cache_t : file { ioctl read write create getattr setattr lock append unlink link rename }; allow httpd_t httpd_cache_t : dir { ioctl read write create getattr setattr lock unlink link rename add_name remove_name reparent search rmdir }; allow httpd_t httpd_cache_t : lnk_file { read create getattr setattr unlink link rename }; コンテキストを変更 wp-content 以下に httpd_cache_t を設定する。 ...

2009年5月31日 · Toshimitsu Takahashi

Rubygems で x64 環境の標準 MySQL に対して mysql ライブラリをインストールする

x64 環境だとオプションを指定しないと、mysqlclient が見つからず config で失敗する。 # gem install mysql – –with-mysql-config=/usr/lib64/mysql/mysql_config Building native extensions. This could take a while… Successfully installed mysql-2.7

2009年5月17日 · Toshimitsu Takahashi

CentOS 5 で OpenLDAP によって LDAP ユーザーサービスを提供する

CentOS 5.3 で環境構築にあたってのメモ。 ベースDNは dc=tilfin,dc=local とする。 グループ tilfin とそれに属するユーザー tosshi を追加する。 openldap パッケージをインストール # yum install openldap-clients # yum install openldap-servers /etc/openldap/slapd.conf の設定 suffix “dc=tilfin,dc=local” rootdn “cn=Manager,dc=tilfin,dc=local” rootpw secret パスワード属性に対する制限を追記 ######################################################## # Set Permisson “userPassword” access to attrs=userPassword by self write by anonymous auth by * none # Set Permission except “userPassword” access to * by self write by * read DB パラメータの配置 # cd /var/lib/ldap # cp /etc/openldap/DB_CONFIG.example DB_CONFIG # chgrp ldap DB_CONFIG ...

2009年5月6日 · Toshimitsu Takahashi

CentOS 5 に 9Arrows を導入したときのメモ

以前、何かハマって止めていました。もう一度試してみることにして、ようやく成功しました。 PostgreSQL をインストール 普段 MySQL ばかりだったが、9Arrows は Postgres を要求しているのでインストールします。 CentOS なので、例によって yum を使いました。postgres ユーザも作成されます。 devel も入れるのは、このあと pg_config を gem で pg を入れるときに必要になるためです。 # yum install postgresql.i386 # yum install postgresql-devel.i386 PostgreSQL の初期設定 postgres ユーザになって initdb そして postmaster を起動します。 # su - postgres $ initdb $ pg_ctl -D /var/lib/pgsql/data -l logfile start 9arrows_production データベースと Postgres 上に 9arrows ユーザーを作成しておきます。 さらに 9arrows_production データベース に 9arrows ユーザーをパスワード「9arrows」で割り当てます。 $ createdb 9arrows_production CREATE DATABASE $ createuser 9arrows Shall the new role be a superuser? (y/n) n Shall the new role be allowed to create databases? (y/n) n Shall the new role be allowed to create more new roles? (y/n) n CREATE ROLE $ psql 9arrows_production 9arrows_production=# ALTER USER “9arrows” with password ‘9arrows’; ALTER ROLE 9arrows_production=# \q <== [CTRL + D] ...

2009年1月24日 · Toshimitsu Takahashi