2010年11月13日土曜日

コマンドプロンプトでFTP

■FTPサーバ(Linux)に接続
c:\Temp>ftp 192.168.1.12
192.168.1.12 に接続しました。
220 (vsFTPd 2.0.5)
ユーザー (192.168.1.12:(none)): public
331 Please specify the password.
パスワード:
230 Login successful.

■対象ディレクトリに移動
ftp> cd /tmp/ftp
250 Directory successfully changed.
ftp> ls
200 PORT command successful. Consider using PASV.
150 Here comes the directory listing.
sample_data
226 Directory send OK.
ftp: 13 バイトが受信されました 0.00秒 13.00KB/秒。

■PCのディレクトリ移動
ftp> lcd put_data
ローカル ディレクトリは現在 c:\Temp\put_data です。

■バイナリーモードに変更
ftp> bin
200 Switching to Binary mode.

■確認時自動的にyesを選択させる
ftp> prompt
対話モード オフ。

■複数ファイルをアップロード
ftp> mput *
200 PORT command successful. Consider using PASV.
150 Ok to send data.
226 File receive OK.
ftp: 169506 バイトが送信されました 0.01秒 33901.20KB/秒。
200 PORT command successful. Consider using PASV.
150 Ok to send data.
226 File receive OK.
ftp: 183785 バイトが送信されました 0.01秒 36757.00KB/秒。
200 PORT command successful. Consider using PASV.
150 Ok to send data.
226 File receive OK.
ftp: 160099 バイトが送信されました 0.01秒 17788.78KB/秒。

■ファイルリストを表示
ftp> ls
200 PORT command successful. Consider using PASV.
150 Here comes the directory listing.
P1000713.JPG
P1000787.JPG
P1000952.JPG
sample_data
226 Directory send OK.
ftp: 55 バイトが受信されました 0.00秒 55.00KB/秒。

■サーバのディレクトリ移動
ftp> lcd ../get_data
ローカル ディレクトリは現在 c:\Temp\get_data です。

■サーバよりディレクトリごとダウンロード
ftp> mget sample_data
200 Switching to Binary mode.
200 PORT command successful. Consider using PASV.
150 Opening BINARY mode data connection for sample_data/005.jpg (84702 bytes).
226 File send OK.
ftp: 84702 バイトが受信されました 0.01秒 8470.20KB/秒。
(中略)
200 PORT command successful. Consider using PASV.
150 Opening BINARY mode data connection for sample_data/029.jpg (83463 bytes).
226 File send OK.
ftp: 83463 バイトが受信されました 0.01秒 11923.29KB/秒。

■切断
ftp> bye
221 Goodbye.

c:\Temp>

2010年11月12日金曜日

LinuxのシェルスクリプトでFTPする方法


LinuxのコマンドでFTPすることはもちろん可能ですが、
細かい内容はすぐ忘れてしまうのでシェルスクリプトにまとめてみました。

OS: CetnOS 5.7


■FTP用シェルスクリプトサンプル

#!/bin/sh

LOG="./log_ftp.log"
TARGET_HOST="192.168.216.232"
TARGET_USER="root"
TARGET_PASS="password"
TARGET_DIR="/tmp"
PUTDATA="putdata.txt"
GETDATA="getdata.txt"

uptime > $LOG

ftp -i -v -n $TARGET_HOST << END >> $LOG
user $TARGET_USER $TARGET_PASS
cd $TARGET_DIR
bin
# put $PUTDATA
# get $GETDATA
quit
END

uptime >> $LOG

exit 0

この情報が何かのお役にたてれば幸いです。m(_ _)m

2010年7月4日日曜日

PHP5.2.9 インストールメモ

■PHPインストール先のディレクトリ作成
[root@tanyao-web02 ~]# mkdir /opt/php5


■libiconvのインストール(文字コード対応に必要っぽい。)
http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.13.1.tar.gz からモジュールをダウンロード
[root@tanyao-web02 library_20100129]# tar -zxf libiconv-1.13.1.tar.gz
[root@tanyao-web02 library_20100129]# cd libiconv-1.13.1
[root@tanyao-web02 libiconv-1.13.1]# ./configure --prefix=/opt/php5/local
[root@tanyao-web02 libiconv-1.13.1]# make
[root@tanyao-web02 libiconv-1.13.1]# make install


■libmcryptのインストール
http://sourceforge.net/projects/mcrypt/ にてlibmcrypt-2.5.8.tar.gzをダウンロード
[root@tanyao-web02 library_20100129]# tar -zxf libmcrypt-2.5.8.tar.gz
[root@tanyao-web02 library_20100129]# cd libmcrypt-2.5.8
[root@tanyao-web02 libmcrypt-2.5.8]# ./configure --prefix=/opt/php5/mcrypt
[root@tanyao-web02 libmcrypt-2.5.8]# make
[root@tanyao-web02 libmcrypt-2.5.8]# make install


■php5本体のインストール
[root@tanyao-web02 ~]# cd /home/operation/src/php5/
[root@tanyao-web02 php5]# tar -zxf php-5.2.9.tar.gz
[root@tanyao-web02 php5]# cd php-5.2.9
[root@tanyao-web02 php-5.2.9]# ./configure \
> --prefix=/opt/php5 \
> --with-nsapi=/opt/sjsws \
> --with-libxml-dir=/usr/lib \
> --with-cdb \
> --with-gd \
> --with-jpeg-dir=/usr/lib \
> --with-png-dir=/usr/lib \
> --with-zlib \
> --with-freetype-dir=/usr/lib \
> --with-mcrypt=/opt/php5/mcrypt \
> --with-pear=/opt/php5/lib/php \
> --without-mysql \
> --enable-libgcc \
> --enable-mbstring \
> --enable-mbregex \
> --enable-zend-multibyte \
> --enable-sigchild \
> --disable-pdo

最後に下記が表示される
+--------------------------------------------------------------------+
License:
This software is subject to the PHP License, available in this
distribution in the file LICENSE. By continuing this installation
process, you are bound by the terms of this license agreement.
If you do not agree with the terms of this license, you must abort
the installation process at this point.
+--------------------------------------------------------------------+

Thank you for using PHP.

[root@tanyao-web02 php-5.2.9]# make ←5分くらいはかかる
[root@tanyao-web02 php-5.2.9]# make install
Installing PHP SAPI module: nsapi
Installing PHP CLI binary: /opt/php5/bin/
Installing PHP CLI man page: /opt/php5/man/man1/
Installing build environment: /opt/php5/lib/php/build/
Installing header files: /opt/php5/include/php/
Installing helper programs: /opt/php5/bin/
program: phpize
program: php-config
Installing man pages: /opt/php5/man/man1/
page: phpize.1
page: php-config.1
Installing PEAR environment: /opt/php5/lib/php/
[PEAR] Console_Getopt - installed: 1.2.3
[PEAR] Archive_Tar - installed: 1.3.2
[PEAR] Structures_Graph- installed: 1.0.2
pear/PEAR can optionally use package "pear/XML_RPC" (version >= 1.4.0)
[PEAR] PEAR - installed: 1.7.2
Wrote PEAR system config file at: /opt/php5/etc/pear.conf
You may want to add: /opt/php5/lib/php to your php.ini include_path


--- SunJavaWebServerのconfigファイル群の編集 ---
[root@tanyao-web02 ~]# cd /opt/sjsws/https-tanyao-web02.tanyao.net/config

■mime.types
[root@tanyao-web02 config]# cp mime.types mime.types.20100130
[root@tanyao-web02 config]# vi mime.types
→145行目あたりに追加
type=magnus-internal/x-httpd-php exts=php


■magnus.conf
[root@tanyao-web02 config]# cp magnus.conf magnus.conf.20100130
[root@tanyao-web02 config]# vi magnus.conf

→17行目と18行目の間あたりに下記2行を追加 ★これを有効化するとWebサーバが起動エラー!!!
Init fn="load-modules" funcs="php5_init,php4_execute,php5_auth_trans" shlib="/opt/sjsws/bin/libphp5.so"
Init fn="php5_init" LateInit="yes" errorString="Failed to initialize PHP!"

■obj.conf
[root@tanyao-web02 config]# cp obj.conf obj.conf.20100130
[root@tanyao-web02 config]# vi obj.conf
---
Service method="TRACE" fn="service-trace"
Service fn="php5_execute" type="magnus-internal/x-httpd-php" ←追加
Error fn="error-j2ee"

2009年4月1日水曜日

SSHを利用したrsync検証

20090401
10.47.216.180(Cent-web)の /opt/iw 領域をrsyncで /opt/iw にレプリケーション
10.47.216.180(Cent-web)の /nfs/apps と /nfs/export をcentos01のローカルストレージの/apps /exportでマウント
centos01でTSとODが起動するかどうか検証

→結果×
iwtsユーザや、/usr/bin/iwgethome等が存在しないため


■マウントポイント作成
[root@centos01 ~]# mkdir /opt/iw
[root@centos01 ~]# mkdir /apps
[root@centos01 ~]# mkdir /export


■スタンバイサーバで公開鍵を生成
[root@centos01 ~]# ssh-keygen -t dsa
Generating public/private dsa key pair.
Enter file in which to save the key (/root/.ssh/id_dsa):
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_dsa.
Your public key has been saved in /root/.ssh/id_dsa.pub.
The key fingerprint is:
cc:61:cc:68:71:02:8f:53:d7:7f:9f:c2:6a:2a:d7:0b root@centos01.tanyao.net ←FQDNはIPアドレスに変更してもOK


■生成した公開鍵をマスタサーバへコピー。
[root@centos01 ~]# scp /root/.ssh/id_dsa.pub 10.47.216.180:/tmp/


■マスタサーバにて/tmp/id_dsa.pubファイルをauthorized_keysに追記
[root@Cent-web ~]# cat /tmp/id_dsa.pub >> /root/.ssh/authorized_keys


■バックアップサーバにてスクリプト作成
[root@centos01 ~]# cat rsync.sh
#!/bin/sh

# レプリケート対象ホスト名(またはIPアドレス)
TARGET_HOST=10.47.216.180
# レプリケート対象ディレクトリ
TARGET_DIRECTORY=/nfs/iw/
# 保存先ディレクトリ
LOCAL_DIRECTORY=/opt/iw/
# ログ出力先
LOG=./rsync.log

echo "#`date \"+%Y-%m-%d %H:%M:%S\"` rsync start" >> $LOG
rsync -avz -e ssh $TARGET_HOST:$TARGET_DIRECTORY --delete $LOCAL_DIRECTORY >> $LOG
echo "#`date \"+%Y-%m-%d %H:%M:%S\"` rsync end" >> $LOG
echo "" >> $LOG



★マウント
[root@centos01 ~]# mount -t nfs 10.47.216.180:/nfs/apps /apps
[root@centos01 ~]# mount -t nfs 10.47.216.180:/nfs/export /export

★起動スクリプトのコピー(ここだけコピーしても無駄だった)
[root@centos01 ~]# scp root@10.47.216.195:/etc/init.d/iw* /etc/init.d/

2009年3月26日木曜日

ディスク追加手順

20090326
■現状確認
[root@Cent-web ~]# df -m
Filesystem 1M-ブロック 使用 使用可 使用% マウント位置
/dev/sda4 5946 2708 2936 48% /
/dev/sda1 99 12 82 13% /boot
none 252 0 252 0% /dev/shm
/dev/sda3 2016 132 1782 7% /var


■fdisk実行
[root@Cent-web ~]# fdisk /dev/sdb
デバイスは正常な DOS 領域テーブルも、Sun, SGI や OSF ディスクラベルも
含んでいません
新たに DOS ディスクラベルを作成します。あなたが書き込みを決定するまで、変更は
メモリ内だけに残します。その後はもちろん以前の内容は修復不可能になります。

このディスクのシリンダ数は 1566 に設定されています。
間違いではないのですが、1024 を超えているため、以下の場合
に問題を生じうる事を確認しましょう:
1) ブート時に実行するソフトウェア (例. バージョンが古い LILO)
2) 別の OS のブートやパーティション作成ソフト
(例. DOS FDISK, OS/2 FDISK)
警告: 領域テーブル 4 の不正なフラグ 0x0000 は w(書き込み)によって正常になります

コマンド (m でヘルプ): m
コマンドの動作
a ブート可能フラグをつける
b bsd ディスクラベルを編集する
c dos 互換フラグをつける
d 領域を削除する
l 既知の領域タイプをリスト表示する
m このメニューを表示する
n 新たに領域を作成する
o 新たに空の DOS 領域テーブルを作成する
p 領域テーブルを表示する
q 変更を保存せずに終了する
s 空の Sun ディスクラベルを作成する
t 領域のシステム ID を変更する
u 表示/項目ユニットを変更する
v 領域テーブルを照合する
w テーブルをディスクに書き込み、終了する
x 特別な機能 (エキスパート専用)

コマンド (m でヘルプ): p

Disk /dev/sdb: 12.8 GB, 12884901888 bytes
255 heads, 63 sectors/track, 1566 cylinders
Units = シリンダ数 of 16065 * 512 = 8225280 bytes

デバイス Boot Start End Blocks Id System

コマンド (m でヘルプ): n
コマンドアクション
e 拡張
p 基本領域 (1-4)
p
領域番号 (1-4): 1
最初 シリンダ (1-1566, default 1): 1
終点 シリンダ または +サイズ または +サイズM または +サイズK (1-1566, default 1566): 700

コマンド (m でヘルプ): n
コマンドアクション
e 拡張
p 基本領域 (1-4)
p
領域番号 (1-4): 2
最初 シリンダ (701-1566, default 701): 701
終点 シリンダ または +サイズ または +サイズM または +サイズK (701-1566, default 1566): 1100

コマンド (m でヘルプ): n
コマンドアクション
e 拡張
p 基本領域 (1-4)
p
領域番号 (1-4): 3
最初 シリンダ (1101-1566, default 1101): 1101
終点 シリンダ または +サイズ または +サイズM または +サイズK (1101-1566, default 1566): 1566

コマンド (m でヘルプ): p

Disk /dev/sdb: 12.8 GB, 12884901888 bytes
255 heads, 63 sectors/track, 1566 cylinders
Units = シリンダ数 of 16065 * 512 = 8225280 bytes

デバイス Boot Start End Blocks Id System
/dev/sdb1 1 700 5622718+ 83 Linux
/dev/sdb2 701 1100 3213000 83 Linux
/dev/sdb3 1101 1566 3743145 83 Linux

コマンド (m でヘルプ): w
領域テーブルは交換されました!

ioctl() を呼び出して領域テーブルを再読込みします。
ディスクを同期させます。


■ext3でフォーマット
[root@Cent-web ~]# mke2fs -j /dev/sdb1
mke2fs 1.35 (28-Feb-2004)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
703136 inodes, 1405679 blocks
70283 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1442840576
43 block groups
32768 blocks per group, 32768 fragments per group
16352 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736

Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 23 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.

■同様にパーティション2,3もフォーマット
[root@Cent-web ~]# mke2fs -j /dev/sdb2
[root@Cent-web ~]# mke2fs -j /dev/sdb3

■ラベルの割当
[root@Cent-web ~]# e2label /dev/sdb1 /iw
[root@Cent-web ~]# e2label /dev/sdb2 /apps
[root@Cent-web ~]# e2label /dev/sdb3 /export

■ファイルシステムチェック
[root@Cent-web ~]# e2fsck /dev/sdb1
e2fsck 1.35 (28-Feb-2004)
/ts: clean, 11/703136 files, 33027/1405679 blocks
[root@Cent-web ~]# e2fsck /dev/sdb2
e2fsck 1.35 (28-Feb-2004)
/apps: clean, 11/402400 files, 22021/803250 blocks
[root@Cent-web ~]# e2fsck /dev/sdb3
e2fsck 1.35 (28-Feb-2004)
/export: clean, 11/468640 files, 24751/935786 blocks

■マウントポイントの作成
[root@Cent-web ~]# mkdir /nfs/iw
[root@Cent-web ~]# mkdir /nfs/apps
[root@Cent-web ~]# mkdir /nfs/export

■/etc/fstabに追記
LABEL=/iw /nfs/iw ext3 defaults 1 2
LABEL=/apps /nfs/apps ext3 defaults 1 2
LABEL=/export /nfs/export ext3 defaults 1 2

■マウント
[root@Cent-web ~]# mount -a
確認
[root@Cent-web ~]# mount grep sdb
/dev/sdb1 on /nfs/iw type ext3 (rw)
/dev/sdb2 on /nfs/apps type ext3 (rw)
/dev/sdb3 on /nfs/export type ext3 (rw)



■公開ディレクトリの設定
[root@Cent-web ~]# vi /etc/exports
/nfs/iw *(rw,sync,no_root_squash)
/nfs/apps *(rw,sync,no_root_squash)
/nfs/export *(rw,sync,no_root_squash)

■NFSサービス起動
[root@Cent-web ~]# /etc/init.d/nfs start
NFS サービスを起動中: [ OK ]
NFS クォータを起動中: [ OK ]
NFS デーモンを起動中: [ OK ]
NFS mountd を起動中: [ OK ]

■NFSサービス起動設定
[root@Cent-web ~]# chkconfig --level 3 nfs on
[root@Cent-web ~]# chkconfig --level 5 nfs on


■NFSクライアントが起動時にマウントする設定
[root@iwts04 iw]# cat /etc/fstab
(下記を追記)
# NFS mount settings
192.168.216.180:/nfs/iw /opt/iw nfs nfsvers=3,rsize=32768,wsize=32768,rw,hard,intr 0 0
192.168.216.180:/nfs/apps /apps nfs nfsvers=3,rsize=32768,wsize=32768,rw,hard,intr 0 0
192.168.216.180:/nfs/export /export nfs defaults 0 0


■手動マウント
mount -t nfs -o nfsvers=3,rsize=32768,wsize=32768,rw,hard,intr 192.168.216.180:/nfs/export /export
mount -t nfs -o nfsvers=3,rsize=32768,wsize=32768,rw,hard,intr 192.168.216.180:/nfs/iw /opt/iw