2010年12月9日木曜日

SELinux無効化

■OSインストール後にSELinuxを無効にする
/etc/selinux/configをvi等で編集し SELINUX=disabled とした後rebootする。

[root@tanyao ~]# cat /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#       enforcing - SELinux security policy is enforced.
#       permissive - SELinux prints warnings instead of enforcing.
#       disabled - SELinux is fully disabled.
SELINUX=disabled
# SELINUXTYPE= type of policy in use. Possible values are:
#       targeted - Only targeted network daemons are protected.
#       strict - Full SELinux protection.
SELINUXTYPE=targeted
[root@tanyao ~]# 

[root@tanyao ~]# reboot

※ SELINUX=permissive の状態でidコマンドを実行すると下記のように表示される。
[root@tanyao ~]# id
uid=0(root) gid=0(root) 所属グループ=0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel) context=root:system_r:unconfined_t:SystemLow-SystemHigh


■SELinuxの動作モード確認と切り替え方法
----------------------------------------------------
Enforcing:許可されていないアクセスを拒否する
Permissive:許可されていないアクセスがあった場合でもログを出力するだけで実際にはアクセス制御を行わない
Disabled:SELinux無効
----------------------------------------------------
[root@tanyao ~]# setenforce 0
[root@tanyao ~]# getenforce
Permissive
[root@tanyao ~]# setenforce 1
[root@tanyao ~]# getenforce
Enforcing

※ /etc/selinux/config で SELINUX=permissive または SELINUX=enforcing となっている場合。
※ 上記コマンドは一時的な設定でありrebootすると/etc/selinux/configの設定に戻る。

⇒ /etc/selinux/config が SELINUX=disabled に設定されている場合で上記コマンドを実行すると下記のようになる。
[root@tanyao ~]# getenforce
Disabled
[root@tanyao ~]# setenforce 0
setenforce: SELinux is disabled
[root@tanyao ~]# setenforce 1
setenforce: SELinux is disabled

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"