WEBの勉強ノート
Loading

Linux でディレクトリ内のファイルをすべて消去

2009 年 5 月 21 日 木曜日

専用のオプションでもあるのかと思いきや、意外と簡単な方法を組み合わせてで
きるのですね。

こんなディレクトリと、ファイルがあったとして、

[root@localhost test]# ls -a
.  ..  test01.text  test02.text  test03.text  test04.text  test05.text

rm -f ./* を実行。「同じディレクトリのすべてのファイルを消去」ですね。

[root@localhost test]# rm -f ./*
[root@localhost test]# ls -a
.  ..

Linux システムの文字コード

2009 年 5 月 17 日 日曜日

Linux システム自体の文字コードは、以下の場所で確認・変更することができます。

[root@centos ~]# cat /etc/sysconfig/i18n
LANG="ja_JP.UTF-8"

yum.conf /etc/yum.repos.d/

2009 年 5 月 16 日 土曜日

yum の設定ファイル yum.conf

yum の設定ファイルは etc 直下にある。ManYumConf で詳細を確認することができる。デフォルトの yum.conf は以下のとおり。

[root@centos ~]# cat /etc/yum.conf
[main]
cachedir=/var/cache/yum
keepcache=0
debuglevel=2
logfile=/var/log/yum.log
distroverpkg=redhat-release
tolerant=1
exactarch=1
obsoletes=1
gpgcheck=1
plugins=1

# Note: yum-RHN-plugin doesn't honor this.
metadata_expire=1h

installonly_limit = 5

# PUT YOUR REPOS HERE OR IN separate files named file.repo
# in /etc/yum.repos.d

「PUT YOUR REPOS HERE OR IN separate files named file.repo in /etc/yum.repos.d」 とあるように、yum.conf 内か、/etc/yum.repos.d ディレクトリに .repo ファイルを置くことで、yum が参照するリポジトリを追加することができる。

yum の設定ファイル /etc/yum.repos.d 以下の .repos

CentOS 5.3 に最初から入っている CentOS-Base.repos ファイルの例。大体の構造をつかめればと。詳細は、yum の wiki で確認することができる。

[root@centos ~]# cat /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://mirror.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5

#released updates
[updates]
name=CentOS-$releasever - Updates
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5

#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://mirror.centos.org/centos/$releasever/addons/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
#baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5

#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://mirror.centos.org/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5

#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib
#baseurl=http://mirror.centos.org/centos/$releasever/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5

ManYumConf から意味を確認。最初のコメント部分の意味は一番下で*1

name

A human readable string describing the repository.

人間がリポジトリを判別するための名前を指定。

mirrorlist

Specifies a URL to a file containing a list of baseurls. This can be used instead of or with the baseurl option. Substitution variables, described below, can be used with this option.

baseurls リストを含むファイルへのパスを指定します。mirrorlist は baseurls のオプションとして、代わりに指定したり、一緒に使用します。

baseurl

Must be a URL to the directory where the yum repository’s ‘repodata’ directory lives. Can be an http:// ftp:// or file:// URL. You can specify multiple URLs in one baseurl statement. The best way to do this is like this: [repositoryid] name=Some name for this repository baseurl=url://server1/path/to/repository/

  • url://server2/path/to/repository/ url://server3/path/to/repository/

If you list more than one baseurl= statement in a repository you will find yum will ignore the earlier ones and probably act bizarrely. Don’t do this, you’ve been warned.

yum リポジトリの repodata ディレクトリを指定します。http://, ftp://, file:// で指定します。1つの baseurl で複数の URL を指定することもできます。また、複数 baseurl を記述すると動作がおかしくなることがあります。

gpgcheck

GPG署名のチェックを行うかどうかの指定をします。0 か 1 で指定します。

enabled

Either ’1′ or ’0′. This tells yum whether or not use this repository.

このリポジトリを使うかどうかを指定します。0 か 1 で指定します。

gpgkey

repository. This option is used if yum needs a public key to verify a package and the required key hasn’t been imported into the RPM database. If this option is set, yum will automatically import the key from the specified URL. You will be prompted before the key is installed unless the assumeyes option is set.

このオプションは、yum がパッケージの検証を行うのに公開キーを必要とる場合に、要求したキーが RPM データベースにインポートされていない場合に使用されます。このオプションを設定すると、yum は自動的に指定した URL から該当のキーをインポートします。キーがインストールされる前に、yes を入力するまでメッセージが表示されます。

exclude

デフォルトの CentOS-Base.repos には入っていないけど、よく使うオプション。

List of packages to exclude from updates or installs. This should be a space separated list. Shell globs using wildcards (eg. * and ?) are allowed.

アップデートやインストールから除外するパッケージを指定します。これは、スペースで区切って複数指定することができます。ワイルドカードの指定が可能です。


*1 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.

「このファイルは、Lance Davis が CentOS のために開発した新しいミラーリストシステムです。このミラーシステムは、更新されており、かつ地理的に近いミラーを探すために、クライアントの IP アドレスとミラーのアップデートステータスを使います。 手動で他のミラーを探すことなく、 CentOS をアップデートすることができます。もしこのミラーリストが動作しないことがあれば、、、※この文がよくわからず、、」

参考にしたサイト

ManYumConf

yum の概要とコマンド

2009 年 5 月 16 日 土曜日

yum とは

yum の公式サイトを覗いてみました→yumによると、RPM パッケージの管理システムの一つで、アプリケーションの依存関係を自動的に検出する機能を持っているもの、とのこと。*1

使えそうな yum のコマンド

yum install, yum remove 以外で、使えそうなものをまとめてみました。man とか ?help でみればよいのでしょうが、WEB では「Basic Yum Commands and how to use them」で確認することもできるようです。

yum list installed

このコマンドは rpm の rpm ?qa と同等のコマンドで、システムにインストールされている全てのパッケージを表示します。

yum info パッケージ名

パッケージの詳細な情報を表示します。

[root@centos ~]# yum info httpd
(省略)
Name       : httpd
Arch       : i386
Version    : 2.2.3
Release    : 22.el5.centos
Size       : 3.1 M
Repo       : installed
Summary    : Apache HTTP Server
URL        : http://httpd.apache.org/
License    : Apache Software License
Description: The Apache HTTP Server is a powerful, efficient, and extensible web server.

yum search キーワード

設定されているリポジトリから、キーワードで検索をおこなう。検索対象は、リポジトリ内のRPMファイルのName、Packager、Dummary、Descriptionの各フィールド 。複数のキーワードも可。


*1 yum の公式サイトの一番最初に書いてある。

Yum is an automatic updater and package installer/remover for rpm systems. It automatically computes dependencies and figures out what things should occur to install packages. It makes it easier to maintain groups of machines without having to manually update each one using rpm. Yum has a plugin interface for adding simple features. Yum can also be used from other python programs via its module inteface.

yum

Yum は、rpm システムの自動アップデート、インストール、アンインストールを行うものです。依存関係を自動的に算出し、インストールパッケージに何が起こるかを検出します。rpm を使った手動アップデートを行うことなく、複数のマシーンの保守をより簡単にすることができます。

Yum はシンプルな機能を追加するためのプラグインインターフェイスをもっています。Yum はモジュールインターフェイスを経由して、python プログラムから使うこともできます。

Linux (CentOS) のホスト名の変更

2009 年 5 月 16 日 土曜日

Linux (RedHat系) では、2つファイルを変更する必要があるようです。

/etc/hosts

[root@centos ~]# cat /etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1               centos.com centos localhost.localdomain localhost
::1             localhost6.localdomain6 localhost6

/etc/sysconfig/network

[root@centos ~]# cat /etc/sysconfig/network
NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=centos.com
GATEWAY=192.168.0.1
[root@centos ~]#

参考にしたサイト

ITmedia エンタープライズ : Linux Tips ホスト名を変更したい

Linux のネットワーク設定

2009 年 5 月 13 日 水曜日

IP などを変更したいとき用の設定方法。/etc/sysconfig/network-scripts/ifcfg-eth0 を編集する。

[root@localhost ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=static
IPADDR=192.168.16.10
NETMASK=255.255.255.0
GATEWAY=192.168.16.2
ONBOOT=yes
# HWADDR=00:0c:29:01:e3:47

設定を反映させるために、ネットワークサービスを再起動する。

 /etc/init.d/network restart

sudo の設定

2009 年 5 月 13 日 水曜日

普段触るのは検証とかテスト用の環境だけだけれど、誤操作防止のために su – を使わない方法も試してみようと思い立った。sudo することを許可する設定がまず必要。

sudo 設定

visudo コマンドを使って、/etc/sudoers を編集して、sudo を許可するアカウントを追加する。編集の仕方は vi と一緒。

書式は「アカウント 許可するホスト = (許可する権限) 許可するコマンド 」

 

[root@centos ~]# visudo
(省略)
## Next comes the main part: which users can run what software on
## which machines (the sudoers file can be shared between multiple
## systems).
## Syntax:
##
##      user    MACHINE=COMMANDS
##
## The COMMANDS section may have other options added to it.
##
## Allow root to run any commands anywhere
root    ALL=(ALL)       ALL
centos  ALL=(ALL)       ALL

sudo のみにして su を禁止する

/etc/pam.d/su を編集して、以下の # を削除。

[root@centos ~]# vi /etc/pam.d/su
# pam_wheel.so use_uid

これで、sudo しか使えない状態に。


参考にしたサイト

sudo の設定

ユーザーの作成・削除・変更

2009 年 5 月 13 日 水曜日

ユーザーの作成

ユーザーの作成には、useradd コマンドを使用。passwd コマンドでパスワードを加えることで初めて使用できるようになる。ユーザーのデフォルト設定は useradd  -D で確認することができる。

[root@centos ~]# useradd centos[root@centos ~]# passwd centosChanging password for user centos.
New UNIX password:
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
[root@centos ~]#

ユーザーの削除(根こそぎ)

ユーザーの削除は userdel だけど、ユーザーが所有していたファイルはそのまま残る。userdel ?r でホームディレクトリのファイルとメールスプールも削除される。

[root@centos ~]# userdel centos -r

その他の場所のユーザーが所有していたファイルやディレクトリも削除したい場合は、削除を行う前にユーザーの uid を確認して、find コマンドで該当の uid が所有者となっているファイルを検索し、何か出てきたら rm -f とか rm -rf とかで消す。

[root@centos ~]# cat /etc/passwd
(省略)
centos:x:501:501::/home/user02:/bin/bash
[root@centos ~]# find / -uid 501

ユーザーをグループに追加

ユーザーをグループに追加するには、ユーザーの属性を変更する usermod コマンドで ?G グループの変更オプションを使用

[root@centos ~]# usermod -G wheel user

ダウンロードしたデータの整合性をハッシュで確認

2009 年 5 月 12 日 火曜日

このまえ、wget でダウンロードしたデータが破損していて、インストールできないということがあった。たまたま、そのサイトにはハッシュ値が載せられていたので、さっと確認できたらいいなと思って調べてみました。

ハッシュ値の計算には openssl コマンドを使います。

ファイル名のハッシュ値

たとえば、shadow ファイルのハッシュ値だと

# cat /etc/shadow |openssl md5

文字列のハッシュ値の計算

たとえば、hogehoge のハッシュ値は

$ echo hogehoge|openssl md5
d9a3fdfc7ca17c47ed007bed5d2eb873

こんな感じ


参考にしたサイト

ITpro : 原理から学ぶネットワーク・セキュリティ 第4回 ハッシュ関数

CentOS インストール後のログ

2009 年 5 月 7 日 木曜日

CentOS インストール後のログは以下の場所に吐き出されるようです。

  • /root/install.log
  • /root/install.log.syslog
  • /var/log/anaconda.log
  • /var/log/anaconda.syslog

/root/install.log の警告

warning: setup-2.5.58-4.el5: Header V3 DSA signature: NOKEY, key ID e8562897

という警告が発生しているのですが、これがなになのかさっぱり。。OS 自体は正常に動いているようなので、問題なさそうなのですが、ほとんど情報がありません。

That just means the key has nor been registered with the system should be no problem it more of a warning then an error

http://www.linuxforums.org/forum/suse-linux-help/126610-header-v3-dsa-signature-nokey-key-id-58857177-a.html

とか

It’s not an error, it’s a warning. Warnings don’t prevent commands from completing. If the command doesn’t work, look for an actual error message in the output.
You can clear the warning by importing the GPG key used to sign the package: http://www.fedorafaq.org/#gpgsig

http://forums.fedoraforum.org/showthread.php?t=98356

とあったりするのですが、何をもって問題ないのかがよくわからず。。GPG キーをインポートすれば、とありますが、GPGって何?

進めば進むほどわからないことが増えています。。。


参考にしたページ

Think IT : ログ管理、これだけは!第1回:必読!ログファイルとディレクトリ
http://thinkit.jp/article/711/3/