bitbucket server(オンプレミス版)のインストール

会社でGitを使う場合、小規模であればbitbucket serverがお勧めです。
オンプレミス版で10ユーザーだと$10という破格値で買えます!
買いきりですが、サポートを付けたかったら2年目以降に$10で付けれますのでそれでも安いですよね。

bitbucket serverですが以前はStashと呼ばれていたものです。
今回はCetnOS7にインストールしてみました。
そういえばCentOS7のインストールについてもまだ記事書いていなかったなぁ・・・順番前後するけど今度に書こう!

ひとまずbitbucket server無料トライアル申込をしてインストーラーをダウンロードします。
atlassian-bitbucket-5.9.0-x64.binというファイルがダウンロードされました。
早速サーバーにアップしてインストールします。

実行権限が無いので実行権限を付けてインストール
インストールは途中で設定を聞いてくるタイプなのでここは全部デフォルトにしました。

# chmod +x atlassian-bitbucket-5.9.0-x64.bin
# ./atlassian-bitbucket-5.9.0-x64.bin

npacking JRE …
Starting Installer …

Unsupported Git version found [1.8.3.1]. Please upgrade Git to a supported
version before installing Bitbucket.
See http://go.atlassian.com/installgit for more information.
NOTE: If you proceed without a working Git, Bitbucket won’t be able to start
after installation until a working Git is found.
If you proceed without a working Git, Bitbucket won’t be able to start after installation.
Are you sure you want to continue?
Yes [y, Enter], No [n]
y
Bitbucket 5.9.0 installation wizard
Would you like to install or upgrade an instance?
Install a new instance [1, Enter], Upgrade an existing instance [2]
1
Install Bitbucket 5.9.0
What type of instance are you looking to install?
Install a Server instance [1, Enter], Install a Data Center instance [2], Install a Smart Mirroring instance [3]

Where should Bitbucket be installed?

[/opt/atlassian/bitbucket/5.9.0]

Default location for Bitbucket home directory

The location for Bitbucket data.
This will be the default location for repositories, plugins, and other data.

Ensure that this location is not used by another Bitbucket installation.
[/var/atlassian/application-data/bitbucket]

Configure which ports Bitbucket will use.

Bitbucket requires a TCP port that isn’t being used by other applications.

The HTTP port is where users access Bitbucket through their browsers.

Bitbucket also requires ports 7992 and 7993 are available to run an embedded
Elasticsearch instance that provides search functionality to Bitbucket.
HTTP Port Number
[7990]

For a production server we recommend that you run Bitbucket as a
Windows/Linux service because Bitbucket will restart automatically when the
computer restarts.
Install Bitbucket as a service?
Yes [y, Enter], No [n]
y
Please review your Bitbucket installation settings

Installation Directory: /opt/atlassian/bitbucket/5.9.0
Home Directory: /var/atlassian/application-data/bitbucket
HTTP Port: 7990
Install as a service: Yes

Install [i, Enter], Exit [e]
i
Git version 1.8.3.1 is not supported. If you proceed Bitbucket won’t be able to start after installation.
Are you sure you want to continue?
Yes [y, Enter], No [n]
y

Extracting files …
Would you like to launch Bitbucket?
Yes [y, Enter], No [n]
y

Please wait a few moments while Bitbucket starts up.
Launching Bitbucket …

Installation of Bitbucket 5.9.0 is complete
Your installation of Bitbucket 5.9.0 is now ready and can be accessed via
your browser.
Bitbucket 5.9.0 can be accessed at http://localhost:7990
Launch Bitbucket 5.9.0 in browser?
Yes [y, Enter], No [n]
Finishing installation …

とインストールは終了しましたが、最初の方でGitのversionについてエラーが出ていました。
→Git version 1.8.3.1 is not supported. If you proceed Bitbucket won’t be able to start after installation.

yumでインストールしていたものなのでyumで削除して最新のGitのソースを取得してインストールします。
# yum remove git

(2018/3/27)時点ではgit-2.16.3.tar.gzが最新です。

作業ディレクトリで解凍します。
# tar zxvf git-2.16.3.tar.gz
# cd git-2.16.3
# ./configure
# make
ここでエラーになります。
どうやらパッケージが足りないようだったのでyumでインストール
# yum install perl-ExtUtils-MakeMaker

# make

# make install

問題なくインストール完了!

# git –version
-bash: /usr/bin/git: そのようなファイルやディレクトリはありません

おや?
gitはどこに起動ファイルあるのかとログを見てみると/usr/local/binにありました。
確認してもPATHは通ってるし・・・

過去のバージョンがわるさしているのか?
原因探すのは時間がかかりそうだな・・・よしリンクで解決しよう!

根本解決ではないですが簡単ですし、何かあってもすぐに消せるし問題なし!
リンクを設定
# ln -s /usr/local/bin/git /usr/bin/git
確認
# ls -al /usr/bin/git
lrwxrwxrwx 1 root root 18 3月 26 19:06 /usr/bin/git -> /usr/local/bin/git
gitが通るか確認
# git –version
git version 2.16.3

問題ないですね。

インストール時に1.8が入ってたので一度bitbucketを再起動します。
再起動しないとずっと1.8というエラーが表示されます。

そのまんまインストールしたので起動スクリプトは下記のフォルダにあります。
/opt/atlassian/bitbucket/5.9.0/bin

停止
# stop-bitbucket.sh

起動
# start-bitbucket.sh

インストール自体はここで終わりですが内部DBを使うよりDBを別で立てたほうがいいです。
postgresqlがいいようなので久しぶりにインストールしてみますかね。

php5.3からphp5.6へのバージョンアップ

しばらくほったらかしにしていたせいでサーバのアプリのバージョンが古い状態でした。

新しいものをインストールする際に困ることがおきるのでバージョンアップをすることにしました。

今回はphpを5.6にします。

php5.6ではEPELとRemiリポジトリが必要なので追加します。

EPELはyumでさくっと、remiについてはwgetで取得してyum.repod.dに配置します。

# yum -y install epel-release
# cd /etc/yum.repos.d
# wget http://rpms.famillecollet.com/enterprise/remi.repo

既存php5.3ですがphp5.6をそのままインストールしても置き換えてくれます。
気になる場合は削除してから行ってください

まずは現在のphpの確認
# rpm -qa | grep php
php53-cli-5.3.3-26.el5_11
php53-pdo-5.3.3-26.el5_11
php53-mysql-5.3.3-26.el5_11
php53-mbstring-5.3.3-26.el5_11
php53-common-5.3.3-26.el5_11
php53-5.3.3-26.el5_11

削除する場合は下記のコマンドを実施

# yum remove php*

php5.6のインストールを実施

# yum install –enablerepo=remi,remi-php56 php php-devel php-mbstring php-pdo php-gd

アップデートされたか確認

# rpm -qa | grep php
php-cli-5.6.24-1.el5.remi
php-5.6.24-1.el5.remi
php-pecl-jsonc-devel-1.3.10-1.el5.remi.5.6
php-common-5.6.24-1.el5.remi
php-pecl-jsonc-1.3.10-1.el5.remi.5.6
php-mysqlnd-5.6.24-1.el5.remi
php-gd-5.6.24-1.el5.remi
php-devel-5.6.24-1.el5.remi
php-pecl-zip-1.13.4-1.el5.remi.5.6
php-pdo-5.6.24-1.el5.remi
php-mbstring-5.6.24-1.el5.remi

作業自体は簡単ですがバージョンアップするとphpで使えなくなる関数とかあったりしてプログラムの不具合等がでるので十分注意して下さい。

 

 

 

Basic認証

今更な感じはありますが、よく使われるBasic認証についてメモ

apacheに.htaccessを使用させる為にhttpd.confを変更します。

<Directory />
# AllowOverride none を All に変更
AllowOverride All
</Directory>

ケース1 apacheの設定ファイルに記述する場合
httpd.confに以下を追記します。

<Directory “/var/www/html/”> ← Basic認証を設定したいディレクトリのパスを記述
AuthType Basic
AuthName “Please enter your ID and Password”
AuthUserFile /var/www/.htpasswd
AuthGroupFile /dev/null
Require valid-user
</Directory>

apacheの設定変更をしたらapacheは再起動して下さい。
# /etc/init.d/httpd restart

ケース2 .htaccessファイルを作成する場合
Basic認証をかけたい場所に「.htaccess」ファイルを配置します。
記述は下記のような形で書きます。

<<Basic認証用設定>>
AuthType Basic
AuthName “Please enter your ID and Password”
AuthUserFile /var/www/.htpasswd
AuthGroupFile /dev/null
Require valid-user

■ AuthType
認証方法です。Basic認証にしています。
■ AuthName
認証名、主にパスワードを求めるポップアップに表示される文字を書きます。
“”の中身が表示されます。ブラウザによっては日本語は文字化けするので
英語を使うほうが無難です。
■ AuthUserFile
パスワードファイルを指定します。必ずフルパスで記述して下さい。
できればHTTPでアクセスできないディレクトリに置いてください。
■ AuthGroupFile
グループ毎のアクセス制限に用います。
使わなければ書かなくても問題ないです。
ちなみに/dev/nullは制限しないという意味なので書かない事とあまり変わりません。
■Require valid-user
全ユーザーに認証させる設定になります。

認証ファイル「.htpasswd」を作成します。
作成場所はAuthUserFileで指定した場所です。

# htpasswd -c -b /var/www/.htpasswd user1 password

ユーザーを追加する場合

# htpasswd -b /var/www/.htpasswd user2 password

パスワードファイル(.htpasswd)の作り方 apacheを利用しない場合

<<.htpasswrd例>>
neko:gH7weU0OdCg99
cat:G.MuRtXkmfsx2

パスワードファイルの記載方法はアカウント名:パスワードになります。
複数アカウントを指定する場合は改行して次の行に記述します。
パスワードについては暗号化して記述する必要があります。
暗号化には何かしらツールを使う必要がありますが、perlのスクリプトで
暗号化させることができます。
使うのはperlのcrypt関数です。
crypt(TEXT, SALT)
TEXTは暗号化したい文字列です。SALT部分は暗号化する際のキーとなる部分です。
l
<param(‘pass’); ←ここのpassを変更したいパスワードにする。
my $encpass = &encrypt_passwd($pass);
print “Password encryption : “;
print ${encpass};
print “\n”;
exit;

sub encrypt_passwd {
my($pass)=@_;
my @salt_set = (‘a’..’z’,’A’..’Z’,’0′..’9′,’.’,’/’);
srand;
my $ida1 = int(rand(63));
my $ida2 = int(rand(63));
my $salt = $salt_set[$ida1] . $salt_set[$ida2];
return crypt($pass, $salt);
}

print部分は好みで変えてください。
SLAT部分は大文字・小文字アルファベットと 0 ~ 9 の数字、そして、
「.(ドット)」「/(スラッシュ)」のいずれか2文字にしています。
SALTもなるべく生成するたびにランダムな文字列になるほうがいいので
rand関数を使ってランダムな2文字を抽出しています。

perlとか面倒だという場合は暗号化してくれるサイトは結構あるので
そちらで暗号化してその暗号化文字をパスワード欄に記載してください。

メーリングリストサーバmailmanの構築

【前提条件】
apacheがインストール済み
postfix,sendmail,qmail等のsmtpがインストール済み
Pythonがインストール済み
Python-develがインストール済み
gccが2.8.1以降

※selinuxが動いているとmailmanのCGIが動きません。
 SElinuxの設定をする必要がありますが今のところ
 面倒なのでdisableにしています。

今回はpostfixを使用しています。

mailmanはmailman-2.1.14+j7.tgzを使用します。
事前に公式サイトからダウンロードして/usr/local/src/に
配置します。

グループ及びユーザー作成
# groupadd mailman
# useradd -c “GNU Mailman” -s /sbin/nologin -g mailman mailman

デフォルトでインストールディレクトリが/usr/local/mailmanなので
フォルダを作り権限を設定します。
# mkdir /usr/local/mailman
# usermod -d /usr/local/mailman mailman
# chown mailman. /usr/local/mailman
# chmod a+rx,g+ws /usr/local/mailman

mailmanをダウンロードしたディレクトリに移動して解凍します。
また所有者をmailmanユーザーにします。

# cd /usr/local/src/
# tar zxvf mailman-2.1.14+j7.tgz
# chown -R mailman. mailman-2.1.14+j7

解凍したディレクトリへ移動しインストールを実施します。
※注意点 日本語はEUCになります。linux環境でUTF-8にしている場合は
文字化けするので注意すること

# cd mailman-2.1.14+j7
# su mailman -s “/bin/bash” -c “./configure –with-cgi-gid=apache”
# su mailman -s “/bin/bash” -c “make” && make install

インストール終了後、インストールディレクトリに移動して
パーミッションの補正スクリプトcheck_permsを実行します。

# cd /usr/local/mailman
# bin/check_perms -f

警告: 限定公開保存書庫ディレクトリが other-executable (o+x) に
なっています. あなたのシステムのシェルユーザがこの保存書庫
を読むことができます. インストールマニュアルには, これを
どうしたら修正できるか書いてありますので, 参考にしてください.

問題ありません

問題ありませんとなるまで何度か実行します。

●WEBサーバの設定
CGIを使うのでCGIの許可設定が必要です。
今回はmailman用にコンフィグファイルを別途作ります。

# vi /etc/httpd/conf.d/mailman.conf
ScriptAlias /mailman/ /usr/local/mailman/cgi-bin/
<Directory /usr/local/mailman/cgi-bin/>
AllowOverride None
Options ExecCGI
Order allow,deny
Allow from all
</Directory>
Alias /pipermail/ /usr/local/mailman/archives/public/
<Directory /usr/local/mailman/archives/public/>
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>

mailman用ロゴファイルを所定のディレクトリーにコピーします。
# cp /usr/local/mailman/icons/* /var/www/icons/

ここまで終わったらWEBサーバの再起動
# /etc/init.d/httpd restart

●メールサーバの設定(postfix編)

postfixのmain.cfに下記の設定をします。
デフォルトではoffになっていると思うのでコメントアウトを外すか
新規で記述して下さい。

# vi /etc/postfix/main.cf

alias_maps = hash:/etc/postfix/aliases, hash:/usr/local/mailman/data/aliases

owner_request_special = no
recipient_delimiter = +
unknown_local_recipient_reject_code = 550

●mailmanの設定
mailmanの設定ファイルを編集します。

# vi /usr/local/mailman/Mailman/mm_cfg.py

##################################################
# Put YOUR site-specific settings below this line.

## mailman setup ###
MTA = ‘Postfix’
DEFAULT_URL_HOST = ‘testserver.ddo.jp’
DEFAULT_EMAIL_HOST = ‘testserver.ddo.jp’
DEFAULT_URL_PATTERN = ‘http://%s/mailman/’
DEFAULT_SERVER_LANGUAGE = ‘ja’

PostfixのPは大文字です。間違えると次がエラーになってしまいます。

bin/genaliases スクリプトを実行して aliases ファイルを初期化し、
メーリングリストサーバ管理パスワード設定します。

# /usr/local/mailman/bin/genaliases パスワード
パスワードを変更しました。

data/aliases と data/aliases.db の所有者とグループををmailmanに変更します。
またグループ書き込み許可も付けます。

# chown mailman:mailman data/aliases*
# chmod g+w data/aliases*

サイトリスト登録
# bin/newlist mailman
リスト管理者のメールアドレスを入力してください: webmaster@testserver.ddo.jp
mailman の初期パスワード:
Enter を押して mailman の管理者にメール通知する…

# bin/config_list -i data/sitelist.cfg mailman
標準でない値を修復: personalize

mailmanのcronを設定します。
# cd /usr/local/mailman/cron
# crontab -u mailman crontab.in
確認
# crontab -l -u mailman

起動します。
# /usr/local/mailman/bin/mailmanctl start

起動状況を確認

# ps aux | grep mailman
mailman 5166 0.0 1.0 14716 5444 ? Ss 11:14 0:00 /usr/bin/python /usr/local/mailman/bin/mailmanctl star
mailman 5167 0.9 1.4 14472 7336 ? S 11:14 0:00 /usr/bin/python /usr/local/mailman/bin/qrunner –runner=ArchRunner:0:1 -s
mailman 5168 0.8 1.4 14472 7352 ? S 11:14 0:00 /usr/bin/python /usr/local/mailman/bin/qrunner –runner=BounceRunner:0:1 -s
mailman 5169 0.9 1.4 14476 7340 ? S 11:14 0:00 /usr/bin/python /usr/local/mailman/bin/qrunner –runner=CommandRunner:0:1 -s
mailman 5170 0.8 1.4 14472 7300 ? S 11:14 0:00 /usr/bin/python /usr/local/mailman/bin/qrunner –runner=IncomingRunner:0:1 -s
mailman 5171 0.9 1.4 14460 7384 ? S 11:14 0:00 /usr/bin/python /usr/local/mailman/bin/qrunner –runner=NewsRunner:0:1 -s
mailman 5172 1.0 1.4 14860 7680 ? S 11:14 0:00 /usr/bin/python /usr/local/mailman/bin/qrunner –runner=OutgoingRunner:0:1 -s
mailman 5173 0.9 1.4 14472 7472 ? S 11:14 0:00 /usr/bin/python /usr/local/mailman/bin/qrunner –runner=VirginRunner:0:1 -s
mailman 5174 0.9 1.4 14472 7364 ? S 11:14 0:00 /usr/bin/python /usr/local/mailman/bin/qrunner –runner=RetryRunner:0:1 -s
root 5176 0.0 0.1 5108 788 pts/0 R+ 11:14 0:00 grep mailman

自動起動を登録します。
起動スクリプトをコピー
# cp /usr/local/mailman/scripts/mailman /etc/rc.d/init.d/
スクリプトが動く事を確認
# /etc/init.d/mailman stop
# /etc/init.d/mailman start
問題かければchkconfigに登録
# chkconfig –add mailman
# chkconfig mailman on
# chkconfig –list | grep mailman
mailman 0:off 1:off 2:on 3:on 4:on 5:on 6:off

●mailmanの確認
管理画面は
http://サーバ名/mailman/admin

リストを作ってみます。
http://サーバ名/mailman/create
「リストの名前」⇒test

「リスト管理者アドレスの初期設定」⇒リスト管理者メールアドレス

「初期パスワードを自動生成しますか?」⇒はい

「リスト作成者の認証パスワード」⇒メーリングリストサーバー管理パスワード

「リストを作成する」ボタン押下

管理画面でリストができていればOKです。

wordpressドメイン変更手順

自分が使っている無料のDDNS(Dynamic Domain Name System)のサービスの1つが
サービス変更により使えなくなってしまいました。
まあ、無料だし仕方がないのでひとまず別に持っていたDDNSのドメインに収容変えしました。
普通にapacheのconfig部分だけ修正して再起動したんですがwordpressは前のドメインのままで表示されません( ̄□ ̄;

どうすればいいんだろうとググっていたらmysqlのDBにドメイン名が入っているとのことでこの値を変更して上げれば
良いみたいです。

wp_optionsのsiteurlとhomeというキーにドメイン名が入った値があるみたいで、この2つの値を変更します。

mysql > update wp_options set option_value=replace(option_value, ‘nekofamily.ddo.jp’, ‘neko.mydns.jp’) where option_name in (‘siteurl’, ‘home’);

サクッと終わりました。

サイトも新しいドメインで表示されるようになりました。
—————————————————————————————————–
11月27日追記
投稿ページのリンク等はそのまま前のURLになっていました。
一括で変更する手段を探しましたが見つからず、1つ1つ修正しています。。。