Archive for the 'linux' Category

Linux:rsyncでファイル同期

まずrsyncコマンドの基本

rsync [option] [同期元ファイルパス] [同期先ファイルパス]

リモートサーバと同期するときはファイルパスの前に:で区切ってサーバ名またはIPアドレスを指定する
rsync [option] user@192.168.0.2:/tmp /tmp
※この例ではuserアカウントで192.168.0.2にアクセスしようとしているので、目的のサーバに接続した後、パスワードを聞かれる。
パスワードを答えると同期が行われる。

cron等で定期的に同期したい場合、このパスワード入力が面倒。
リモートのrsyncサーバにユーザを登録していれば--password-fileというオプションをつけてコマンドラインにパスワードを含めることができる。

rsyncサーバの設定

rsyncの設定ファイルを作成しする。
設定ファイルにはリモートでアクセスできる接続元や、ディレクトリ、ユーザの設定を書く。
/etc/rsync.conf
#
# Global options
#
uid = root
gid = root
use chroot = yes
log file = /var/log/rsyncd.log
pid file = /var/run/rsyncd.pid
hosts allow = 192.168.0.1/24
hosts deny = *
dont compress = *.gz *.tgz *.zip *.pdf *.sit *.sitx *.lzh *.bz2 *.jpg *.gif *.png

#
# Module options
#
[remote1]
comment = rsync server
path = /tmp/remote1
auth users = remote_user1
secrets file = /etc/rsyncd.secrets
read only = no

[remote2]
comment = rsync server
path = /tmp/remote2
auth users = remote_user2
secrets file = /etc/rsyncd.secrets
read only = no

次にユーザのパスワードを設定する。
※ここで作成するユーザ(上記のrsync.confのremote_user1,remote_user2にあたる)はrsyncのユーザである。
Linuxに同じユーザを作成する必要は無い。

rsync.confで”secrets file”に指定したファイルを編集する。
/etc/rsync.secrets
remote_user1:password
remore_user2:password

※secrets fileのパーミッションは600にすること。それ以外のパーミッションでは認証できない。

以上でrsyncサーバの設定は終わり。サーバを起動するには
rsync --daemon --config=/etc/rsyncd.conf

rsyncユーザで接続

rsyncサーバに設定したユーザ、ディレクトリで同期できるかのテストは以下のようなコマンドで行う。
rsync -r /tmp/test remote_user1@192.168.0.2::remote1

パスワードを聞かれないようにするにはパスワードファイルを作成し、コマンドオプションでそのパスワードファイルを指定する。
rsync -r --password-file=/etc/rsync.passwd /tmp/test remote_user1@192.168.0.2::remote1
/etc/rsync.passwdにはパスワードを平文で書いてよい。但し、他のユーザにアクセスされない場所に置くこと。
またこのファイルもパーミッション600でなければ認証できないので注意

linux:GUIのvimをソースからインストール

vim7.2が使いたいのでソースからインストールした。

cd ~/local/src
wget ftp://ftp.vim.org/pub/vim/unix/vim-7.2.tar.bz2
wget ftp://ftp.vim.org/pub/vim/extra/vim-7.2-http://blog.mktime.com/wp-admin/post-new.phpextra.tar.gz
wget ftp://ftp.vim.org/pub/vim/extra/vim-7.2-lang.tar.gz
tar jxfv vim-7.2.tar.bz2
tar jxzv vim-7.2-extra.tar.gz
tar jxzv vim-7.2-lang.tar.gz
cd vim72/
mkdir patch
cd patch
wget ftp://ftp.vim.org/pub/vim/patches/7.2/7.2.*
cd ..
cat patch/7.2.* | patch -p0
GUIで使いたいので、GUIを有効にするconfigureオプションを指定する。
./configure \
--enable-multibyte \
--enable-xim \
--with-x \
--with-features=big \
--enable-perlinterp \
--enable-pythoninterp \
--enable-rubyinterp \
--enable-gui=gnome2

make

makeでエラーが出る。

os_unix.c:2641: error: ‘security_context_t’ undeclared (first use in this function)


selinux要るの?
yum install libselinux-devel

これでmake ,makeinstallまでいけたけど、vim -g で起動したらエラーが。

E25: GUIは使用不可能です: コンパイル時に無効にされています


configureログを確認すると確かに無効になっている。
checking --enable-gui argument“ GNOME 2.x GUI support
checking whether or not to look for GTK“ yes
checking --with-gtk-prefix argument“ no
checking --with-gtk-exec-prefix argument“ no
checking --disable-gtktest argument“ gtk test enabled
checking for gtk-config“ (cached) no
checking for gtk12-config“ (cached) no
checking for pkg-config“ (cached) /usr/bin/pkg-config
checking for GTKxn--version >= 2.2.0“ no
checking for GTKxn--version >= 1.1.16“ no
checking for X11/SM/SMlib.h“ (cached) yes
checking for X11/xpm.h“ (cached) yes
checking for X11/Sunkeysym.h“ (cached) yes
checking for XIMText in X11/Xlib.h“ yes
no GUI selected; xim has been disabled

gtk2が必要か。

sudo yum install gtk2-devel

gtk2をインストールしたあと、もう一度
./configure \
--enable-multibyte \
--enable-xim \
--enable-x \
--with-features=big \
--enable-perlinterp \
--enable-pythoninterp \
--enable-rubyinterp \
--enable-gui=gnome2

make
sudo make install

よし。完璧です。

linux:cronでcommand not found

cronで「/bin/sh: 行数: ユーザ名 command not found」というエラーが出たら、*が多いか、ユーザ別cronでユーザ名を書いてしまっている。

1つコマンドがずれているために起こるエラーである。

あとcronでありがちな失敗としてはcrondを再起動していない

# crondを再起動
/etc/init.d/crond restart

エラーメールが飛んできているのに気が付かない、などがある。
su [cronを実行するユーザ]
#メール確認
mailx

linux:crontabのヘッダー

いつもcronの時間設定の書き方を忘れるので、コメントヘッダーを付けることにした。
これで5分おき、1時間おきの設定も迷わないはず。

#minute hour  mday month   wday who  command
#
*/5     *   *    *    *    user    /home/user/script.sh

CentOS:日本語platexをインストール

CentOSに日本語latexをインストールするのにかなり苦しんだのでメモ
こちらを参考にさせていただいた。
http://a1667203.blog.shinobi.jp/Entry/89/

/usr/local/srcにplatex3のソースを置き、ソースを展開する。
展開するのはptetex3-20080616.tar.gzだけでよい。他のものはmakeで自動的に解凍される。

mkdir /usr/local/src/platex3
cd /usr/loca/src/platex3
wget http://tutimura.ath.cx/~nob/tex/ptetex/ptetex3/ptetex3-20080616.tar.gz
wget http://www.ring.gr.jp/pub/text/CTAN/systems/unix/teTeX/3.0/distrib/tetex-src-3.0.tar.gz
wget http://www.ring.gr.jp/pub/text/CTAN/systems/unix/teTeX/3.0/distrib/tetex-texmf-3.0po.tar.gz
tar zxf ptetex3-20080616.tar.gz
cd ptetex3-20080616

my_optionをサンプルからコピー。

cp my_option.sample ../my_option

このあとは
make
su
make install
で完了のはずだが、私の環境ではいろいろ足りなかったのでyumでインストール
yum install gcc 
yum install gcc-c++
yum install bison

でもまだ完全にはmakeできない。こんなメッセージが出る
We are NOT going to compile xdvi.  We have two choices.
1. (with xdvi)    Check if we have X11 headers.
2. (without xdvi) Set XDVI=echo in "my_option" to omit xdvi test.
もちろんxdviも使いたい。X11 headersとは何だろう。
yum install xorg-X11-devel
としてみても解決しない。
仕方ないのでGNOMEから
アプリケーション>ソフトウェアの追加・削除
で、「開発」の「Xソフトウェア開発」にチェックを入れてインストール。

yum.logをみるとこれだけインストールされていた。
どれがどれか解らない・・・。
Apr 25 10:44:03 Installed: fontconfig-devel-2.4.1-7.el5.i386
Apr 25 10:44:05 Installed: libjpeg-devel-6b-37.i386
Apr 25 10:44:05 Installed: 2:libpng-devel-1.2.10-7.1.el5_3.2.i386
Apr 25 10:44:06 Installed: libXau-devel-1.0.1-3.1.i386
Apr 25 10:44:06 Installed: libfontenc-devel-1.0.2-2.2.el5.i386
Apr 25 10:44:12 Installed: alsa-lib-devel-1.0.17-1.el5.i386
Apr 25 10:44:13 Installed: xorg-x11-util-macros-1.0.2-4.fc6.i386
Apr 25 10:44:13 Installed: libmng-devel-1.0.9-5.1.i386
Apr 25 10:44:14 Installed: xorg-x11-xtrans-devel-1.0.1-1.1.fc6.i386
Apr 25 10:44:15 Installed: netpbm-devel-10.35-6.1.el5_3.1.i386
Apr 25 10:44:18 Installed: libtiff-devel-3.8.2-7.el5_2.2.i386
Apr 25 10:44:19 Installed: libdrm-devel-2.0.2-1.1.i386
Apr 25 10:44:34 Installed: libXcomposite-0.3-5.1.i386
Apr 25 10:44:37 Installed: libXvMC-1.0.2-2.1.i386
Apr 25 10:44:38 Installed: xrestop-0.2-6.2.2.i386
Apr 25 10:44:42 Installed: xorg-x11-proto-devel-7.1-9.el5.centos.i386
Apr 25 10:44:51 Installed: libX11-devel-1.0.3-9.el5.i386
Apr 25 10:44:52 Installed: libXext-devel-1.0.1-2.1.i386
Apr 25 10:44:56 Installed: mesa-libGL-devel-6.5.1-7.7.el5.i386
Apr 25 10:44:57 Installed: libXrender-devel-0.9.1-3.1.i386
Apr 25 10:44:57 Installed: libXfixes-devel-4.0.1-2.1.i386
Apr 25 10:44:59 Installed: mesa-libGLU-devel-6.5.1-7.7.el5.i386
Apr 25 10:44:59 Installed: libXv-devel-1.0.1-4.1.i386
Apr 25 10:45:00 Installed: libXrandr-devel-1.1.1-3.1.i386
Apr 25 10:45:01 Installed: libICE-devel-1.0.1-2.1.i386
Apr 25 10:45:01 Installed: libSM-devel-1.0.1-3.1.i386
Apr 25 10:45:02 Installed: libXdmcp-devel-1.0.1-2.1.i386
Apr 25 10:45:02 Installed: libXvMC-devel-1.0.2-2.1.i386
Apr 25 10:45:02 Installed: libXcomposite-devel-0.3-5.1.i386
Apr 25 10:45:03 Installed: libXdamage-devel-1.0.3-2.1.i386
Apr 25 10:45:04 Installed: libXft-devel-2.1.10-1.1.i386
Apr 25 10:45:04 Installed: libXevie-devel-1.0.1-3.1.i386
Apr 25 10:45:04 Installed: libXScrnSaver-devel-1.1.0-3.1.i386
Apr 25 10:45:05 Installed: libXxf86misc-devel-1.0.1-3.1.i386
Apr 25 10:45:05 Installed: libXtst-devel-1.0.1-3.1.i386
Apr 25 10:45:05 Installed: libXTrap-devel-1.0.0-3.1.i386
Apr 25 10:45:06 Installed: libXres-devel-1.0.1-3.1.i386
Apr 25 10:45:07 Installed: libXxf86vm-devel-1.0.1-3.1.i386
Apr 25 10:45:07 Installed: libXfontcache-devel-1.0.2-3.1.i386
Apr 25 10:45:07 Installed: libXxf86dga-devel-1.0.1-3.1.i386
Apr 25 10:45:07 Installed: libXcursor-devel-1.1.7-1.1.i386
Apr 25 10:45:08 Installed: libXfont-devel-1.2.2-1.0.3.el5_1.i386
Apr 25 10:45:11 Installed: libXt-devel-1.0.2-3.1.fc6.i386
Apr 25 10:45:11 Installed: libXpm-devel-3.5.5-3.i386
Apr 25 10:45:12 Installed: libXmu-devel-1.0.2-5.i386
Apr 25 10:45:13 Installed: Xaw3d-devel-1.5E-10.1.i386
Apr 25 10:45:14 Installed: gd-devel-2.0.33-9.4.el5_1.1.i386
Apr 25 10:45:17 Installed: SDL-devel-1.2.10-8.el5.i386
Apr 25 10:45:18 Installed: libXaw-devel-1.0.2-8.1.i386

けど、とりあえずmakeできたのでmake install
・・・
finished!
テストします。
PATH=/usr/local/teTex/bin:$PATH; export PATH
vi test.tex    # viでtexドキュメントを書く
platex -kanji=utf8 test.tex
This is pTeX, Version 3.141592-p3.1.10 (utf8.euc) (Web2C 7.5.4)
(./test.tex
pLaTeX2e <2006/11/10>+0 (based on LaTeX2e <2003/12/01> patch level 0)
(/usr/local/teTeX/share/texmf/ptex/platex/base/jarticle.cls
Document Class: jarticle 2006/06/27 v1.6 Standard pLaTeX class
(/usr/local/teTeX/share/texmf/ptex/platex/base/jsize10.clo)) (./test.aux)
[1] (./test.aux) )
Output written on test.dvi (1 page, 300 bytes).
test.log、test.dvi、test.auxというファイルができた。
とりあえずOKかな。
dviをビューワで見る
pxdvi test.dvi
Warning: Missing charsets in String to FontSet conversion
Warning: Missing charsets in String to FontSet conversion
ウォーニングが出るけど、日本語表示はできている。
最後にPDFにするテスト
/usr/local/teTeX/bin/dvipdfmx test.dvi
完璧です。

最後にパスとオプションの設定を.bashrcに残しておく。
$HOME/.bashrc
PATH=$PATH:/usr/local/teTeX/bin
alias platex="platex -kanji=utf8"

CentOS:日本語入力できるようにする

yumのリポジトリを作成し、キーを登録する。

cd /etc/yum.repos.d
wget http://centos.karan.org/kbsingh-CentOS-Extras.repo
wget http://centos.karan.org/kbsingh-CentOS-Misc.repo
rpm --import http://centos.karan.org/RPM-GPG-KEY-karan.org.txt


yumでSCIM と Anthyをインストール
yum install anthy scim scim-anthy

システム設定入力メソッドを Anthy + SCIM へ切替える。
/usr/sbin/alternatives --config xinput-ja_JP

ここでサーバを再起動。
reboot

※今使っているVMwareイメージではブート状況の表示で日本語が四角くつぶれる。
ブートが進むと日本語表示されるようになるので気にしないことにする。

再起動してログインするとCtrl-Space(または半角/全角キー)でローマ字入力できるようになる。

※できない場合は入力メソッドでシステム設定に従う[SCIM]が選択されているか確認する。
システム>設定>他の個人設定>入力メソッド

Linux:ssh公開鍵認証

ローカルサーバ(接続元)からリモートサーバ(接続先)にパスワード無しでログインする設定。
以下ローカルサーバのfooユーザがリモートサーバにbarユーザでログインする場合。

ローカルサーバ(接続元)で認証キーを作る

# ssh-keygen -t rsa -N “” -f /home/foo/.ssh/authkey_bar
rsync.pub (公開鍵)をリモートサーバ(接続先)の/bar/.sshにコピーするローカルサーバからSCPで転送
# scp authkey_bar.pub bar@リモートサーバ:/tmp
この時点ではまだパスワードを聞かれるので入力する。

リモートサーバにbarでログインして/home/bar/.sshに移動し、パーミッション変更&authorized_keysに追記

authorized_keysのパーミッションは必ず600でなくてはいけない。644ではパスワードを聞かれます。
# chmod 700 /home/bar/.ssh
# mv /tmp/rsync.pub /home/bar/.ssh
# cat /home/bar/.ssh/authkey_bar.pub >> /root/.ssh/authorized_keys
# chmod 600 /home/bar/.ssh/authorized_keys
# rm /home/bar/.ssh/authkey_bar.pub

Linux:ソースからインストール&パッケージ作成

checkinstallなるものでソースからインストールしつつパッケージを作成できるらしいので試してみた。

まずはcheckinstallをインストールする。

wget http://asic-linux.com.mx/~izto/checkinstall/files/rpm/checkinstall-1.6.1-1.i386.rpm
rpm -ihv checkinstall-1.6.1

どこに入ったかわからなくなったので・・・^^;
rpm -ql checkinstall

どうやら/usr/local/sbin/checkinstall

-h でヘルプ表示
/usr/local/sbin/checkinstall -h

checkinstall 1.6.1, Copyright 2002 Felipe Eduardo Sanchez Diaz Duran
This software is released under the GNU GPL.

Usage: checkinstall [options] [command [command arguments]]
Options:
*Package type selection*
-t,--type= Choose packaging system
-S Build a Slackware package
-R Build a RPM package
-D Build a Debian package
*Install options*
--install= Toggle created package installation
--fstrans= Enable/disable the filesystem translation code
*Scripting options*
-y, --default Accept default answers to all questions
--pkgname= Set name
--pkgversion= Set version
-A, --arch, --pkgarch= Set architecture
--pkgrelease= Set release
--pkglicense= Set license
--pkggroup= Set software group
--pkgsource= Set source location
--pkgaltsource= Set alternate source location
--pakdir= The new package will be saved here
--maintainer= The package maintainer (.deb)
--provides= Features provided by this package (.rpm)
--requires= Features required by this package
--rpmflags= Pass this flags to the rpm installer
--rpmi Use the -i flag for rpm when installing a .rpm
--rpmu Use the -U flag for rpm when installing a .rpm
--dpkgflags= Pass this flags to the dpkg installer
--spec= .spec file location
--nodoc Do not include documentation files

*Info display options*

-d<0|1|2> Set debug level
-si Run an interactive install command
--showinstall= Toggle interactive install command
-ss Run an interactive Slackware installation script
--showslack= Toggle interactive Slackware installation script

*Package tuning options*

--autodoinst= Toggle the creation of a doinst.sh script
--strip= Strip any ELF binaries found inside the package
--stripso= Strip any ELF binary libraries (.so files)
--addso= Search for any shared libs and add
them to /etc/ld.so.conf
--reset-uids= Reset perms for all files/dirs to 755 and
the owner/group for all dirs to root.root
--gzman= Compress any man pages found inside the package
--docdir= Where to put documentation files
--umask= Set the umask value
--exclude= Exclude these files/directories from the package
--include= Force the inclusion in the package of the
files/dirs listed in “listfile”
--inspect Inspect the package” file list
--review-spec Review the spec file before creating a .rpm
--review-control Review the control file before creating a .deb
--newslack Use the new (8.1+) Slackware description format
(“--newslack” implies “-S”)
--with-tar=/path/to/tar Manually set the path to the tar binary
in this system

*Cleanup options*

--deldoc= Delete doc-pak upon termination
--deldesc= Delete description-pak upon termination
--delspec= Delete spec file upon termination
--bk Backup any overwritten files
--backup= Toggle backup

*About CheckInstall*

--help, -h Show this message
--copyright Show Copyright information
--version Show version information

RPMは-Rか。

何かのソースからパッケージを作ってみたい。
今回試すのはsquidにしてみる。

wget http://www.squid-cache.org/Versions/v3/3.0/squid-3.0.STABLE13.tar.gz
tar zxfv squid-3.0.STABLE13.tar.gz
cd squid-3.0.STABLE13
./configure
make
make install
/usr/local/sbin/checkinstall -R

途中の入力は全部パスして進めると、最後にこう表示される。OKか?
**********************************************************************

Done. The new package has been saved to

/usr/src/redhat/RPMS/i386/squid-3.0.STABLE13-1.i386.rpm
You can install it in your system anytime using:

rpm -i squid-3.0.STABLE13-1.i386.rpm

**********************************************************************

とりあえず/usr/src/redhat/RPMS/i386/にrpmができているのは確認した。
しかし、このパッケージからインストールしようとするとgrepの競合というエラーが出る。
ソースからすでにインストールしたからかな?

linux:サーバのアーキテクチャを調べるには

パッケージをインストールするとき、どのアーキテクチャを選択すればよいかわからない時はuname -a

# uname -a
Linux localhost.localdomain 2.6.9-023stab046.2-smp #1 SMP Mon Dec 10 15:04:55 MSK 2007 x86_64 x86_64 x86_64 GNU/Linux

後ろのほうのx86_64がそのサーバのアーキテクチャ。
他にi386やi686などがある。
noarchは全アーキテクチャ共通のパッケージ

VirtualHost環境にMTOSをインストール

cgi-script のハンドラを有効にします。ついでに.plでもCGIが動くようにします。

/etc/httpd/conf/httpd.conf
#AddHandler cgi-script .cgi
AddHandler cgi-script .cgi .pl

VirtualHostを定義。
スクリプトは非公開領域で動くようにScriptAliasを設定する。
/etc/httpd/conf.d/vhosts.conf
<VirtualHost *:80>>
    DocumentRoot "/path/to/public_html"
    ScriptAlias /cgi-bin/ "/path/to/cgi/"
    ServerName example.com
    ErrorLog "logs/example.com-access.log"
    CustomLog "logs/example.com-error.log" common
</VirtualHost>

“/path/to/cgi”にソースを解答し、/cgi-bin/mt-check.cgiにアクセスして必要なライブラリを確認する。
yumまたはcpanで必要なライブラリを入れる。
yum install perl-GD
cpan> install DBI
cpan> install DBD::mysql
#…以下必要なだけインストール
cgiファイルの権限を変更し実行可能にする。
chmod 755 *.cgi

/cgi-bin/mt.cgiにアクセス。あとはウィザードに従ってインストール。

« 前ページへ次ページへ »