2014年8月30日土曜日

CentOS6.x + S3QL 2系 (インストール編)

2014年9月7日追記:
9月5日にバージョン2.11.1がリリースされています。
⇒主な変更点は、バージョン2.11でmountt.s3qlコマンドがデーモン化しなくなったのが、元に戻った事です。
下記の記事は特に修正はしていませんが、同様の手順でバージョン2.11.1の導入が可能なので、試すのであれば最新版でどうぞ!!



S3QLとは、Amazon S3のようなストレージサービスをローカルにマウントし、通常のハードディスクのようなデータ操作を可能にするツールです。
⇒もちろん実際のデータはローカルではなく、ストレージサービス側に保存されます

現在、S3QLには(原則、機能追加を行わないバグフィックスだけの)バージョン1系と(新機能追加など活発な開発が行われている)バージョン2系が存在します。

どうせ使うなら新しいほうが良いよねという事で、CentOS6.5(x86_64)にバージョン2.11(2014年8月時点での最新版)を導入するのが今回の内容です。


基本的には、以下のドキュメントを参考に進めていきます。
http://www.rath.org/s3ql-docs/installation.html
https://bitbucket.org/nikratio/s3ql/wiki/installation_centos



S3QL ver2.11のインストール


1.ビルドに必要なパッケージをインストール
# yum install autoconf gcc unzip fuse fuse-devel libattr-devel

2.Python3.3のインストール
バージョン2系はPythonの3.3以上が必要になるので、ドキュメントを真似てPUIAS repoからPython3.3をインストールします。
※1行だけ、文字が小さくなってすみません(変なところで改行が入るのを防ぐ為)

# cd /etc/pki/rpm-gpg/
# wget -q http://springdale.math.ias.edu/data/puias/6/x86_64/os/RPM-GPG-KEY-puias
# rpm --import RPM-GPG-KEY-puias
# cat <<EOF >> /etc/yum.repos.d/puias-computational.repo
> [PUIAS_6_computational]
> name=PUIAS Computational Base
> mirrorlist=http://puias.math.ias.edu/data/puias/computational/\$releasever/\$basearch/mirrorlist
> gpgcheck=1
> gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-puias
> EOF
#
# yum install python3 python3-devel python3-libs

3.Pythonのパッケージ管理ツールpipのインストール
この作業でsetuptoolsも一緒にインストールされます。

# wget -O - https://raw.github.com/pypa/pip/master/contrib/get-pip.py | python3
# pip -V
pip 1.5.6 from /usr/lib/python3.3/site-packages (python 3.3)
#
# pip list
pip (1.5.6)
setuptools (5.4.2)
#

4.SQLiteをソースでインストール
OS標準のパッケージsqlite-3.6.20とコンフリクト(上書き)しないように、/usr/local/sqlite-3.8配下にインストールします。

$ wget http://www.sqlite.org/2014/sqlite-autoconf-3080500.tar.gz
$ tar zxf sqlite-autoconf-3080500.tar.gz
$ cd sqlite-autoconf-3080500
$ ./configure --prefix=/usr/local/sqlite-3.8
$ make
$ su
Password: パスワードの入力
# make install
# echo "/usr/local/sqlite-3.8/lib" > /etc/ld.so.conf.d/sqlite.conf
# ldconfig

5.Pythonモジュールのインストール
ドキュメントに指定されているPythonモジュールをインストールします。
# pip install pycrypto
# pip install defusedxml
# pip install requests
# pip install llfuse
# pip install dugong

6.APSWモジュールのインストール
SQLiteを/usr/local/sqlite-3.8配下にインストールしているので、それに合わせてsetup.pyファイルを編集してからインストールを実施します。
# wget https://github.com/rogerbinns/apsw/releases/download/3.8.5-r1/apsw-3.8.5-r1.zip
# unzip apsw-3.8.5-r1.zip
# cd apsw-3.8.5-r1
# cp -p setup.py{,.orig}
# vi setup.py
<編集後のdiff出力>====================================
--- setup.py.orig       2014-06-04 21:32:56.000000000 +0900
+++ setup.py    2014-08-14 22:43:08.417085436 +0900
@@ -19,8 +19,8 @@
 ## http://www.python.org/doc/2.5.2/dist/setup-config.html
 ##
-include_dirs=['src']
-library_dirs=[]
+include_dirs=['src','/usr/local/sqlite-3.8/include']
+library_dirs=['/usr/local/sqlite-3.8/lib']
 define_macros=[]
 libraries=[]
=====================================================
# python3 setup.py install

7.S3QL 導入前の確認
今までの作業の結果、インストールしたモジュール等を確認すると以下のようになります。

# pip list
Warning: cannot find svn location for apsw==3.8.5-r1
apsw (3.8.5-r1)
defusedxml (0.4.1)
dugong (3.2)
llfuse (0.40)
pip (1.5.6)
pycrypto (2.6.1)
requests (2.3.0)
setuptools (5.4.1)
#

8.S3QL 2.11のインストール
APSWモジュールのインストールと同様に、ソースでインストールしたSQLiteを指定してインストールします。
# wget https://bitbucket.org/nikratio/s3ql/downloads/s3ql-2.11.tar.bz2
# tar jxf s3ql-2.11.tar.bz2
# cd s3ql-2.11
#
# python3 setup.py build_ext --include-dirs='/usr/local/sqlite-3.8/include' \
> --library-dirs='/usr/local/sqlite-3.8/lib' --inplace
# python3 runtests.py tests
(snip)
========= 550 passed, 17 skipped, 1 warnings in 161.45 seconds ===========
#
# python3 setup.py install
(snip)
Using /usr/lib64/python3.3/site-packages
Finished processing dependencies for s3ql==2.11
#

 結果、S3QLのコマンド群が以下のようにインストールされます。
# ls -l /usr/bin/*s3ql*
-rwxr-xr-x 1 root root 294 Aug 29 23:17 /usr/bin/fsck.s3ql*
-rwxr-xr-x 1 root root 294 Aug 29 23:17 /usr/bin/mkfs.s3ql*
-rwxr-xr-x 1 root root 296 Aug 29 23:17 /usr/bin/mount.s3ql*
-rwxr-xr-x 1 root root 290 Aug 29 23:17 /usr/bin/s3qladm*
-rwxr-xr-x 1 root root 288 Aug 29 23:17 /usr/bin/s3qlcp*
-rwxr-xr-x 1 root root 292 Aug 29 23:17 /usr/bin/s3qlctrl*
-rwxr-xr-x 1 root root 292 Aug 29 23:17 /usr/bin/s3qllock*
-rwxr-xr-x 1 root root 310 Aug 29 23:17 /usr/bin/s3ql_oauth_client*
-rwxr-xr-x 1 root root 288 Aug 29 23:17 /usr/bin/s3qlrm*
-rwxr-xr-x 1 root root 292 Aug 29 23:17 /usr/bin/s3qlstat*
-rwxr-xr-x 1 root root 298 Aug 29 23:17 /usr/bin/s3ql_verify*
-rwxr-xr-x 1 root root 298 Aug 29 23:17 /usr/bin/umount.s3ql*
#


長くなったのでここまでで一旦終了とし、次回、実際にAmazon S3をマウントしてみたいと思います。

2014年7月24日木曜日

DRBD 8.4.x コミュニティバイナリでセットアップ

以前「DRBD8.4.x RPM作成」という記事を書きましたが、そんな面倒な事をせずにほぼ最新のRPMが用意されているコミュニティ(ELrepo)版バイナリでセットアップしよう!というのが今回の内容です。

#検証環境は、CentOS6.5(x86_64) x2台です
 - ホスト名はそれぞれnode01とnode02です
 - コマンドプロンプトに[ALL]とある場合は、両方のホストで作業を実施し、
  [ONE]とある場合は、どちらか片方のホストで作業を実施する事を意味します


ELrepoリポジトリの作成

ELrepoのサイトに書いてあるとおりですが、下記のようにリポジトリを作成します。
[ALL]# rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
[ALL]# rpm -Uvh http://www.elrepo.org/elrepo-release-6-6.el6.elrepo.noarch.rpm
Retrieving http://www.elrepo.org/elrepo-release-6-6.el6.elrepo.noarch.rpm
Preparing...                ########################################### [100%]
   1:elrepo-release         ########################################### [100%]
[ALL]#


DRBDのインストール

[ALL]# yum install drbd84-utils kmod-drbd84


DRBDのセットアップ

※詳細は、以前に書いた「DRBD 8.4.x 設定(初回フル同期スキップ)」の”DRBD領域の準備”以降を参照してください。

ここではざっと流れだけをあげておきます。

1.DRBD領域の用意 → ファイルシステムを作成していないまっさらなパーティションを用意
2.DRBDの設定ファイルの作成
3.metaデータ領域を作成
 [ALL]# drbdadm create-md r0/0
4.DRBDの起動
 [ALL]# /etc/rc.d/init.d/drbd start
5.どちらかをmasterに昇格して、初回同期
 [ONE]# drbdadm primary r0/0
  [ONE]# drbdaldm new-current-uuid -clear-bitmap r0/0
6.master側でファイルシステムを作成し、マウント
 [ONE]# drbdadm primary r0/0
  [ONE}# mkfs.ext4 /dev/drbd0
  [ONE]# mount /dev/drbd0 /mnt
  

コミュニティ版バイナリのメリット

一番のメリットは、KMP (Kernel Module Package)に対応したパッケージングがされている事です。
具体的には、新しいkernelをインストールすると、自動的にdrbd.koが用意されるようになります。

以前に書いた「DRBD8.4.x RPM作成」では、新しいkernelが提供されるたびに、その新しいkernel用のDRBDモジュールを生成する作業が必要でした。
 →DRBDモジュールをビルドし忘れて新しいkernelで起動すると当然DRBDが起動できません

kernelのアップデートをしていくと下記のようになっていきます。
#実体はkmod-drbd84パッケージでインストールされたdrbd.koのシンボリックリンクとなります
# locate drbd.ko
/lib/modules/2.6.32-358.el6.x86_64/extra/drbd84/drbd.ko
/lib/modules/2.6.32-431.1.2.0.1.el6.x86_64/weak-updates/drbd84/drbd.ko
/lib/modules/2.6.32-431.17.1.el6.x86_64/weak-updates/drbd84/drbd.ko
/lib/modules/2.6.32-431.5.1.el6.x86_64/weak-updates/drbd84/drbd.ko
#

※詳細が知りたい場合は、weak-updatesのキーワードで検索してみてください

2014年7月8日火曜日

CentOS5.x にpostfix2.12をソースからインストール

CentOS5.xでpostfixをyumでインストールするとバージョンが2.3.3と非常に古い。
epel-postfixリポジトリを利用して、バージョン2.9や2.10をRPMで導入するのもいいのですが、どうせなら一番新しいpostfixをソースからインストールしてみよう!というのが今回の内容です。
※なお、作業はCentOS5.10(x86_64)で実施しています。


今回インストールする条件

※あくまでも1例です。
  必ずこの通りビルドしなくてはいけないという事ではないので、ドキュメントで良く確認して必要な機能を増減させてください。


・以下の2つを実現するためにstableな2.11ではなく、experimentalな2.12を利用します
 - 共有ライブラリをサポートするpostfixをビルドする
 - 様々なルックアップテーブルをプラグインとして利用する

・SMTP認証を利用します(タイプはdovecot)
・ルックアップテーブルとしてPCREを利用します
・TLSを利用します



Postfix2.12のインストール手順


1. パッケージ postfixのアンインストール

もし、インストールされていない場合は、一度インストールを実施してください。
インストール実施後、起動ファイルの/etc/rc.d/init.d/postfixを任意の場所に退避(コピー)してから改めてアンインストールを実施してください。
これで、以下の2つの作業が省略できます。

 - postfixの動作に必要なユーザやグループの作成
 - 起動ファイルの作成


2. パッケージ sendmailのアンインストール

もし、インストールされているようであればアンインストールしてください。
※Postfixをソースからインストールする事で、パッケージのsendmailに含まれるsendmailコマンドやmailqコマンドを上書いてしまう為、管理を煩雑にしないためアンインストールをお勧めします
※依存関係でエラーになる場合は下記のように"--nodeps"オプションを付与して実施してください
 →他のパッケージが依存しているsendmailコマンド等は、postfixをインストールする事で用意されます

# rpm -e --nodeps sendmail


3.openssl1.x、その他のビルドに必要なパッケージのインストール

CentOS5.xのopensslのバージョンはこちらも0.9.8と古く、そのままだとpostfix2.12ではTLS関連のビルドが行えませんので、ここではソースから最新のopensslを/usr/local配下にインストールします。
$ wget -O - http://www.openssl.org/source/openssl-1.0.1h.tar.gz | tar zxf -
$ cd openssl-1.0.1h/
$ ./config  --prefix=/usr/local
$ make
$ su
# make install

また、Postfixのビルドに必要なその他のパッケージを以下のようにインストールしておきます。
# yum -y install pcre-devel db4-devel


4.ソースの展開

$ wget http://mirror.postfix.jp/postfix-release/experimental/postfix-2.12-20140703.tar.gz  ←★改行されてますがここまでが1行
$ tar zxf postfix-2.12-20140703.tar.gz
$ cd postfix-2.12-20140703


 5.makefilesの作成

インストールする条件に合わせて、以下のように実施します。

$ make makefiles shared=yes \
shlib_directory=/usr/lib64/postfix/2.12-20140703/ dynamicmaps=yes \
CCARGS="-DUSE_TLS -DUSE_SASL_AUTH -DDEF_SERVER_SASL_TYPE=\\\"dovecot\\\" \
-I/usr/local/include/openssl" \
AUXLIBS="-lssl -lcrypto -L/usr/local/lib64" \
AUXLIBS_PCRE=`pcre-config --libs`


6. ビルドとインストール

$ make
$ su
# make install
   (snip)
  ※以下、聞かれる質問には、表示されるものをそのまま選択します(Enterを押していきます)。
Please specify the prefix for installed file names. Specify this ONLY
if you are building ready-to-install packages for distribution to OTHER
machines. See PACKAGE_README for instructions.
install_root: [/]
Please specify a directory for scratch files while installing Postfix. You
must have write permission in this directory.
tempdir: [/home/toshiaki/postfix-2.12-20140703]
Please specify the final destination directory for installed Postfix
configuration files.
config_directory: [/etc/postfix]
Please specify the final destination directory for installed Postfix
administrative commands. This directory should be in the command search
path of adminstrative users.
command_directory: [/usr/sbin]
Please specify the final destination directory for installed Postfix
daemon programs. This directory should not be in the command search path
of any users.
daemon_directory: [/usr/libexec/postfix]
Please specify the final destination directory for Postfix-writable
data files such as caches or random numbers. This directory should not
be shared with non-Postfix software.
data_directory: [/var/lib/postfix]
Please specify the final destination directory for the Postfix HTML
files. Specify "no" if you do not want to install these files.
html_directory: [no]
Please specify the owner of the Postfix queue. Specify an account with
numerical user ID and group ID values that are not used by any other
accounts on the system.
mail_owner: [postfix]Please specify the final destination pathname for the installed Postfix
mailq command. This is the Sendmail-compatible mail queue listing command.
mailq_path: [/usr/bin/mailq]
Please specify the final destination directory for the Postfix on-line
manual pages. You can no longer specify "no" here.
manpage_directory: [/usr/local/man]
Please specify the final destination pathname for the installed Postfix
newaliases command. This is the Sendmail-compatible command to build
alias databases for the Postfix local delivery agent.
newaliases_path: [/usr/bin/newaliases]
Please specify the final destination directory for Postfix queues.
queue_directory: [/var/spool/postfix]
Please specify the final destination directory for the Postfix README
files. Specify "no" if you do not want to install these files.
readme_directory: [no]
Please specify the final destination pathname for the installed Postfix
sendmail command. This is the Sendmail-compatible mail posting interface.
sendmail_path: [/usr/sbin/sendmail]
Please specify the group for mail submission and for queue management
commands. Specify a group name with a numerical group ID that is
not shared with other accounts, not even with the Postfix mail_owner
account. You can no longer specify "no" here.
setgid_group: [postdrop]
Please specify the final destination directory for Postfix shared-library
files.
shlib_directory: [/usr/lib64/postfix/2.12-20140703/]
Please specify the final destination directory for non-executable files
that are shared among multiple Postfix instances, such as postfix-files,
dynamicmaps.cf, as well as the multi-instance template files main.cf.proto
and master.cf.proto.
meta_directory: [/etc/postfix]

 (snip)

    Warning: you still need to edit myorigin/mydestination/mynetworks
    parameter settings in /etc/postfix/main.cf.
    See also http://www.postfix.org/STANDARD_CONFIGURATION_README.html
    for information about dialup sites or about sites inside a firewalled
    network.
    BTW: Check your /etc/aliases file and be sure to set up aliases
    that send mail for root and postmaster to a real person, then run
    /usr/bin/newaliases.
#



Postfixの起動など

後は、/etc/aliasesや/etc/postfix/main.cfなどの設定ファイルを編集しすれば、postfixが起動できます。

# postfix start (もしくは # /usr/sbin/postfix start

また、os起動時にpostfixを自動起動させるには、postfixをアンインストールする前に退避させておいた/etc/rc.d/init.d/postfixファイルを元の場所にもどし、以下のように設定します。

# chkconfig --add postfix
# chkconfig postfix on 



(備考)

静的ライブラリと共有ライブラリでのバイナリファイルのサイズの違い


<静的ライブラリ>
# ls -lh /usr/sbin/post*
-rwxr-xr-x 1 root root     193K Jan  9  2013 /usr/sbin/postalias*
-rwxr-xr-x 1 root root     112K Jan  9  2013 /usr/sbin/postcat*
-rwxr-xr-x 1 root root     261K Jan  9  2013 /usr/sbin/postconf*
-rwxr-sr-x 1 root postdrop 168K Jan  9  2013 /usr/sbin/postdrop*
-rwxr-xr-x 1 root root     100K Jan  9  2013 /usr/sbin/postfix*
-rwxr-xr-x 1 root root     112K Jan  9  2013 /usr/sbin/postkick*
-rwxr-xr-x 1 root root     108K Jan  9  2013 /usr/sbin/postlock*
-rwxr-xr-x 1 root root     100K Jan  9  2013 /usr/sbin/postlog*
-rwxr-xr-x 1 root root     185K Jan  9  2013 /usr/sbin/postmap*
-rwxr-sr-x 1 root postdrop 189K Jan  9  2013 /usr/sbin/postqueue*
-rwxr-xr-x 1 root root     116K Jan  9  2013 /usr/sbin/postsuper*

<共有ライブラリ>
 ※サイズが大幅に小さくなっているのが確認できます
# ls -lh /usr/sbin/post*
-rwxr-xr-x 1 root root      34K Jul  7 00:34 /usr/sbin/postalias*
-rwxr-xr-x 1 root root      29K Jul  7 00:34 /usr/sbin/postcat*
-rwxr-xr-x 1 root root     318K Jul  7 00:34 /usr/sbin/postconf*
-rwxr-sr-x 1 root postdrop  27K Jul  7 00:34 /usr/sbin/postdrop*
-rwxr-xr-x 1 root root      22K Jul  7 00:34 /usr/sbin/postfix*
-rwxr-xr-x 1 root root      16K Jul  7 00:34 /usr/sbin/postkick*
-rwxr-xr-x 1 root root      19K Jul  7 00:34 /usr/sbin/postlock*
-rwxr-xr-x 1 root root      18K Jul  7 00:34 /usr/sbin/postlog*
-rwxr-xr-x 1 root root      39K Jul  7 00:34 /usr/sbin/postmap*
-rwxr-xr-x 1 root root      52K Jul  7 00:34 /usr/sbin/postmulti*
-rwxr-sr-x 1 root postdrop  30K Jul  7 00:34 /usr/sbin/postqueue*
-rwxr-xr-x 1 root root      48K Jul  7 00:34 /usr/sbin/postsuper*




2014年6月28日土曜日

Fedora20 テキスト インストール

マシンスペックの向上した現在、そんなに出番はないと思いますが・・・
Fedora20をテキストモードでインストールしようというのが今回の内容です。



最初にこのモードでインストールする場合の注意点を2つあげておきます。
これが許容できない場合は、他の手段でのインストールを検討してください。

  1. ディスクレイアウトをカスタマイズできない 
  2. インストール完了後、コンソールのKEYMAPが英語になる
         ※コンソールのKEYMAPを変更したい場合は、この記事の一番最後を見てください




テキストインストール


それでは早速インストールをしていきましょう。

1.インストールが開始されたら画面下部の「Press Tab for full configuration options on menu items.」のメッセージに従って、TABキーを押します。ブートオプションとして、textを指定します。





2.次に、最初に注意としてあげたディスクのパーティショニングについての情報が表示され、textモードではなくvncモードでのインストールを代替案として提示されます。ここではテキストモードでインストールする為、”2”と入力します。
 ※vncでのインストールは、こちらの記事を参照してください


















すると画面下部にInstallationメニューが表示されます。
項目的には1)~7)まであり、設定が必要な箇所には”!”マークがついていて、これを全て設定済み(”x”マーク)にしていきます。






3.各項目の設定

※画面の一番下に「Please make your choice from above ['q' to quit | 'c' to continue | 'r' to refresh]: 」とあるように、もし項目をちゃんとセットアップしたのにもかかわらず”x”マークがつかない場合は、一度”r”キーを押してrefreshを実施してみてください。


1)Timezone Settings
上記の画面から1と入力後、Asiaの6 → Tokyoの71と選択しました。

2)Installation source
2と入力後、ここではCD/DVDの1と選択しました。

3)Software selecttion
3と入力後、ここではMinimal Installの12 → continueのcと進めました。

4)Installation Destination
4と入力後、c  → Use All Spaceの2 → c → Standard Partitionの1 → c と進めました。

5)Network configuration
DHCPでIPが取得できると最初から”x”マークがついていますが、固定IPを設定するには5と入力後

- Set hostnameの1を入力後、サーバのホスト名を入力
- Configure device xxxxの2を入力後、必要箇所を一つづつ入力











で最後に c → c と進めました。

6)Root password
6と入力後、任意のパスワードを2回入力しました。

7)User creation
7と入力後、一般(作業用)ユーザを作成しました。
 - 3)Username でユーザ名を
 - 4) Use password でパスワード認証を有効に
 - 5) Passwordで、ユーザのパスワードを設定
 - 6) Administratorの箇所にチェックを入れることでsudoの設定が有効になります


以上で、下記のように全ての項目にxがついた状態でcを入力するとインストールが開始されます。




そして、「Installation complete. Press return to quit」と表示されたらインストールは完了です。
表示されたとおりRetrunキーを押し、インストーラーを終了させてください。






















コンソールのKEYMAPを変更するには


ここでは、jp106へ変更してみます。
※変更が完了するまでは、コンソールは英語のKEYMAPになっているので、可能であればPuttyなどのSSHクライアントから作業を実施した方が良いかもしれません


1. /etc/vconsole.confの修正

以下の記述だけにします。
KEYMAP="jp106"

2. Setup Virtual Consoleの再起動
# systemctl status systemd-vconsole-setup.service
systemd-vconsole-setup.service - Setup Virtual Console
   Loaded: loaded (/usr/lib/systemd/system/systemd-vconsole-setup.service; static)
   Active: active (exited) since Sat 2014-06-28 16:40:14 JST; 27min ago
     Docs: man:systemd-vconsole-setup.service(8)
           man:vconsole.conf(5)
 Main PID: 72 (code=exited, status=0/SUCCESS)
Jun 28 16:40:14 test.examp.com systemd[1]: Starting Setup Virtual Console...
Jun 28 16:40:14 test.examp.com systemd[1]: Started Setup Virtual Console.
#
# systemctl restart systemd-vconsole-setup.service

以上で、コンソールのKEYMAPも日本語になっているはずです。

2014年5月20日火曜日

Fedora20 VNC経由でインストール

タイトルのとおり、Fedora20をVNC経由でインストールしようというのが今回の内容です。



インストールするサーバでの作業


1.インストールが開始されたら画面下部の「Press Tab for full configuration options on menu items.」のメッセージに従って、TABキーを押します。
するとブートオプションが入力できるようになるので、ここでvncと入力後、Enterを押します。




















2.多少時間はかかりますが、下記の図のようにvnc clientから接続する情報が提示されるので、メモをしておきます。







クライアントからの作業


ここからは、VNC Viewerのインストールされている端末から作業を継続します。
※私の場合は、Windows7+Chrome+拡張機能(VNC Viewer for Google Chrome)でアクセスしました




VNC Viewerを起動するとインストールするサーバのIPアドレスをきかれるので、サーバでの作業2.のところでメモした情報を入力して、[Connect]をクリックします。




















すると、以下のようにインストーラーが立ち上がるので、後は通常どおりインストールを進めます。


2014年5月6日火曜日

Linux Tips: コンソールでの文字化けを解消するには

久しぶりにDebian系ディストリのインストールを行った。
その際、インストール初期に聞かれるLanguageの画面で”日本語”を選択し、インストールを完了させました。
次に、コンソールを利用したのですが、manを見れば文字化け、apt-get updateをすれば表示されるメッセージは文字化けと困った事に。


原因は、日本語でセットアップしたことにより、localeが以下のように設定されてしまうから。
→コンソールで、ja_JP.UTF-8の表示は基本的にまともにできない
 (いまでもkonとかあるんだろうか → さがしたらkon2とかでてきますね)
~$ locale
LANG=ja_JP.UTF-8
LANGUAGE=
LC_CTYPE="ja_JP.UTF-8"
LC_NUMERIC="ja_JP.UTF-8"
LC_TIME="ja_JP.UTF-8"
LC_COLLATE="ja_JP.UTF-8"
LC_MONETARY="ja_JP.UTF-8"
LC_MESSAGES="ja_JP.UTF-8"
LC_PAPER="ja_JP.UTF-8"
LC_NAME="ja_JP.UTF-8"
LC_ADDRESS="ja_JP.UTF-8"
LC_TELEPHONE="ja_JP.UTF-8"
LC_MEASUREMENT="ja_JP.UTF-8"
LC_IDENTIFICATION="ja_JP.UTF-8"
LC_ALL=
$

前置きが長くなりましたが、この状態を回避しようというのが今回の内容です。


回避策

1.インストール初期のLanguageをEnglishにしてインストールし直す


時間が許せばこの方法が、一番ベストだと思います。
これでlocaleは、en_US.UTF-8あたりに設定されるので、基本的に文字化けしません。
※サーバ用途では、日本語による表示を必要としないのなら、不必要なパッケージのインストールを防ぐという観点から、これを特にお勧めします


2.コンソールにログイン後、環境変数を設定する


ログイン後、以下のコマンドを毎回実行してから作業を実施します。
※これが面倒な場合は下記の3.を試してください。
$ export LANG=C


3. 作業する$TERMにあわせて$LANGを自動的に選択させる


以下の記述を~/.bashrcあたりにすることによって、$TERMの種類により、ログインする環境にあわせた$LANGを設定する事ができます。
※コンソールはCの表示にし、それ以外(例えばxtermやWindows上のPuttyなど)は日本語での表示を可能にします

case $TERM in
   linux)
        LANG=C
        ;;
   *)
    LANG=ja_JP.UTF-8
    ;;
esac
export LANG


(備考)
Redhat系の場合、この3.と同様の設定が、Fedoraだと8あたりから、CentOSだと5から/etc/profile.d/lang.shとして用意されています

2014年5月2日金曜日

Fedora20 インストール画面がまともに表示されなかったら

自分のところでは、VMware環境で100%なってしまいますが)インストールを開始してパーティショニングするところで、下の画像のように、画面の表示がおかしくなり困った事はないでしょうか?
この状況を回避しようというのが今回の内容です。







回避策


インストーラーのAnacondaで解像度を調整することにより回避する事ができます。

1.インストールが開始されたら画面下部の「Press Tab for full configuration options on menu items.」のメッセージに従って、TABキーを押します。





2.するとブートオプションを入力できるようになるので、ここに解像度を指定してやります。
  ここでは、resolution=1024x768と指定しました。



結果、以下のように画面全てがまともに表示されるようになります。




(備考)
Anacondaのブートオプションには、その他に有用な(面白そうな)ものが結構あるので興味があれば調べてみると良いかもしれません。

https://fedoraproject.org/wiki/Anaconda_Boot_Options?rd=Anaconda/Options