2011年8月15日月曜日

[Emacs]さくらVPSセットアップ

前回、さくらVPSの環境にLAMP環境を構築しました。

今回は開発環境らしくするため、Emacsをインストールします。

■gccをインストール
gccが入っていないとはじまりませんな。
$yum install gcc*

■Emacsをインストール
ソースGet!
$ wget ftp://ftp.ring.gr.jp/pub/GNU/emacs/emacs-23.1.tar.gz
$ wget http://ftp.gnu.org/pub/gnu/emacs/emacs-23.1.tar.gz
$ tar xzf emacs-23.1.tar.gz
$ ls -la

$ ./configure --without-x
$ make
$ make install
$ emacs --version
GNU Emacs 23.1.1
Copyright (C) 2009 Free Software Foundation, Inc.
GNU Emacs comes with ABSOLUTELY NO WARRANTY.
You may redistribute copies of Emacs
under the terms of the GNU General Public License.
For more information about these matters, see the file named COPYING.

Emacs設定ファイルの配置
私は各種設定ファイルをさまざまな環境で共有できるようにDropboxに保存しています。

今回もDropboxからファイルダウンロードして配置しようかと思いましたが、
以下のページを見つけてこのやり方はまずいかなと、再検討しております。

さくらVPSでDropboxをX11なしで使う
Dropboxを使うな、とまでは言いませんが

とりあえず、".emacs"は作成したけれど、何か良い手はないものか。

2011年8月7日日曜日

[LAMP][CentOS]さくらVPSセットアップ

■概要
さくらVPSにLAMP環境を構築します。

■基本情報
OS   : CentOS 5(2011/8時点の最小構成)
ディスク: 20GB
メモリ : 512MB

■パッケージ確認
Apache、MySQL、PHPそれぞれのインストールパッケージを確認します。
# yum list | grep httpd
httpd.x86_64 2.2.3-45.el5.centos.1 updates
httpd-devel.i386 2.2.3-45.el5.centos.1 updates
httpd-devel.x86_64 2.2.3-45.el5.centos.1 updates
httpd-manual.x86_64 2.2.3-45.el5.centos.1 updates
system-config-httpd.noarch 5:1.3.3.3-1.el5 base

# yum list | grep mysql
apr-util-mysql.x86_64 1.2.7-11.el5_5.2 base
bytefx-data-mysql.x86_64 1.2.4-2.el5.centos extras
freeradius-mysql.x86_64 1.1.3-1.6.el5 base
freeradius2-mysql.x86_64 2.1.7-7.el5 base
libdbi-dbd-mysql.x86_64 0.8.1a-1.2.2 base
mod_auth_mysql.x86_64 1:3.0.0-3.2.el5_3 base
mysql.i386 5.0.77-4.el5_6.6 updates
mysql.x86_64 5.0.77-4.el5_6.6 updates
mysql-bench.x86_64 5.0.77-4.el5_6.6 updates
mysql-connector-odbc.x86_64 3.51.26r1127-1.el5 base
mysql-devel.i386 5.0.77-4.el5_6.6 updates
mysql-devel.x86_64 5.0.77-4.el5_6.6 updates
mysql-server.x86_64 5.0.77-4.el5_6.6 updates
mysql-test.x86_64 5.0.77-4.el5_6.6 updates
pdns-backend-mysql.x86_64 2.9.21-4.el5.centos extras
php-mysql.x86_64 5.1.6-27.el5_5.3 base
php-pear-MDB2-Driver-mysql.noarch 1.4.1-3.el5.centos extras
php53-mysql.x86_64 5.3.3-1.el5_6.1 updates
qt4-mysql.x86_64 4.2.1-1 base
rsyslog-mysql.x86_64 3.22.1-3.el5_6.1 updates

# yum list | grep php
php.x86_64 5.1.6-27.el5_5.3 base
php-bcmath.x86_64 5.1.6-27.el5_5.3 base
php-cli.x86_64 5.1.6-27.el5_5.3 base
php-common.x86_64 5.1.6-27.el5_5.3 base
php-dba.x86_64 5.1.6-27.el5_5.3 base
php-dbase.x86_64 5.1.6-15.el5.centos.1 extras
php-devel.x86_64 5.1.6-27.el5_5.3 base
php-gd.x86_64 5.1.6-27.el5_5.3 base
php-imap.x86_64 5.1.6-27.el5_5.3 base
php-ldap.x86_64 5.1.6-27.el5_5.3 base
php-mbstring.x86_64 5.1.6-27.el5_5.3 base
php-mcrypt.x86_64 5.1.6-15.el5.centos.1 extras
php-mhash.x86_64 5.1.6-15.el5.centos.1 extras
php-mssql.x86_64 5.1.6-15.el5.centos.1 extras
php-mysql.x86_64 5.1.6-27.el5_5.3 base
php-ncurses.x86_64 5.1.6-27.el5_5.3 base
php-odbc.x86_64 5.1.6-27.el5_5.3 base
php-pdo.x86_64 5.1.6-27.el5_5.3 base
php-pear.noarch 1:1.4.9-6.el5 base
php-pear-Auth-SASL.noarch 1.0.2-4.el5.centos extras
php-pear-DB.noarch 1.7.13-1.el5.centos extras
php-pear-Date.noarch 1.4.7-2.el5.centos extras
php-pear-File.noarch 1.2.2-1.el5.centos extras
php-pear-HTTP-Request.noarch 1.4.2-1.el5.centos extras
php-pear-Log.noarch 1.9.13-1.el5.centos extras
php-pear-MDB2.noarch 2.4.1-2.el5.centos extras
php-pear-MDB2-Driver-mysql.noarch 1.4.1-3.el5.centos extras
php-pear-Mail.noarch 1.1.14-1.el5.centos extras
php-pear-Mail-Mime.noarch 1.4.0-1.el5.centos extras
php-pear-Net-SMTP.noarch 1.2.10-1.el5.centos extras
php-pear-Net-Sieve.noarch 1.1.5-2.el5.centos extras
php-pear-Net-Socket.noarch 1.0.8-1.el5.centos extras
php-pear-Net-URL.noarch 1.0.15-1.el5.centos extras
php-pecl-Fileinfo.x86_64 1.0.4-3.el5.centos extras
php-pecl-memcache.x86_64 2.2.3-1.el5_2 extras
php-pgsql.x86_64 5.1.6-27.el5_5.3 base
php-readline.x86_64 5.1.6-15.el5.centos.1 extras
php-snmp.x86_64 5.1.6-27.el5_5.3 base
php-soap.x86_64 5.1.6-27.el5_5.3 base
php-tidy.x86_64 5.1.6-15.el5.centos.1 extras
php-xml.x86_64 5.1.6-27.el5_5.3 base
php-xmlrpc.x86_64 5.1.6-27.el5_5.3 base
php53.x86_64 5.3.3-1.el5_6.1 updates
php53-bcmath.x86_64 5.3.3-1.el5_6.1 updates
php53-cli.x86_64 5.3.3-1.el5_6.1 updates
php53-common.x86_64 5.3.3-1.el5_6.1 updates
php53-dba.x86_64 5.3.3-1.el5_6.1 updates
php53-devel.x86_64 5.3.3-1.el5_6.1 updates
php53-gd.x86_64 5.3.3-1.el5_6.1 updates
php53-imap.x86_64 5.3.3-1.el5_6.1 updates
php53-intl.x86_64 5.3.3-1.el5_6.1 updates
php53-ldap.x86_64 5.3.3-1.el5_6.1 updates
php53-mbstring.x86_64 5.3.3-1.el5_6.1 updates
php53-mysql.x86_64 5.3.3-1.el5_6.1 updates
php53-odbc.x86_64 5.3.3-1.el5_6.1 updates
php53-pdo.x86_64 5.3.3-1.el5_6.1 updates
php53-pgsql.x86_64 5.3.3-1.el5_6.1 updates
php53-process.x86_64 5.3.3-1.el5_6.1 updates
php53-pspell.x86_64 5.3.3-1.el5_6.1 updates
php53-snmp.x86_64 5.3.3-1.el5_6.1 updates
php53-soap.x86_64 5.3.3-1.el5_6.1 updates
php53-xml.x86_64 5.3.3-1.el5_6.1 updates
php53-xmlrpc.x86_64 5.3.3-1.el5_6.1 updates

Apache2.2系、MySQL5.0系、PHP5.1系がインストール可能です。

■Apache
# yum -y install httpd
# httpd -v
Server version: Apache/2.2.3
Server built: May 4 2011 06:51:15

■MySQL

今回、MySQLは5.5系、PHPは5.3系をインストールしたい為、サードパーティのリポジトリを指定してインストールします。

リポジトリの登録
# rpm -ivh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpm
# rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-5.rpm
# yum --enablerepo=remi install mysql mysql-server

MySQLサーバ起動
# /etc/rc.d/init.d/mysqld start
MySQL Daemon failed to start.
Starting mysqld: [FAILED]

失敗する。ログを確認してみる。
# cat /var/log/mysqld.log
110807 20:03:29 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
110807 20:03:29 [ERROR] Error message file '/usr/share/mysql/english/errmsg.sys' had only 480 error messages,
but it should contain at least 712 error messages.
Check that the above file is the right version for this program!
110807 20:03:29 [Note] Plugin 'FEDERATED' is disabled.
/usr/libexec/mysqld: Unknown error 1146
110807 20:03:29 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
110807 20:03:29 InnoDB: The InnoDB memory heap is disabled
110807 20:03:29 InnoDB: Mutexes and rw_locks use GCC atomic builtins
110807 20:03:29 InnoDB: Compressed tables use zlib 1.2.3
110807 20:03:29 InnoDB: Using Linux native AIO
110807 20:03:29 InnoDB: Initializing buffer pool, size = 128.0M
110807 20:03:29 InnoDB: Completed initialization of buffer pool
InnoDB: The first specified data file ./ibdata1 did not exist:
InnoDB: a new database to be created!
110807 20:03:29 InnoDB: Setting file ./ibdata1 size to 10 MB
InnoDB: Database physically writes the file full: wait...
110807 20:03:30 InnoDB: Log file ./ib_logfile0 did not exist: new to be created
InnoDB: Setting log file ./ib_logfile0 size to 5 MB
InnoDB: Database physically writes the file full: wait...
110807 20:03:30 InnoDB: Log file ./ib_logfile1 did not exist: new to be created
InnoDB: Setting log file ./ib_logfile1 size to 5 MB
InnoDB: Database physically writes the file full: wait...
InnoDB: Doublewrite buffer not found: creating new
InnoDB: Doublewrite buffer created
InnoDB: 127 rollback segment(s) active.
InnoDB: Creating foreign key constraint system tables
InnoDB: Foreign key constraint system tables created
110807 20:03:31 InnoDB: Waiting for the background threads to start
110807 20:03:32 InnoDB: 1.1.8 started; log sequence number 0
110807 20:03:32 [ERROR] Aborting

110807 20:03:32 InnoDB: Starting shutdown...
110807 20:03:33 InnoDB: Shutdown completed; log sequence number 1595675
110807 20:03:33 [Note]
110807 20:03:33 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended

メッセージファイル(/usr/share/mysql/english/errmsg.sys)の競合が発生しているようです。

該当ファイルの競合を確認
# rpm -q --whatprovides /usr/share/mysql/english/errmsg.sys
mysql-libs-5.5.15-1.el5.remi
mysql-5.0.77-4.el5_6.6

2つのバージョンが競合していることが分かりました。現状のmysqlをいったん削除します。
# yum -y remove mysql mysql-server mysql-libs

明示的にバージョン指定
# yum --enablerepo=remi install mysql-server.x86_64
# yum --enablerepo=remi install mysql-devel.x86_64

# mysql_install_db

# /etc/rc.d/init.d/mysqld start

因みにMySQL5.5系ではmy.cnfに以下の設定を記述すると起動しない。innodbがデフォルトエンジンだからかも。 
設定内容:skip_innodb

■PHP
# yum install -y --enablerepo=remi php
# php -v
PHP 5.3.6 (cli) (built: May 16 2011 19:18:05)
Copyright (c) 1997-2011 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies

以上です。

2011年7月18日月曜日

[Windows][Cygwin]新規ユーザを追加する

■概要
Cygwinではuseradd(UNIXでのユーザ追加コマンド)が存在しません。

■ユーザ登録
ユーザの追加はWindowsのユーザを/etc/passwdファイルに追記します。
mkpasswd -l -u UserName >> /etc/passwd

以上です。

2011年7月10日日曜日

[Linux][CentOS]新規ユーザを追加する

■概要
Linuxで新しくサーバを構築する際に、必ず実行する手順であるユーザの追加方法を
まとめます。

以下CentOSで作業しますが、bashが使える環境であれば同様のコマンドを
使用できます。

■ユーザ登録
セキュリティ上、rootユーザは使用しないポリシーとし、
新規ユーザに適切なsudo権限を付与する運用がベターです。

・新規ユーザ用グループを作成

※rootユーザで作業する

# groupadd appmng

・新規ユーザ作成
# useradd -g appmng appmng
# ls -l /home/
合計 4
drwx------ 2 appmng appmng 4096  7月  1 15:28 2011 appmng
⇒作成されていること

・新規ユーザのパスワードを変更する
# passwd appmng
ユーザー appmng のパスワードを変更。
新しいパスワード:
新しいパスワードを再入力してください:
passwd: 全ての認証トークンが正しく更新できました。

・新規ユーザにsudo権限を付与します。
# cp -pi /etc/sudoers /etc/sudoers.YYYYMMDD
# vim /etc/sudoers
ppmng  ALL=(ALL)       ALL

・rootユーザでの作業を終了します。
# exit

・新規ユーザのログイン確認
$ ssh appmng@xxx.xxx.xxx.xxx
$ uname -n
⇒ホスト名が表示される
$ id
uid=500(appmng) gid=500(appmng) 所属グループ=500(appmng)


以上です。

2011年5月31日火曜日

[Ruby] gem updateがエラーとなった場合の対応

■概要
gem updateのエラーごとの対応をまとめていく

1.Proxy認証エラー
$ gem update --system
Updating RubyGems
ERROR: http://gems.rubyforge.org/ does not appear to be a repository
ERROR: While executing gem ... (Gem::RemoteFetcher::FetchError)
Errno::ECONNREFUSED: 対象のコンピュータによって拒否されたため、接続できませ
んでした。 - connect(2) (http://gems.rubyforge.org/yaml)

Proxy認証を通すコマンドは以下の通り
gem update --system --http-proxy http://User:Passward@Proxy_Server:Port_No

以上です。

2011年5月11日水曜日

[Deploy][Mac] Capistranoコマンド試行

前回、Capistranoをセットアップしました。
[Deploy][Mac] Capistranoセットアップ

今回は実際にコマンドを発行してみます。

まずローカルでCapfileという設定ファイルを作成します。
ファイルはどこで作成しても問題ありません。

$ vim Capfile
set :user, 'app' // 実行ユーザを指定。ここでは前回作成したappユーザを指定します。
task :diskcheck, :hosts => "192.168.251.131" do // タスク名と実行ホストを指定。
run "df -kh" // 実行コマンドを指定。ここではリモートサーバのディスク使用量を確認するコマンドを指定してみます。
end

Capfileを作成したら、実際にコマンドを発行してみます。
$cap diskcheck
* executing `diskcheck'
* executing "df -kh"
servers: ["192.168.251.131"]
[192.168.251.131] executing command
** [out :: 192.168.251.131] Filesystem サイズ 使用 残り 使用% マウント位置
** [out :: 192.168.251.131] /dev/mapper/VolGroup00-LogVol00
** [out :: 192.168.251.131] 18G 5.9G 11G 36% /
** [out :: 192.168.251.131] /dev/sda1 99M 12M 82M 13% /boot
** [out :: 192.168.251.131] tmpfs 506M 0 506M 0% /dev/shm
command finished in 130ms

対応するタスクが実行され、リモートサーバのディスク使用量を確認することができました。

Capistranoにはデプロイ用のタスクが予め多数用意されていて、それを使用することでデプロイを容易に行うことができます。
次回からはデプロイ用タスクを掘り下げて行きます。


以上です。

2011年5月7日土曜日

[Deploy][Mac] Capistranoセットアップ

自宅MacにCapistranoをインストールして、いろいろやってみようという試み。

CapistranoはRubyで動作する有名なデプロイツール。インストールはgemを使用する。

インストール前にgemをアップデート。
$sudo gem update --system
Password:
Updating RubyGems
Updating rubygems-update
Successfully installed rubygems-update-1.8.4
Updating RubyGems to 1.8.4
Installing RubyGems 1.8.4
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems/commands/update_command.rb:153: warning: Insecure world writable dir /usr/local/share in PATH, mode 040777
RubyGems 1.8.4 installed

=== 1.8.4 / 2011-05-25

* 1 minor enhancement:

* Removed default_executable deprecations from Specification.


------------------------------------------------------------------------------

RubyGems installed the following executables:
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/gem

次にcapistranoがインストールされていないことを確認する。
$gem list capistrano

*** LOCAL GEMS ***

上記の場合はインストールされていない。
続けてインストールコマンドを実行する。
$sudo gem install capistrano
Password:
Fetching: highline-1.6.2.gem (100%)
Fetching: net-ssh-2.1.4.gem (100%)
Fetching: net-sftp-2.0.5.gem (100%)
Fetching: net-scp-1.0.4.gem (100%)
Fetching: net-ssh-gateway-1.1.0.gem (100%)
Fetching: capistrano-2.6.0.gem (100%)
Successfully installed highline-1.6.2
Successfully installed net-ssh-2.1.4
Successfully installed net-sftp-2.0.5
Successfully installed net-scp-1.0.4
Successfully installed net-ssh-gateway-1.1.0
Successfully installed capistrano-2.6.0
6 gems installed
Installing ri documentation for highline-1.6.2...
Installing ri documentation for net-ssh-2.1.4...
Installing ri documentation for net-sftp-2.0.5...
Installing ri documentation for net-scp-1.0.4...
Installing ri documentation for net-ssh-gateway-1.1.0...
Installing ri documentation for capistrano-2.6.0...
Installing RDoc documentation for highline-1.6.2...
Installing RDoc documentation for net-ssh-2.1.4...
Installing RDoc documentation for net-sftp-2.0.5...
Installing RDoc documentation for net-scp-1.0.4...
Installing RDoc documentation for net-ssh-gateway-1.1.0...
Installing RDoc documentation for capistrano-2.6.0...

capistranoのバージョンを確認する。
以下のようにバージョンが表示されれば正常にインストールされている。
$cap --version
Capistrano v2.6.0

次にsshの準備を行う。
すでに作成済みの公開鍵をデプロイ対象のサーバにアップロードする。
※未作成の場合は$ssh-keygenを実行し鍵を作成する。

今回はVM上に構築したCentOS環境にアップロードします。
$scp -p .ssh/id_rsa.pub radengineer@192.168.251.131:~
radengineer@192.168.251.131's password:
id_rsa.pub 100% 410 0.4KB/s 00:00

公開鍵を配置
$ mkdir -m 700 .ssh
$ cat id_rsa.pub >> .ssh/authorized_keys

また、デプロイ用に共有アカウントを用意します。
$ sudo /usr/sbin/useradd -m app
$ sudo -u app mkdir -m 700 /home/app/.ssh
$ sudo -u app touch /home/app/.ssh/authorized_keys
$ sudo sh -c "cat id_rsa.pub >> /home/app/.ssh/authorized_keys"

リモートログイン時のパスフェイズ入力を省略する為の設定を行う。
$ ssh-agent bash
$ ssh-add
Enter passphrase for /Users/Radengineer/.ssh/id_rsa:
Identity added: /Users/Radengineer/.ssh/id_rsa (/Users/Radengineer/.ssh/id_rsa)

公開鍵で本番サーバにログインする。
$ ssh 192.168.251.131
$ ssh app@192.168.251.131
パスワードなしでログインできれば設定完了。


以上です。