2011年9月18日日曜日

CentOS5.7バンドルのMySQL

★RubyOnRailsのデータベースとしてMySQLを準備

■OSバンドルのmysqlモジュール確認
[root@rails01 ~]# rpm -qa | grep mysql
libdbi-dbd-mysql-0.8.1a-1.2.2
mysql-5.0.77-4.el5_6.6
mysql-server-5.0.77-4.el5_6.6
mysql-5.0.77-4.el5_6.6
mysql-connector-odbc-3.51.26r1127-1.el5
⇒mysql-develがない!

■mysql-develインストール
[root@rails01 ~]# yum install mysql-devel
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: www.ftp.ne.jp
 * extras: www.ftp.ne.jp
 * updates: www.ftp.ne.jp
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package mysql-devel.i386 0:5.0.77-4.el5_6.6 set to be updated
---> Package mysql-devel.x86_64 0:5.0.77-4.el5_6.6 set to be updated
--> Finished Dependency Resolution

Dependencies Resolved

========================================================================================================================
 Package                       Arch                     Version                            Repository              Size
========================================================================================================================
Installing:
 mysql-devel                   i386                     5.0.77-4.el5_6.6                   base                   2.4 M
 mysql-devel                   x86_64                   5.0.77-4.el5_6.6                   base                   2.5 M

Transaction Summary
========================================================================================================================
Install       2 Package(s)
Upgrade       0 Package(s)

Total download size: 4.9 M
Is this ok [y/N]: y
Downloading Packages:
(1/2): mysql-devel-5.0.77-4.el5_6.6.i386.rpm                                                     | 2.4 MB     00:01
(2/2): mysql-devel-5.0.77-4.el5_6.6.x86_64.rpm                                                   | 2.5 MB     00:00
------------------------------------------------------------------------------------------------------------------------
Total                                                                                   2.1 MB/s | 4.9 MB     00:02
警告: rpmts_HdrFromFdno: ヘッダ V3 DSA signature: NOKEY, key ID e8562897
base/gpgkey                                                                                      | 1.5 kB     00:00
Importing GPG key 0xE8562897 "CentOS-5 Key (CentOS 5 Official Signing Key) " from /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5
Is this ok [y/N]: y
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing     : mysql-devel                                                                                      1/2
  Installing     : mysql-devel                                                                                      2/2

Installed:
  mysql-devel.i386 0:5.0.77-4.el5_6.6                       mysql-devel.x86_64 0:5.0.77-4.el5_6.6

Complete!
[root@rails01 ~]# rpm -qa | grep mysql
libdbi-dbd-mysql-0.8.1a-1.2.2
mysql-5.0.77-4.el5_6.6
mysql-devel-5.0.77-4.el5_6.6
mysql-server-5.0.77-4.el5_6.6
mysql-5.0.77-4.el5_6.6
mysql-connector-odbc-3.51.26r1127-1.el5
mysql-devel-5.0.77-4.el5_6.6


■データベース初期化
[root@rails01 ~]# /etc/init.d/mysqld start
MySQL データベースを初期化中:  Installing MySQL system tables...
OK
Filling help tables...
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h rails01 password 'new-password'

Alternatively you can run:
/usr/bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:
cd /usr ; /usr/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl
cd mysql-test ; perl mysql-test-run.pl

Please report any problems with the /usr/bin/mysqlbug script!

The latest information about MySQL is available on the web at
http://www.mysql.com
Support MySQL by buying support/licenses at http://shop.mysql.com
                                                           [  OK  ]
MySQL を起動中:                                            [  OK  ]

⇒起動確認
[root@rails01 ~]# mysqlshow
+--------------------+
|     Databases      |
+--------------------+
| information_schema |
| mysql              |
| test               |
+--------------------+

⇒停止
[root@rails01 ~]# /etc/init.d/mysqld stop
MySQL を停止中:                                            [  OK  ]

2011年9月17日土曜日

CentOS5.7インストールパッケージ

★RubyOnRails用として仮想サーバをCentOSで構築。
⇒MySQLはOSバンドルを利用予定。
⇒RubyおよびRailsは最新版をインストール予定。

■OSインストール時のパッケージ選択
-----------------------------------------------------------
【デスクトップ環境】
 ■ GNOMEデスクトップ環境
 □ KDE(Kデスクトップ環境)

【アプリケーション】
 □ Emacs
 □ Office/生産性
 ■ エディタ
 ■ グラフィカルインターネット
 ■ グラフィクス
 □ ゲームと娯楽
 ■ サウンドとビデオ
 □ テキストベースのインターネット
 □ 技術系と科学系
 □ 著作権と発行

【開発】
 □ GNOMEソフトウェア開発
 ■ Java開発
 □ KDEソフトウェア開発
 □ Ruby
 □ Xソフトウェア開発
 ■ レガシーなソフトウェアの開発
 ■ 開発ツール
 ■ 開発ライブラリ

【サーバー】
 □ DNSネームサーバー
 ■ FTPサーバー
 ■ MySQLデータベース
 □ PostgreSQLデータベース
 ■ Webサーバー
 ■ Windowsファイルサーバー
 ■ サーバー設定ツール
 □ ニュースサーバー 
 □ ネットワークサーバー
 □ メールサーバー
 □ レガシーなネットワークサーバー
 □ 印刷サポート

【ベースシステム】
 ■ Java
 ■ OpenFabrics Enterprise ディストリビューション
 ■ X Window System
 ■ システムツール
 □ ダイヤルアップネットワークサポート
 ■ ベース
 ■ レガシーなソフトウェアのサポート
 ■ 管理ツール

【仮想化】
 □ KVM
 □ 仮想化

【クラスタリング】
 □ クラスタリング

【クラスタストレージ】
 □ クラスタストレージ

【言語】
 ■ 日本語のサポート

2011年6月28日火曜日

cookie検証

[root@tanyao0b cgi-bin]# cat login.cgi
#!/usr/bin/perl

#フォームからの受け取りをデコードする
&dec;

#クッキーの読み出し
&splt;

#入室用のパスワード
$passw = '0123';

#入力されたパスが正しければ
if ($forminh{'pass'} eq $passw) { &site_form; }

#cookieのパスが正しければ
elsif ($COOKIE{'ckpas'} eq $passw) { &site_cookie; }

# 初期アクセス
print <<"HTML";
Content-type: text/html








統合監視システムへようこそ!
パスワード:
HTML exit; #入力されたパスが正しければ表示するサイトのサブルーチン sub site_form { #クッキーの書き出し print <<"HTML"; Content-type: text/html Set-Cookie: ckpas=$forminh{'pass'}; expires=Tue, 1-Jan-2030 00:00:00 GMT; path=/cgi-bin/; HTML print <<"HTML"; Content-type: text/html site_form 統合監視システムへログイン成功!!
Get from COOKIE: $ENV{'HTTP_COOKIE'}
Get from FORM: $forminh{'pass'}

下記リンクをクリックするとこのページをリロードします。
login.cgi
HTML exit; } #cookieのパスが正しければ表示するサイトのサブルーチン sub site_cookie { print <<"HTML"; Content-type: text/html site_cookie こちらは、統合監視システムです。すでに認証済みです。
Get from COOKIE: $ENV{'HTTP_COOKIE'}
Get from FORM: $forminh{'pass'}

ログアウトはこちら
HTML exit; } #フォームからの値をデコードするサブルーチン sub dec { #フォームからデータを受け取り変数へ入れる read(STDIN, $formin, $ENV{'CONTENT_LENGTH'}); # + 記号を半角スペースに戻す $formin =~ tr/+/ /; #URLエンコードデータをデコード $formin =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; @indata = split (/&/,$formin); #受け取ったデータを&で区切り、配列へ foreach $tmp (@indata) #フォームの要素分(配列分)以下の処理を繰り返す { ($name,$value) = split (/=/,$tmp); # =記号で区切り、名前 と 値 に分ける $forminh{$name} = $value; #区切った名前を付けた連想配列に値を入れる } } #クッキー読み出し用のサブルーチン sub splt { @cookdata = split(/;/,$ENV{'HTTP_COOKIE'}); #クッキーを配列に foreach $tmp (@cookdata) #クッキーデータの有る間処理をする { ($youso,$atai) = split(/=/,$tmp); #要素名と値に区切る $youso =~ s/ //; #要素間のスペース除去 $COOKIE{$youso} = $atai; #要素名の連想配列に値を入れる } } [root@tanyao0b cgi-bin]# cat logout.cgi #!/usr/bin/perl #クッキーの読み出し &splt; #入室用のパスワード $passw = '0123'; #cookieのパスが正しければ if ($COOKIE{'ckpas'} eq $passw) { &site_cookie; } # 初期アクセス print <<"HTML"; Content-type: text/html 認証に失敗している可能性があります。

認証画面はこちら
HTML exit; #cookieのパスが正しければ表示するサイトのサブルーチン sub site_cookie { #クッキーの書き出し print <<"HTML"; Content-type: text/html Set-Cookie: ckpas= ; expires=Tue, 1-Jan-2020 00:00:00 GMT; path=/cgi-bin/; HTML print <<"HTML"; Content-type: text/html site_cookie ログアウトしました。

Get from COOKIE: $ENV{'HTTP_COOKIE'}
Get from FORM: $forminh{'pass'}
Delete Password from Cookie !!

ログイン画面はlogin.cgi
HTML exit; } #クッキー読み出し用のサブルーチン sub splt { @cookdata = split(/;/,$ENV{'HTTP_COOKIE'}); #クッキーを配列に foreach $tmp (@cookdata) #クッキーデータの有る間処理をする { ($youso,$atai) = split(/=/,$tmp); #要素名と値に区切る $youso =~ s/ //; #要素間のスペース除去 $COOKIE{$youso} = $atai; #要素名の連想配列に値を入れる } }

2011年6月14日火曜日

smbセッションキャッシュクリア

--------------------------------------------------
同じユーザーによる、サーバーまたは共有リソースへの複数のユーザー名での複数の接続は許可されません。
サーバーまたは共有リソースへの以前の接続をすべて切断してから、再試行してください。
--------------------------------------------------
上記のようなメッセージが表示され、smb領域のディレクトリにアクセスできない場合
コマンドプロンプトから解消可能。

C:\Documents and Settings\Administrator>net use
新しい接続は記憶されます。


ステータス ローカル名 リモート名 ネットワーク名

-------------------------------------------------------------------------------
OK \\192.168.188.54\files_bk Microsoft Windows Network
\\TSCLIENT\C Microsoft Terminal Services
\\TSCLIENT\D Microsoft Terminal Services
\\TSCLIENT\S Microsoft Terminal Services
コマンドは正常に終了しました。


C:\Documents and Settings\Administrator>net use \\192.168.188.54\files_bk /delete

\\192.168.188.54\files_bk が削除されました。

2011年6月7日火曜日

Linux OSユーザ一括作成シェルスクリプト

通常OSユーザを作成する場合は、useraddコマンドおよびpasswdコマンドを手動で打ち、
一人ひとり作成していきますが、ユーザ数が多くなるとちょっと厄介、ぶっちゃけめんどいです。

今回紹介するスクリプトはユーザ情報がリスト化されたファイルを読み込んで一括でユーザを
作成することができます。
ただし、ユーザが所属するグループを事前に作成しておく必要があります。


■グループを事前に作成
[root@tanyao script]# /usr/sbin/groupadd -g 5000 public

■ユーザリストを準備
[root@tanyao script]# cat mk_user.list
# name:password:uid:gid:comment:home_directory:login_shell:sub_gid
user01:secret01:5001:5000:::/bin/bash
user02:secret02:5002:5000:::/bin/bash
user03:secret03:5003:5000:::/bin/bash
#user04:secret04:5004:5000:::/bin/bash
user05:secret05:5005:5000:::/bin/bash
[root@tanyao script]#
※ /etc/passwd ファイルのフォーマットに合わせてみた。つもり。

■ユーザ一括作成スクリプト(mk_user.sh)
[root@tanyao script]# cat mk_user.sh
#!/bin/sh
# mk_user.listに記述されたユーザを一括で作成します。
# 行頭に"#"がある行はコメント行とみなします。
# 既に存在しているユーザを作成しようとするとスキップされます。
# 事前にグループを作成ください。
# rootユーザで実行してください。

USERLIST=./mk_user.list

if [ ! -f ${USERLIST} ]; then
    echo "${USERLIST} no such file or directory"
    exit 1
fi

grep -v \^# ${USERLIST} | while read line
do
    name="`echo ${line} | cut -d ":" -f1`"
    passwd="`echo ${line} | cut -d ":" -f2`"
    uid="`echo ${line} | cut -d ":" -f3`"
    gid="`echo ${line} | cut -d ":" -f4`"
    comment="`echo ${line} | cut -d ":" -f5`"
    homedir="`echo ${line} | cut -d ":" -f6`"
    loginsh="`echo ${line} | cut -d ":" -f7`"
    subgid="`echo ${line} | cut -d ":" -f8`"

# サブグループがない場合
if [[ ${subgid} = "" ]]; then
    /usr/sbin/useradd -u ${uid} -g ${gid} -c "${comment}" ${name} || continue
# サブグループがある場合
else
    /usr/sbin/useradd -u ${uid} -g ${gid} -G ${subgid} -c "${comment}" ${name} || continue
fi

echo ${name}:${passwd} | chpasswd
echo "Making ${name} succeeded."
done

exit 0
[root@tanyao script]#
[root@tanyao script]# chmod 755 mk_user.sh

■ユーザ作成
[root@tanyao script]# ./mk_user.sh
Making user01 succeeded.
Making user02 succeeded.
Making user03 succeeded.
Making user05 succeeded.
[root@tanyao script]#

■確認
[root@tanyao script]# su - user01
[user01@tanyao ~]$ su - user02
Password:
[user02@tanyao ~]$ id
uid=5002(user02) gid=5000(public) groups=5000(public)
[user02@tanyao ~]$ pwd
/home/user02
[user02@tanyao ~]$

■ユーザ削除コマンド(参考)
[root@tanyao script]# userdel -r user05
[root@tanyao script]# id user05
id: user05: No such user
[root@tanyao script]#


◆ユーザ作成コマンドオプション確認
[root@tanyao script]# useradd --help
Usage: useradd [options] LOGIN

Options:
  -b, --base-dir BASE_DIR       base directory for the home directory of the
                                new account
  -c, --comment COMMENT         GECOS field of the new account
  -d, --home-dir HOME_DIR       home directory of the new account
  -D, --defaults                print or change default useradd configuration
  -e, --expiredate EXPIRE_DATE  expiration date of the new account
  -f, --inactive INACTIVE       password inactivity period of the new account
  -g, --gid GROUP               name or ID of the primary group of the new
                                account
  -G, --groups GROUPS           list of supplementary groups of the new
                                account
  -h, --help                    display this help message and exit
  -k, --skel SKEL_DIR           use this alternative skeleton directory
  -K, --key KEY=VALUE           override /etc/login.defs defaults
  -l, --no-log-init             do not add the user to the lastlog and
                                faillog databases
  -m, --create-home             create the user's home directory
  -M, --no-create-home          do not create the user's home directory
  -N, --no-user-group           do not create a group with the same name as
                                the user
  -o, --non-unique              allow to create users with duplicate
                                (non-unique) UID
  -p, --password PASSWORD       encrypted password of the new account
  -r, --system                  create a system account
  -s, --shell SHELL             login shell of the new account
  -u, --uid UID                 user ID of the new account
  -U, --user-group              create a group with the same name as the user
  -Z, --selinux-user SEUSER     use a specific SEUSER for the SELinux user mapping

[root@tanyao script]#

◆ユーザ編集コマンドオプション確認
[root@tanyao script]# usermod --help
Usage: usermod [options] LOGIN

Options:
  -c, --comment COMMENT         new value of the GECOS field
  -d, --home HOME_DIR           new home directory for the user account
  -e, --expiredate EXPIRE_DATE  set account expiration date to EXPIRE_DATE
  -f, --inactive INACTIVE       set password inactive after expiration
                                to INACTIVE
  -g, --gid GROUP               force use GROUP as new primary group
  -G, --groups GROUPS           new list of supplementary GROUPS
  -a, --append                  append the user to the supplemental GROUPS
                                mentioned by the -G option without removing
                                him/her from other groups
  -h, --help                    display this help message and exit
  -l, --login NEW_LOGIN         new value of the login name
  -L, --lock                    lock the user account
  -m, --move-home               move contents of the home directory to the
                                new location (use only with -d)
  -o, --non-unique              allow using duplicate (non-unique) UID
  -p, --password PASSWORD       use encrypted password for the new password
  -s, --shell SHELL             new login shell for the user account
  -u, --uid UID                 new UID for the user account
  -U, --unlock                  unlock the user account
  -Z, --selinux-user            new SELinux user mapping for the user account

[root@tanyao script]#

◆ユーザ削除コマンドオプション確認
[root@tanyao script]# userdel --help
Usage: userdel [options] LOGIN

Options:
  -f, --force                   force removal of files,
                                even if not owned by user
  -h, --help                    display this help message and exit
  -r, --remove                  remove home directory and mail spool
  -Z, --selinux-user            remove SELinux user from SELinux user mapping

[root@tanyao script]#


この情報がお役に立ちましたら、いえ、ご寄付はいりません。
サイト継続のご協力を賜りたく存じます。 m(_ _)m