Home > Linux
Linux Archive
今更だけど玄箱のNAS化に挑戦 2
- 2008-08-05 (火)
- Linux
まだ設定に難があるが最低限設定したときのメモ。この玄箱+Debianサーバー、日本語環境が入っていないため、日本語のフォルダやファイルを作成した際はサーバー側では文字化けが発生している。Debian側の日本語環境を整えないとやばいかもしれない…
【GLOBAL】
dos charset:sambaがクライアントと通信するときの文字コードを指定する。
unix charset:sambaが稼動しているマシンで使用している文字コードを指定する。
display charset:SWATで表示する際の文字コード指定。smb.confのドキュメントを参照する限り、unix charsetの指定と同一が望ましいそうだ。
workgroup:sambaサーバーのネットワークコンピュータにおけるグループ指定。
os level:Sambaサーバーがマスタブラウザに昇格するための自身の優先順位。この値が大きければ大きいほどマスタブラウザになりやすくなる
preferred master:このSambaサーバーがマスタブラウザになるかどうかの設定
create mask:Sambaサーバーの共有フォルダ上にファイルが作成されたときに生成されるパーミッションのマスク値
security mask:Windowsからファイルのパーミッションを変更するときに特定の制限を行わせるマスク値。0777と設定されると、Windows上からそのファイルのパーミッション設定が自由に変更できる
directory mask:[create mask]のディレクトリ版
【SHARES】
comment:
path:「ファイル共有の選択」で選択した共有フォルダのサーバー側のパス
write list:アクセスを許可するユーザー。SambaのアカウントはDebian本体のユーザーとは独立しているのでsmbpasswdコマンドでユーザーを作って有効化する必要がある。このユーザーはWindows側のユーザーアカウント/パスワードと統一しているとノンパスで共有フォルダにアクセスが出来た。
今更だけど玄箱のNAS化に挑戦 1
- 2008-08-03 (日)
- Linux
自宅のサーバーをNAS化するため、Sambaを玄箱にインストールしてみた。
【aputitudeの更新】
[ホスト名]:~# aptitude update
Reading Package Lists... Done
Building Dependency Tree
Reading extended state information
Initializing package states... Done
Reading task descriptions... Done
…
[略]
…
Reading Package Lists... Done
Building Dependency Tree
Reading extended state information
Initializing package states... Done
Reading task descriptions... Done
[ホスト名]:~#
【sambaのインストール】[ホスト名]:~# aptitude install samba
Reading Package Lists... Done
Building Dependency Tree
Reading extended state information
Initializing package states... Done
Reading task descriptions... Done
The following NEW packages will be automatically installed:
libconvert-asn1-perl libcrypt-smbhash-perl libcupsys2 libdigest-md4-perl
libdigest-sha1-perl libio-socket-ssl-perl libjcode-pm-perl
libnet-ldap-perl libnet-ssleay-perl libunicode-map-perl
libunicode-map8-perl libunicode-maputf8-perl libunicode-string-perl
samba-common smbldap-tools
…
【省略】…
Get:16 http://security.debian.org stable/updates/main samba-common 3.0.24-6etch10 [2548kB]
Get:17 http://security.debian.org stable/updates/main samba 3.0.24-6etch10 [3553kB]
Fetched 8027kB in 29s (274kB/s)
Preconfiguring packages ...
Samba Server
Please specify the workgroup you want this server to appear to be in when queried by
clients. Note that this parameter also controls the domain name used with the security=domain setting.
Workgroup/Domain Name:
WORKGROUP____________________________________________________________
<Ok>Sambaサーバーのワークグループ設定。名前は任意だけど無難にWORKGROUPにした。
Samba Server
All recent Windows clients communicate with SMB servers using encrypted passwords.
If you want to use clear text passwords you will need to change a parameter in
your Windows registry.
Enabling this option is highly recommended. If you do, make sure you have a valid
/etc/samba/smbpasswd file and that you set passwords in there for each user using
the smbpasswd command.
Use password encryption?
<Yes> <No>暗号化パスワードを使用するかどうか。推奨値通りの設定を行った。
Samba Server
If your computer gets IP address information from a DHCP server on the network, the DHCP server may also provide information about WINS servers ("NetBIOS name x servers") present on the network. This requires a change to your smb.conf file so that DHCP-provided WINS settings will automatically be read from x /etc/samba/dhcp.conf.
The dhcp3-client package must be installed to take advantage of this feature.
Modify smb.conf to use WINS settings from DHCP?
<Yes> <No>
WINSとDHCPを使うためにsmb.confを設定するかどうか。サーバーは静的なIPアドレスを使用しているため、No。
Samba Server
The Samba daemon smbd can run as a normal daemon or from inetd. Running as a daemon is the recommended approach.
How do you want to run Samba?
daemons
inetd
<Ok>Sambaをどうやって起動するか。うちの環境ではinetdが上がっているので、inetd経由で起動するようにする。
Samba Server
To be compatible with the defaults in most versions of Windows, Samba must be
configured to use encrypted passwords. This requires user passwords to be stored
in a file separate from /etc/passwd. This file can be created automatically, but
the passwords must be added manually by running smbpasswd and be kept up-to-date
in the future.
If you do not create it, you will have to reconfigure Samba (and probably your
client machines) to use plaintext passwords.
See /usr/share/doc/samba-doc/htmldocs/ENCRYPTION.html from the samba-doc package
for more details.
Create samba password database, /var/lib/samba/passdb.tdb?
<Yes> <No>
パスワードデータベースを作るかどうか。推奨値通りの設定にした。
…
[略]
…
Importing accout for mysql...ok
Importing accout for sshd...ok
Starting Samba daemons: nmbd.
Setting up libcrypt-smbhash-perl (0.12-1) ...
Setting up smbldap-tools (0.9.2-3) ...Reading Package Lists... Done
Building Dependency Tree
Reading extended state information
Initializing package states... Done
Reading task descriptions... Done
【SWATのインストール】
Sambaのインストールが完了し、今度はWeb経由でSambaの設定を行うためにSWATを導入。
[ホスト名]:~# aptitude install swat
Reading Package Lists... Done
Building Dependency Tree
Reading extended state information
Initializing package states... Done
Reading task descriptions... Done
The following NEW packages will be automatically installed:
samba-doc
…
[略]
…(Reading database ... 16767 files and directories currently installed.)
Unpacking samba-doc (from .../samba-doc_3.0.24-6etch10_all.deb) ...
Selecting previously deselected package swat.
Unpacking swat (from .../swat_3.0.24-6etch10_powerpc.deb) ...
Setting up samba-doc (3.0.24-6etch10) ...Setting up swat (3.0.24-6etch10) ...
Reading Package Lists... Done
Building Dependency Tree
Reading extended state information
Initializing package states... Done
Reading task descriptions... Done
[ホスト名]:~#
SWATのインストール完了後、ブラウザからSambaの設定画面を上げてみると、無事アクセスできた。ここからSambaの設定を行って行く。その内容はまた次回のエントリーにて。
Apacheのログに日付を加える
- 2008-05-03 (土)
- Linux
玄箱にLinux+Apacheを導入し、Blogサーバーを構築して暫く経った。Apacheのアクセスログは何も設定しないとファイル名の末尾に数字がつく。これじゃあ何日のログか分からなくなるので、ログファイルに日付をつけることにした。
/etc/logrotate.d/apacheに以下の記述を加えてみる。
postrotate
if [ -f /var/run/apache.pid ]; then \
if [ -x /usr/sbin/invoke-rc.d ]; then \
invoke-rc.d apache reload > /dev/null; \
else \
/etc/init.d/apache reload > /dev/null; \
fi; \
fi;EXT=`date +%Y%m%d`
for f in $1;
do mv $f.1 $f.$EXT;
done
endscript
そんで持って結果がこれ。
-rwxr--r-- 1 root root 491840 Apr 27 23:48 access.log.20080427
-rwxr--r-- 1 root root 602413 Apr 28 23:47 access.log.20080428
-rwxr--r-- 1 root root 756288 Apr 29 23:47 access.log.20080429
-rwxr--r-- 1 root root 646154 Apr 30 23:50 access.log.20080430
-rwxr--r-- 1 root root 459936 May 1 23:44 access.log.20080501
-rwxr--r-- 1 root root 490528 May 2 23:43 access.log.20080502
-rwxr--r-- 1 root root 570498 May 3 23:17 error.log
drwxr--r-- 2 root root 16384 Mar 9 20:14 lost+found
drwxr--r-- 2 root root 4096 Mar 9 20:15 share
drwxr--r-- 2 root root 4096 Mar 9 20:14 share-mac
まあ、何とか出来てる模様。時たま失敗してログの容量が0になるのだがw
.htaccessを利用したアクセス制限
- 2008-04-02 (水)
- Linux
玄箱+Debianで新規にブログサーバーを構築したせいか、以前Apacheで設定していたアクセス制限が設定されなくなってスパムコメントが大量に発生。
ということで.htaccessにて日本が取得しているIPアドレスにしかコメントをさせないようにCGIディレクトリだけアクセス制限をかけることにした。
まずはhttpd.confを編集し、CGIが稼動しているディレクトリのディレクティブ設定を編集。
# cd /etc/apache
# vi httpd.conf--------------------------------------------
<Directory /***/***/**/>
AllowOverride All
Options All
#↑AllowOverrideとOptionsを変更
Order allow,deny
Allow from all
</Directory>
--------------------------------------------
続いて肝心のCGIが稼動しているディレクトリに.htaccessをおく
# cd /***/***/**/
# vi .htaccess--------------------------------------------
order deny,allow
Deny from allAllow from 192.168.1.
Allow from 43.0.0.0/8
Allow from 58.0.0.0/15…
--------------------------------------------
そんでもって、Apacheの再起動して完了。
# apachectl restart
これでスパムコメントは減るかな。
Debian化した玄箱のApache設定メモ
- 2008-03-22 (土)
- Linux
徐々に追加しようと思うが、このサーバーを導入したときのApacheの設定項目をメモしておく。
インストール
- # aptitude install apache
設定ファイルのありか
- /etc/apache/httpd.conf
httpd.confの設定
- Apacheのバージョンを隠す
ServerSignature Off
- Apacheを稼動させているOSやその他の情報を隠す
ServerTokens ProductOnly
- Webページの文字化け対策
AddDefaultCharset Off
※ここは決して「None」などと書いてはいけない。Apacheのマニュアルを見ても、ここの項目に「None」と定義できるとは書いていない。Noneと書くと香具師呼ばわりされるので注意 - mod_perlを使ってPerl処理を高速化するときの指定
<IfModule mod_perl.c>
PerlModule Apache::Registry
<Location /***/***/***>
SetHandler perl-script
PerlHandler Apache::Registry
Options +ExecCGI
</Location>
</IfModule>
- mod_perlのモジュールがロードされていることを確認
/etc/apache/modules.confに以下の記述があるかどうかを確認
LoadModule perl_module /usr/lib/apache/1.3/mod_perl.so
無論、httpd.confにも以下の記述があることが前提
# Please keep this LoadModule: line here, it is needed for installation.
Include /etc/apache/modules.conf
ログのローテーション
- 2007-01-10 (水)
- Linux
Linuxで出力されるmessagesログやsecureログをローテーションするlogrotateを使用してログローテーションをしてみる。
logrotateは基本的にcronで実行される。(logrotateは単なるプロセスだから、定期的に実行するようなことはしない)cronデーモンの設定ファイルにスクリプトファイルとして大概の場合置かれていると思う。
# cd /etc/cron.daily
# ls | grep logrotate
logrotate*
※/etc/cron.daily/配下は毎日実行されるジョブがスクリプトとして登録されている。
# more /etc/crontab
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/
# run-parts
01 * * * * root run-parts /etc/cron.hourly
22 4 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly
上記の場合、毎日実行されるジョブは毎日4:22に実行されるという意味。
cronで実行されるlogrotateは以下のスクリプトを読み込んでログローテートを行う。
# more /etc/logrotate.conf
------------------------------
# see "man logrotate" for details
# rotate log files weekly
weekly
# keep 4 weeks worth of backlogs
rotate 4
# create new (empty) log files after rotating old ones
create
# uncomment this if you want your log files compressed
#compress
# RPM packages drop log rotation information into this directory
include /etc/logrotate.d
# no packages own wtmp -- we'll rotate them here
/var/log/wtmp {
monthly
create 0664 root utmp
rotate 1
}
-------------------------
ログファイルごとに個別にローテーション間隔を設定するときは/etc/logrotate.d内の各ファイルを設定すればいい。
# vi /etc/logrotate.d/syslog
-------------------------
/var/log/messages {
rotate 10←追加
daily←追加
postrotate
/bin/kill -HUP `cat /var/run/syslogd.pid 2> /dev/null` 2> /dev/null || true
endscript
}
/var/log/secure {
postrotate
/bin/kill -HUP `cat /var/run/syslogd.pid 2> /dev/null` 2> /dev/null || true
endscript
}
/var/log/maillog {
postrotate
/bin/kill -HUP `cat /var/run/syslogd.pid 2> /dev/null` 2> /dev/null || true
endscript
}
/var/log/spooler {
postrotate
/bin/kill -HUP `cat /var/run/syslogd.pid 2> /dev/null` 2> /dev/null || true
endscript
}
/var/log/boot.log {
postrotate
/bin/kill -HUP `cat /var/run/syslogd.pid 2> /dev/null` 2> /dev/null || true
endscript
}
/var/log/cron {
postrotate
/bin/kill -HUP `cat /var/run/syslogd.pid 2>/dev/null` 2>/dev/null || true
endscript
}
-------------------------
error: error reading top line of /var/lib/logrotate.status
とエラーを出して動かないので注意すること。
logrotate state -- version 1
CentOSにTelnetサーバー
- 2006-07-11 (火)
- Linux
CentOSにTelnetサーバーを導入する際はyumコマンドだけで簡単にインストールできる。楽になったもんだな
# yum -y install telnet-server
-yオプションは途中で確認メッセージが出ても全部yesと回答するという意味。
CentOSは特にインストールオプションをいじってなければデフォルトでxinetdが導入されているので/etc/xinetd.d/telnetを編集してサービスが立ち上がるようにする。(Telnetはxinetd経由で起動)
# default: on
# description: The telnet server serves telnet sessions; it uses \
# unencrypted username/password pairs for authentication.
service telnet
{
flags = REUSE
socket_type = stream
wait = no
user = root
server = /usr/sbin/in.telnetd
log_on_failure += USERID
disable = no 【←これをnoにしてサービスを有効にする】
only_from = 192.168.1.0 【←接続元の制限設定。192.168.1.0のネットワークからの接続を許可】
}
grubを搭載したブータブルCDを作成する
- 2006-06-15 (木)
- Linux
Windows Vistaをインストールしたいが、絶対このOSはMBRを書き換えてしまって別領域に入っているCentOSが起動できない現象が起こるだろう。そのためにCDからブートしてCentOSが起動できるようにしたい。
#pwd
/tmp/
# losetup /dev/loop1 cdboot
# dd if=/boot/grub/stage1 of=cdboot bs=512 count=1
# dd if=/boot/grub/stage2 of=cdboot bs=512 seek=1
# dd if=/dev/zero of=cdboot bs=512 seek=221 count=5539
# losetup -d /dev/loop1
# mkdir cdimage
# mkisofs -r -J -b cdboot -o cdboot.img ./cdimage
こうして作られたISOイメージファイルcdboot.imgをCDに焼く。ライティングソフトはX-CD-Roastでやるとうまくいった。
CDからブートすると以下のプロンプトが表示される。
grub>
こっからCentOSをブートするには以下を実行
grub>root (hd0,2)
grub>kernel /boot/vmlinuz-2.6.9-22.EL ro root=LABEL=/ rhgb quiet
grub>initrd /boot/initrd-2.6.9-22.EL.img
grub>boot
ブートするためのコマンドがややこしいです!!w
menu.listも焼いとけばよかったか!
参考URL
http://mland98.rc.kyushu-u.ac.jp/memo/cdboot.html
grubのブートコマンドはあくまでCentOSが3番目の領域にインストールされている事が前提。
Home > Linux