lastコマンドで最近ログインしたアカウントを確認することができる。
#last admin pts/0 xx.xx.xx.xxx.in- Sun Jan 7 22:19 still logged in reboot system boot 2.6.9-42.EL Sun Jan 7 22:18 (00:17) admin pts/0 xx.xx.xx.xxx.in- Sat Jan 6 08:23 - down (00:36) root tty1 Sat Jan 6 08:20 - down (00:39) reboot system boot 2.6.9-42.EL Sat Jan 6 06:18 (02:41) admin pts/0 xx.xx.xx.xxx.in- Sat Jan 6 06:11 - down (00:04) reboot system boot 2.6.9-42.EL Sat Jan 6 06:07 (00:08) admin pts/0 xx.xx.xx.xxx. Sat Jan 6 05:55 - down (00:09) reboot system boot 2.6.9-42.ELsmp Sat Jan 6 05:54 (00:11) admin pts/2 xx.xx.xx.xxx.in- Sat Jan 6 00:34 - 02:39 (02:04)
このログは/var/log/wtmpに残っている。これはバイナリなので中を見たいときはwhoコマンドでみる。
#who /var/log/wtmp hoge pts/2 Jan 6 00:34 (xx.xx.xx.xxx..in-addr.arpa) hoge pts/0 Jan 6 05:55 (xxx.xxx.xx.xx) hoge pts/0 Jan 6 06:11 (xx.xx.xx.xxx..in-addr.arpa) root tty1 Jan 6 08:20 hoge pts/0 Jan 6 08:23 (xx.xx.xx.xxx..in-addr.arpa) hoge pts/0 Jan 7 22:19 (xx.xx.xx.xxx..in-addr.arpa)
lastlogコマンドは各アカウントの最終ログインの一覧を見るときに便利だ。普段利用していないアカウントでログインされていると・・・。怖いですね。
の場合はlastloginです。
#lastlog Username Port From Latest root tty1 Sat Jan 6 08:20:21 +0900 2007 bin **Never logged in** daemon **Never logged in** adm **Never logged in** hoge pts/0 xx.xx.xx.xxx.in- Sun Jan 7 22:19:41 +0900 2007 moge pts/1 xx.xx.xx.xxx.in- Sat Dec 30 02:53:05 +0900 2006 mysql **Never logged in** postgres **Never logged in** alias **Never logged in** qmaild **Never logged in** qmaill **Never logged in** qmailp **Never logged in** qmailq **Never logged in** qmailr **Never logged in** qmails **Never logged in** vpopmail **Never logged in**
whoコマンドで/var/run/utmpも見ることができる。
これは現在システムを利用しているユーザの情報。
※ただすべてのプログラムが utmp ファイルを更新しているわけではないので、実際にはそれ以上のユーザーがシステムを使っている可能性がある。 (Manpageより)
【参考サイト】@IT 連載:不正侵入の手口と対策http://www.atmarkit.co.jp/fsecurity/rensai/iprotect06/iprotect01.html
# httpd -v Server version: Apache/2.2.3 Server built: Jan 15 2008 20:33:30
# apachectl -v Server version: Apache/2.2.3 Server built: Jan 15 2008 20:33:30/etc/rc.d/init.d/httpdは起動スクリプトなので-vオプションはききません。
# /usr/local/apache2/bin/httpd -v Server version: Apache/2.2.9 (Unix) Server built: Sep 19 2008 18:28:54
# /usr/local/apache2/bin/apachectl -v Server version: Apache/2.2.9 (Unix) Server built: Sep 19 2008 18:28:54
LILOでシングルユーザモードで起動するにはboot:が表示されたらlinux singleと入力する。
boot: linux single
グラフィカルな画面の場合はCtrl-Xでテキストモードに移ってからlinux singleと打つ。linuxはLILOで設定したラベルである。
GRUBの場合はカーネルの種類を選んでaキーを押すとコマンドラインになるのでsingleを末尾に追加してEnterを押す。
参考サイト:
@IT: Linux TIPS シングルユーザーモードで起動するには
http://www.atmarkit.co.jp/flinux/rensai/linuxtips/488bootsingle.html
CentOSでパッケージのアップデートかけようとしてyum updateを使ったら。
カーネルを自動更新されてしまって次回起動時にはkernel panicで停止するような勝手に更新されては困る場合には/etc/sysconfig/kernelを編集してUPDATEDEFAULT=noにしよう。
# UPDATEDEFAULT specifies if new-kernel-pkg should make # new kernels the default #UPDATEDEFAULT=yes←コメントアウト UPDATEDEFAULT=no # DEFAULTKERNEL specifies the default kernel package type DEFAULTKERNEL=kernel-smp
【参考サイト】カーネルのアップデート/再構築、デバイスファイルの動作
http://www.stackasterisk.jp/tech/systemConstruction/fedoracore302_01.jsp
quotaで設定した情報はrepquota コマンドで一覧にすることができます。
repquota -av
hogeと同じ設定をmogeにもしたい場合は-pオプションで設定できる。
edquota -p hoge moge
sortコマンドは入力にフィルタをかけてソートした結果を出力することができます。
CentOS、Linuxを含むUNIX系OS全般で利用できます。
sortコマンドは1行プログラミングに大変便利です。
デフォルトではアルファベット順でソートですが、-nオプションで数値として処理することができます。
たとえばPSコマンドの出力をソートする場合は次のようになります。
ps | sort (正順でソート) ps | sort -n (数値としてソート) ps | sort -r (逆順でソート) ps | sort -rn (数値として逆順でソート)
デフォルトのsortコマンドで数値が並んでいる表示をソートしようとするとテキストで評価されるため目的の結果が得られません。
そんなときは数値としてソートする「-nオプション」をつけてください。
CentOSインストールからバーチャルドメインによる公開サーバ(Webサーバ、Mailサーバ)の運用ノウハウまでをわかりやすく網羅しています。
困ったときにGoogleを検索すると高い確率でこのサイトにお世話になることになります(笑)。
CentOSのリリース情報を得たり、OSイメージのダウンロードをしたりすることができます。
MySQLとphpMyAdminをインストールする。
追記: 2008/11/22
現在CentOS5.2で利用している設定に訂正しました。
yum -y install mysql-server chkconfig mysqld on chkconfig --list mysqld ---------------------------------------------------------------------- mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off ---------------------------------------------------------------------- /etc/rc.d/init.d/mysqld start mysqladmin -u root password '36NUi8uX'
文字コードがlatin1になっているのをUTF-8に変更する。EUCの場合はutf8をujisと置き換えてください。
追記: 2008/11/22
以前は"init-connect=SET NAMES utf8"を設定していました。しかし、どんな場合でもUTF-8として扱う強制的な設定なため、他の文字コードも混在する場合には不具合の原因となる場合があります。現在はコメントアウトにしています。プログラム側で文字コードの修正ができない場合など有用な場合もあります。
cp /etc/my.cnf /etc/my.cnf.org vi /etc/my.cnf -------------------------------------------------------------- [mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock user=mysql # Default to using old password format for compatibility with mysql 3.x # clients (those using the mysqlclient10 compatibility package). old_passwords=1 default-character-set=utf8 skip-character-set-client-handshake #init-connect=SET NAMES utf8 [mysqld_safe] log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid default-character-set=utf8 [mysql] default-character-set=utf8 -------------------------------------------------------------- /etc/rc.d/init.d/mysqld restart mysql> show variables like 'char%'; +--------------------------+----------------------------+ | Variable_name | Value | +--------------------------+----------------------------+ | character_set_client | ujis | | character_set_connection | ujis | | character_set_database | ujis | | character_set_filesystem | binary | | character_set_results | ujis | | character_set_server | ujis | | character_set_system | utf8 | | character_sets_dir | /usr/share/mysql/charsets/ | +--------------------------+----------------------------+ 8 rows in set (0.00 sec) mysql>exitPHPとPHPのモジュールインストール
PHPのインストールをしていない場合はインストールしてください。
yum -y install php php-mysql php-mbstring php-pear php-gdphpMyAdminのインストール
最新版は本家からダウンロードしてください。CentOS5.2のPHPのバージョンが5.1系なので、PHP5.2以上が必要なphpMyAdmin3系はデフォルトでは利用できません。phpMyAdmin2系の最新版をご検討ください。
http://www.phpmyadmin.net/
cd /usr/local/src/
wget http://jaist.dl.sourceforge.net/sourceforge/phpmyadmin/phpMyAdmin-2.11.9.3-all-languages.tar.gz
tar zxvf phpMyAdmin-2.11.9.3-all-languages.tar.gz
mv phpMyAdmin-2.11.9.3-all-languages /var/www/phpMyAdmin
chown -R root:apache /var/www/phpMyAdmin/
vi /etc/httpd/conf.d/phpmyadmin.conf
------------------------------------------------------
Alias /phpMyAdmin "/var/www/phpMyAdmin"
<Directory "/var/www/phpMyAdmin">
Order allow,deny
Allow from all
</Directory>
------------------------------------------------------
/etc/rc.d/init.d/httpd reload
mkdir /var/www/phpMyAdmin/config
chmod 777 /var/www/phpMyAdmin/config
http://www.example.com/phpMyAdmin/scripts/setup.php にアクセス
--------------------------------------------------------------------------------
Load ボタン
Servers Add ボタン
Authentication type = http
Add ボタン
Save ボタン
--------------------------------------------------------------------------------
mv /var/www/phpMyAdmin/config/config.inc.php /var/www/phpMyAdmin/config.inc.php
http://www.example.com/phpMyAdmin/ にアクセスしてログイン確認
ID: root
PW: MySQL root パスワード
rm -rf /var/www/phpMyAdmin/config
chmod 444 /var/www/phpMyAdmin/config.inc.php
chmod 000 /var/www/phpMyAdmin/scripts
やっぱりLinux上での開発はEmacsだ!という人はCentOSにEmacsをインストールしましょう。
yum -y install emacs
ちなみに寺の息子が大学時代所属していた計算化学の研究室では「イーマックス」ではなく「エマックス」と呼ばれてました。
CentOS5にRubyからMySQLを操作するためのモジュールRuby/MySQLをインストールします。 MySQLが入っていない場合はまずインストールします。
yum -y install mysql-server chkconfig mysqld on chkconfig --list mysqld mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off /etc/rc.d/init.d/mysqld start
MySQLのユーザrootのパスワードを設定します。
mysqladmin -u root password 'pass'
最後にRuby/MySQLをダウンロードしてインストールします。 最新版はプロジェクトのサイトで確認してください。 http://www.tmtm.org/ruby/mysql/
wget http://www.tmtm.org/ruby/mysql/ruby-mysql-0.2.6.tar.gz tar zxvf ruby-mysql-0.2.6.tar.gz cd ruby-mysql-0.2.6 ruby ./setup.rb ruby ./test.rb localhost root pass connect.............ok create_db...........ok create_table........ok insert..............ok select..............ok update..............ok drop_table..........ok drop_db.............ok close...............ok ruby ./install.rb
自分で書いたスクリプトでテストしてみましょう。 sql.rbという名前で下の内容のテキストを作成してください。
#!/usr/bin/ruby
require "mysql"
my = Mysql::new("localhost", "root", "pass", "mysql")
res = my.query("select * from user")
res.each do |row|
p row
end
実行してデータベース「mysql」のテーブルuserの内容が表示されればOKです。
chmod 755 sql.rb ./sql.rb
CentOS5がリリースされました。CentOS4.4からのメジャーバージョンアップとなります。
アップデートされた主なソフトウェアは下記のとおりでPHP、MySQLがともに4系から5系になりました。
Apache-2.2
php-5.1.6
MySQL-5.0
PostgreSQL-8.1.
kernel-2.6.18
Gnome-2.16
KDE-3.5
OpenOffice.org-2.0
Evolution-2.8
Firefox-1.5
Thunderbird-1.5
【Community ENTerprise Operating System】
http://www.centos.org/
CentOS5公式アナウンス(英語)
Xenによる仮想化の支援が強化されました。Virtual Machine Managerも利用できます。インストール時に「Virtualization」を選択することができます。
CentOS 5は、CD 6枚組またはDVD 1枚組として配布されています。 DVDによるOSの配布が多くなってきましたね。
インストールするマシンがDVDドライブならばDVDが便利です。私もDVDでインストールしています。
【ITmediaレビュー レビュー:CentOS 5――堅牢なエンタープライズ向けOS 】 http://www.itmedia.co.jp/enterprise/articles/0704/20/news051.html
#arp Address HWtype HWaddress Flags Mask Iface 1.0.168.192.in-addr.arp ether 00:80:6D:7A:01:5D C eth0 192.168.0.14 ether 00:01:80:58:1B:AA C eth0
# route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 192.168.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0 169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0 0.0.0.0 192.168.0.1 0.0.0.0 UG 0 0 0 eth0
chkconfig smb on service smb startSWATを利用するにはWebサーバも起動している必要があるのでhttpdをONにして起動する。
chkconfig httpd on service httpd startSWATをインストールし、SWATが利用する901番ポートを空けるためxinetdの設定をする。
yum -y install samba-swat
vi /etc/xinetd.d/swat
-------------------------
# default: off
# description: SWAT is the Samba Web Admin Tool. Use swat \
# to configure your Samba server. To use SWAT, \
# connect to port 901 with your favorite web browser.
service swat
{
port = 901
socket_type = stream
wait = no
only_from = 127.0.0.1
only_from = 192.168.0.0/24 (許可するネットワークを追加)
user = root
server = /usr/sbin/swat
log_on_failure += USERID
disable = no (変更)
}
-------------------------
xinetdを再起動してSWATが利用する901番ポートを空ける。
/etc/rc.d/init.d/xinetd restarthttp://192.168.0.10:901/ ID:root パスワード:rootのパスワード SambaへアクセスするUNIXユーザを作成する。
useradd hogehoge passwd hogepasssmbpasswdでSamba独自のユーザも追加する。
smbpasswd -a hogehoge New SMB password: Retype new SMB password: Added user hogehoge.共有のディレクトリを作成する
cd /home/ mkdir share chmod 777 sharepublicの記述を追加して/home/shareが共有ディレクトリになるように設定してsmbを再起動。
cd /etc/samba/ vi smb.conf ------------------------- [public] path = /home/share public = yes only guest = yes writable = yes printable = no volume = share ------------------------- service smb restart
yum -y install vsftpdデフォルトではanonymousFTPサーバが有効になってしまうので設定を無効にする。FTPユーザでログインする際にそのユーザがログインしたホームディレクトリをルートディレクトリとして上位のディレクトリへはアクセスさせない設定(chroot)をする。
chkconfig vsftpd on chkconfig --list vsftpd ---------------------------------------------------------------------- vsftpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off ---------------------------------------------------------------------- ・anonymouss設定停止、chrootの設定等 cd /etc/vsftpd/ cp vsftpd.conf vsftpd.conf.org vi vsftpd.conf ---------------------------------------------------------------------- #anonymous_enable=YES anonymous_enable=NO force_dot_files=YES chroot_local_user=YES chroot_list_enable=YES use_localtime=YES pasv_promiscuous=YES pasv_min_port=50000 pasv_max_port=50030 ascii_upload_enable=YES ascii_download_enable=YES xferlog_file=/var/log/vsftpd.log #xferlog_std_format=YES xferlog_std_format=NO ---------------------------------------------------------------------- touch /etc/vsftpd/chroot_listchrootの設定から除外してすべてのディレクトリを参照するユーザを設定する場合にはvsftpd.chroot_list へユーザ名を記述する。ここではuser2がすべてのディレクトリを参照できるように設定している。
vi /etc/vsftpd.chroot_list ---------------------------------------------------------------------- user2 ----------------------------------------------------------------------vsFTPDの起動
/etc/rc.d/init.d/vsftpd start起動時の設定
chkconfig vsftpd on chkconfig --list | grep ftp ---------------------------------------------------------------------- vsftpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off ----------------------------------------------------------------------
fdisk -l /dev/hda --------------------------------------------------------------------------- Disk /dev/hda: 750.1 GB, 750156374016 bytes 255 heads, 63 sectors/track, 91201 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/hda1 * 1 2550 20482843+ 83 Linux /dev/hda2 2551 5100 20482875 83 Linux /dev/hda3 5101 6375 10241437+ 83 Linux /dev/hda4 6376 91201 681364845 5 Extended /dev/hda5 6376 6630 2048256 82 Linux swap /dev/hda6 6631 91201 679316526 83 Linux ---------------------------------------------------------------------------
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os baseurl=http://ftp.riken.jp/Linux/centos/$releasever/os/$basearch/ #baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
vi /etc/yum.repos.d/CentOS-Base.repo --------------------------------------------------------------------------------- # CentOS-Base.repo # # This file uses a new mirrorlist system developed by Lance Davis for CentOS. # The mirror system uses the connecting IP address of the client and the # update status of each mirror to pick mirrors that are updated to and # geographically close to the client. You should use this for CentOS updates # unless you are manually picking other mirrors. # # If the mirrorlist= does not work for you, as a fall back you can try the # remarked out baseurl= line instead. # # [base] name=CentOS-$releasever - Base #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os baseurl=http://ftp.riken.jp/Linux/centos/$releasever/os/$basearch/ #baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/ gpgcheck=1 gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-centos4 priority=1 protect=1 #released updates [update] name=CentOS-$releasever - Updates #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates baseurl=http://ftp.riken.jp/Linux/centos/$releasever/updates/$basearch/ #baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/ gpgcheck=1 gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-centos4 priority=1 protect=1 #packages used/produced in the build but not released [addons] name=CentOS-$releasever - Addons #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=addons baseurl=http://ftp.riken.jp/Linux/centos/$releasever/addons/$basearch/ #baseurl=http://mirror.centos.org/centos/$releasever/addons/$basearch/ gpgcheck=1 gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-centos4 priority=1 protect=1 #additional packages that may be useful [extras] name=CentOS-$releasever - Extras baseurl=http://ftp.riken.jp/Linux/centos/$releasever/extras/$basearch/ #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras #baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/ gpgcheck=1 gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-centos4 priority=1 protect=1 #additional packages that extend functionality of existing packages [centosplus] name=CentOS-$releasever - Plus #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus baseurl=http://ftp.riken.jp/Linux/centos/$releasever/centosplus/$basearch/ #baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/ gpgcheck=1 enabled=0 gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-centos4 priority=2 protect=1 #contrib - packages by Centos Users [contrib] name=CentOS-$releasever - Contrib #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib baseurl=http://ftp.riken.jp/Linux/centos/$releasever/contrib/$basearch/ #baseurl=http://mirror.centos.org/centos/$releasever/contrib/$basearch/ gpgcheck=1 enabled=0 gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-centos4 priority=2 protect=1 [dag] name=Dag RPM Repository for Redhat EL4 baseurl=http://apt.sw.be/redhat/el$releasever/en/$basearch/dag gpgcheck=1 enabled=1 gpgkey=http://dag.wieers.com/packages/RPM-GPG-KEY.dag.txt ---------------------------------------------------------------------------------yum -y update
yum -y install yum-plugin-fastestmirrorあとは/etc/yum.confに一行追加します。
plugins=1CentOS5の場合は
yum -y install yum-fastestmirrorplugins=1はすでに記述されているので必要ありません。
Determining fastest mirrors
Loading mirror speeds from cached hostfile