アットウィキロゴ

【メモ】2011.06.13~15 システム基盤構築・実践トレーニング -Webシステム構築-

※日本語入力
SHIFT+スペース
 
※日本語入力を再可能にする方法
[root@linux14 root]# ps aux | less
root      4780  0.0  0.1  5004 2408 ?        S    10:01   0:00 kinput2 -canna
 
コマンド投入:kinput2 -canna &
 
?OS(Linux)ディレクトリ?
□確認
[root@localhost root]# ls /
/(ルート)…パーティション分割されていないデータを格納、起動時に最初に認識
home…一般ユーザのホームディレクトリを格納
boot…カーネルなどシステムの起動に必要なファイルを格納
usr…各コマンドやソフトウェアのプログラムを格納
var…メールやプリントデータのスプール領域、ログファイルなどを格納
swap領域…OSがメモリ不足時にデータを退避する特殊な領域
bin
data…一般ユーザの作業用データを格納
etc
initrd
lost+found
mnt
proc
sbin
dev
lib
misc
opt
root
tmp
 
?ネットワーク設定の確認?
□ホスト名の確認
[root@localhost root]# hostname
localhost.localdomain
※再起動
[root@linux14 root]# hostname
linux14
 
□IPアドレス、サブネットマスクの確認
[root@localhost root]# ifconfig
lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:1184 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1184 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:118770 (115.9 Kb)  TX bytes:118770 (115.9 Kb)
 
□デフォルトゲートウェイの確認
[root@localhost root]# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
172.18.9.0      *               255.255.255.0   U     0      0        0 eth0
169.254.0.0     *               255.255.0.0     U     0      0        0 eth0
127.0.0.0       *               255.0.0.0       U     0      0        0 lo
default         172.18.9.1      0.0.0.0         UG    0      0        0 eth0
 
□ネットワーク通信可否の確認
□パーティション設定の確認
[root@localhost root]# df
Filesystem           1K-ブロック    使用   使用可 使用% マウント位置
/dev/hda2              5162828   2118652   2781916  44% /
/dev/hda1               101089     14768     81102  16% /boot
/dev/hda8              3099260     32828   2909000   2% /data
/dev/hda5              5162796     32844   4867696   1% /home
none                   1026388         0   1026388   0% /dev/shm
/dev/hda7              5162796     32912   4867628   1% /usr/local
/dev/hda6              5162796     90740   4809800   2% /var
 
□インストール済パッケージの確認
[root@localhost root]# rpm -qa | grep telnet-server
telnet-server-0.17-26
 
?NICドライバのインストール?
□CDよりドライバのコピー
[root@localhost root]# cp /mnt/cdrom/linux-8.2.18.zip /opt/

□ドライバの解凍&展開
[root@localhost root]# cd /opt/
[root@localhost opt]# unzip linux-8.2.18.zip
Archive:  linux-8.2.18.zip
   creating: Server/Linux/Driver/
  inflating: Server/Linux/Driver/bcm5700-8.2.18-1.src.rpm
  inflating: Server/Linux/Driver/bcm5700-8.2.18.tar.gz
  inflating: Server/Linux/Driver/bcm_sup-8.2.18.tar.gz
  inflating: Server/Linux/Driver/DISTRIB.TXT
  inflating: Server/Linux/Driver/README.TXT
 
□ディレクトリの移動&ドライバファイルの解凍&展開
[root@localhost opt]# cd Server/Linux/Driver/
[root@localhost Driver]# tar xvfz bcm5700-8.2.18.tar.gz
bcm5700-8.2.18/
bcm5700-8.2.18/src/
bcm5700-8.2.18/src/5701rls.c
…
 
□ドライバのコンパイル
[root@localhost Driver]# cd bcm5700-8.2.18/src/
[root@localhost src]# make
gcc -DMODULE -D__KERNEL__ -DDBG=0 -DT3_JUMBO_RCV_RCB_ENTRY_COUNT=256 -DNICE_SUPPORT -DPCIX_TARGET_WORKAROUND=1 -DINCLUDE_TBI_SUPPORT -DINCLUDE_5701_AX_FIX=1 -DRED_HAT_LINUX_KERNEL -Wall -Wstrict-prototypes -I/lib/modules/2.4.21-4.ELsmp/build/include -O2   -c -o b57um.o b57um.c
…
 
□ドライバをカーネルにロード
[root@localhost src]# insmod bcm5700.o

□システムインストール
[root@localhost src]# make install
gzip -c bcm5700.4 > bcm5700.4.gz
 
□NICをデバイス名「eth0」で設定
[root@localhost src]# vi /etc/modules.conf
 ※VIエヂィタの使用方法は別紙参照
設定内容の追加
alias eth0 bcm5700
 
□システム再起動
[root@localhost src]# init 6

□再起動後のファイル設定(「IPアドレス」と「ホスト名」の名前解決用)
[root@localhost root]# vi /etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1 linux14 localhost.localdomain localhost
 
□再起動後のファイル設定(自分から見るホスト名)
[root@localhost root]# vi /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=linux14
 
□IPアドレス、サブネットマスクの確認
[root@localhost root]# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:13:20:58:34:83
          inet addr:172.18.9.114  Bcast:172.18.9.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:84 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:19197 (18.7 Kb)  TX bytes:64 (64.0 b)
          Interrupt:10 Memory:ff7f0000-ff800000
 
lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:2079 errors:0 dropped:0 overruns:0 frame:0
          TX packets:2079 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:213254 (208.2 Kb)  TX bytes:213254 (208.2 Kb)
 
□ネットワーク通信可否の確認
[root@localhost root]# ping 172.18.14.204
PING 172.18.14.204 (172.18.14.204) 56(84) bytes of data.
64 bytes from 172.18.14.204: icmp_seq=0 ttl=63 time=4.02 ms
64 bytes from 172.18.14.204: icmp_seq=1 ttl=63 time=0.318 ms
…
--- 172.18.14.204 ping statistics ---
21 packets transmitted, 21 received, 0% packet loss, time 20040ms
rtt min/avg/max/mdev = 0.259/0.806/6.046/1.433 ms, pipe 2
 
□起動中のサーバの確認?
[root@localhost root]# ps aux
USER       PID %CPU %MEM   VSZ  RSS TTY      STAT START   TIME COMMAND
root         1  0.1  0.0  1508  508 ?        S    15:47   0:03 init
 
root      4624  0.0  0.0  1564  472 ?        S    15:50   0:00 gpm -
 
□ログインIDの確認
[root@localhost root]# pwd
/root
 
□ファイル転送(FTPコマンド使用) ※今回はデータ入手のため
[root@localhost root]# ftp 172.18.14.204
Connected to 172.18.14.204.
220 (vsFTPd 1.2.1)
530 Please login with USER and PASS.
530 Please login with USER and PASS.
KERBEROS_V4 rejected as an authentication type
Name (172.18.14.204:root):
 
Name (172.18.14.204:root): ftp
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
 
ftp> cd pub
250 Directory successfully changed.
ftp> prompt
Interactive mode off.
 
ftp> cd ..
250 Directory successfully changed.
ftp> ls
227 Entering Passive Mode (172,18,14,204,165,154)
150 Here comes the directory listing.
drwxr-xr-x    5 0        0            4096 Nov 16  2005 DOCS_RHEL3
-rw-r--r--    1 0        0          122880 Aug 28  2008 UML13L.tar
drwxr-xr-x    2 0        0            4096 Mar 28 09:26 UMS89L_OLD
-rw-r--r--    1 0        0            3442 Jan 08  2010 check.sh
 
226 Directory send OK.
 
ftp> cd pub-UBS06L
250 Directory successfully changed.
ftp> ls
227 Entering Passive Mode (172,18,14,204,245,248)
150 Here comes the directory listing.
drwxr-xr-x    2 0        0            4096 Jan 24 07:54 RHEL3
drwxr-xr-x    2 0        0            4096 Jan 24 08:00 RHEL5
-rw-rw-rw-    1 0        0           48984 Sep 10  2008 init
226 Directory send OK.
 
ftp> cd RHEL3
250 Directory successfully changed.
ftp> bin
200 Switching to Binary mode.
 
ftp> mget *
local: Hello.java remote: Hello.java
227 Entering Passive Mode (172,18,14,204,161,142)
150 Opening BINARY mode data connection for Hello.java (107 bytes).
226 File send OK.
 
1316612 bytes received in 0.17 seconds (7.4e+03 Kbytes/s)
ftp> by
 
□
[root@localhost root]# ls
アパッチのパッケージ: apache-tomcat-5.5.20.tar.gz
JDK: jdk-1_5_0_11-linux-i586-rpm.bin
postgresql-8.2.3.tar.gz
httpd-2.2.4.tar.gz
tomcat-connectors-1.2.20-src.tar.gz
Hello.java
install.log
anaconda-ks.cfg
install.log.syslog
freemarknans.tgz
 
□システム停止
init 0
 ※PowerOFFのメッセージ表示がされたら、電源のOFFが必要!
 
□登録されているユーザの確認
[root@linux14 root]# vi /etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
 ※LINUXインストール時に自動で作られるユーザ
 
 
□LINUXのパケットフィルタリング機能の設定確認
[root@linux14 root]# iptables -L
外からアクセス:
Chain INPUT (policy ACCEPT)
target     prot opt source               destination
 
自分自身転送で: 
Chain FORWARD (policy ACCEPT)
target     prot opt source               destination
 
自分自身で外に出す:
Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination
 
□<参考>Apacheのコンテンツに対するアクセス権設定
コンテンツの所有者変更(※階層的に処理)chown -R  xxxxx:gggggg /uer/local/apache2/htdocs
コンテンツのアクセス権の設定:
chmod 440 /uer/local/apache2/htdocs/*
 
?Apacheのインストール作業?
□Apacheの圧縮ファイルの展開(解凍)
[root@linux14 root]# tar zxvf httpd-2.2.4.tar.gz -C /usr/local/src
…
httpd-2.2.4/Apache.dsw
httpd-2.2.4/LICENSE
httpd-2.2.4/Makefile.in
httpd-2.2.4/config.layout
httpd-2.2.4/INSTALL
 
□移動
[root@linux14 root]# cd /usr/local/src/httpd-2.2.4/
[root@linux14 httpd-2.2.4]# ls
ABOUT_APACHE    LICENSE           ROADMAP           configure     libhttpd.dsp
Apache.dsw      Makefile.in       VERSIONING        configure.in  modules
BuildBin.dsp    Makefile.win      acinclude.m4      docs          os
CHANGES         NOTICE            apachenw.mcp.zip  emacs-style   server
INSTALL         NWGNUmakefile     build             httpd.dsp     srclib
InstallBin.dsp  README            buildconf         httpd.spec    support
LAYOUT          README.platforms  config.layout     include       test
 
□Apache用のMakefileの作成
[root@linux14 httpd-2.2.4]# ./configure
…
config.status: creating build/pkg/pkginfo
config.status: creating build/config_vars.sh
config.status: creating include/ap_config_auto.h
config.status: executing default commands
 
□Apache用のコンパイル
[root@linux14 httpd-2.2.4]# make
Making all in srclib
make[1]: 入ります ディレクトリ `/usr/local/src/httpd-2.2.4/srclib'
Making all in apr
…
/usr/local/src/httpd-2.2.4/srclib/apr/libtool --silent --mode=link gcc -g -O2 -pthread        -o httpd  modules.lo buildmark.o -export-dynamic server/libmain.la modules/aaa/libmod_authn_file.la modules
…
make[1]: 出ます ディレクトリ `/usr/local/src/httpd-2.2.4'
 
□Apache用のインストール
[root@linux14 httpd-2.2.4]# make install
Making install in srclib
make[1]: 入ります ディレクトリ `/usr/local/src/httpd-2.2.4/srclib'
Making install in apr
…
mkdir /usr/local/apache2/man/man8
mkdir /usr/local/apache2/manual
make[1]: 出ます ディレクトリ `/usr/local/src/httpd-2.2.4'
 
□移動&Apache設定ファイルのバックアップ
[root@linux14 httpd-2.2.4]# cd /usr/local/apache2/conf/
[root@linux14 conf]# cp httpd.conf httpd.conf.bk
 
□Apache設定ファイルの確認&設定
[root@linux14 conf]# vi httpd.conf
 
ServerRoot "/usr/local/apache2"
 
Listen 80
 
User daemon
Group daemon
 
ServerAdmin [email protected]
ServerName linux14:80
 
DocumentRoot "/usr/local/apache2/htdocs"
 
<Directory />
    Options FollowSymLinks
    AllowOverride None
    Order deny,allow
    Deny from all
</Directory>
 
 
<IfModule dir_module>
    DirectoryIndex index.html
</IfModule>
 
<FilesMatch "^\.ht">
    Order allow,deny
    Deny from all
    Satisfy All
</FilesMatch>
 
 <VirtualHost>
# container, that host's errors will be logged there and not here.
#
ErrorLog logs/error_log
 
# LogLevel: Control the number of messages logged to the error_log.
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
#
LogLevel warn
 
<Directory "/usr/local/apache2/cgi-bin">
    AllowOverride None
    Options None
    Order allow,deny
    Allow from all
</Directory>
 
DefaultType text/plain
 
    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz
 
<IfModule ssl_module>
SSLRandomSeed startup builtin
SSLRandomSeed connect builtin
</IfModule>
 
# Server-pool management (specific)
Include conf/extra/httpd-mpm.conf
 
 
□最大接続数「httpd-mpm.conf」ファイルの確認&設定
[root@linux14 apache2]# vi /usr/local/apache2/conf/extra/httpd-mpm.conf
 
<IfModule mpm_prefork_module>
    StartServers          5
    MinSpareServers       5
    MaxSpareServers      10
    MaxClients          150
    MaxRequestsPerChild   0
</IfModule>
 
□Apacheの起動
[root@linux14 apache2]# /usr/local/apache2/bin/apachectl start
 
□Apacheの起動確認
[root@linux14 apache2]# ps aux | grep httpd
root     24165  0.0  0.0  3576 1696 ?        S    13:04   0:00 /usr/local/apache2/bin/httpd -k start
daemon   24166  0.0  0.0  3568 1696 ?        S    13:04   0:00 /usr/
 
□ブラウザを使用して以下のURLでアクセス確認
http://localhost/
 
□Apacheの停止
[root@linux14 apache2]# /usr/local/apache2/bin/apachectl stop
[root@linux14 apache2]# ps aux | grep httpd
root     24205  0.0  0.0  4668  684 pts/0    S    13:09   0:00 grep httpd
 
□Apacheのフォルダ構成
[root@linux14 httpd-2.2.4]# cd /usr/local/apache2/
[root@linux14 apache2]# ls
bin
cgi-bin
error
icons
lib
man
modules
build
conf
htdocs
include
logs
manual
 
?APサーバの構築(JDK、TOMCAT)?
□JDKパッケージファイルの作成
※先にファイルに実行権を与える
[root@linux14 root]# chmod u+x jdk-1_5_0_11-linux-i586-rpm.bin
 
Do you agree to the above license terms? [yes or no]
yes
Unpacking...
Checksumming...
0
0
Extracting...
UnZipSFX 5.42 of 14 January 2001, by Info-ZIP ([email protected]).
  inflating: jdk-1_5_0_11-linux-i586.rpm
Preparing...                ########################################### [100%]
   1:jdk                    ########################################### [100%]
 
Done.
 
□一般ユーザ(root含む)の環境変数の変更
[root@linux14 root]# vi /etc/profile
※最終行に「JDK用のコマンド」が使用できるように以下を追加
export JAVA_HOME=/usr/java/jdk1.5.0_11
export PATH=$PATH:$JAVA_HOME/bin
 
□JAVAファイルのコンパイル確認&実行
[root@linux14 root]# javac Hello.java
 
[root@linux14 root]# ls Hello.class
Hello.class
 
[root@linux14 root]# java Hello
Hello !!!
 
[root@linux14 root]# less Hello.java
public class Hello {
  public static void main(String[] args) {
    System.out.println("Hello !!!");
  }
}
 
?TOMCATのインストール、環境設定?
□ユーザ追加
[root@linux14 root]# useradd postgres
 
□TOMCATファイル(圧縮版)の解凍
[root@linux14 root]# tar zxvf apache-tomcat-5.5.20.tar.gz -C /usr/local/
 ※「ーC」オプションで展開先の指定
 
□TOMCATインストール先ディレクトリの所有者の変更
[root@linux14 root]# cd /usr/local/
[root@linux14 local]# chown -R postgres:postgres apache-tomcat-5.5.20
 ※「ーR」オプションで指定した階層全てを処理
 
□展開したディレクトリに「tomcat」シンボリックリンクを作成
[root@linux14 local]# ln -s apache-tomcat-5.5.20 tomcat
 
□「postgres」ユーザ用の環境変数の設定
[root@linux14 local]# su - postgres
[postgres@linux14 postgres]$ vi .bashrc
 
export CATALINA_HOME=/usr/local/tomcat
export PATH=$PATH:$CATALINA_HOME/bin
export CLASSPATH=$CATALINA_HOME/common/lib/servlet-api.jar
 
□「postgres」ユーザ用の環境変数の反映
[postgres@linux14 postgres]$ exit
logout
 
[root@linux14 local]# su - postgres
[postgres@linux14 postgres]$
 
□TOMCATのコマンド起動確認
[postgres@linux14 postgres]$ startup.sh
Using CATALINA_BASE:   /usr/local/tomcat
Using CATALINA_HOME:   /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME:       /usr/java/jdk1.5.0_11
 
□ブラウザでTOMCAT用サンプルページの確認
http://localhost:8080/
 
http://localhost:8080/aaa
→「HTTPステータス 404 - /aaa」のエラー表示
 
□TOMCATのコマンド停止確認
[postgres@linux14 postgres]$ shutdown.sh
Using CATALINA_BASE:   /usr/local/tomcat
Using CATALINA_HOME:   /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME:       /usr/java/jdk1.5.0_11
 
□TOMCATインストール後のディレクトリ構成の確認
[postgres@linux14 local]$ ls tomcat/
bin…Tomocatに添付される実行プログラムが格納される
conf…TOMCAT専用の環境設定ファイルが格納
common…ライブラリやクラスが格納
logs…ログファイルが格納
shared…全てのアプリケーションで共有されるライブラリやクラスが格納
server…ライブラリやクラスが格納
webapps…アプリケーションコンテンツが格納
work…一時ファイルを格納
temp
LICENSE
RELEASE-NOTES
NOTICE
RUNNING.txt
 
?ApacheとTOMCATの接続連携確認?
□TOMCAT側の連携モジュール「mod_jk」の解凍
[root@linux14 root]# ls
Hello.class                  install.log
Hello.java                   install.log.syslog
anaconda-ks.cfg              jdk-1_5_0_11-linux-i586-rpm.bin
apache-tomcat-5.5.20.tar.gz  jdk-1_5_0_11-linux-i586.rpm
freemarknans.tgz             postgresql-8.2.3.tar.gz
httpd-2.2.4.tar.gz           tomcat-connectors-1.2.20-src.tar.gz
[root@linux14 root]# tar zxvf tomcat-connectors-1.2.20-src.tar.gz -C /usr/local/src/
 
□コンパイル用「configure」ファイルの作成
[root@linux14 root]# cd /usr/local/src/tomcat-connectors-1.2.20-src/native/
[root@linux14 native]# ls
BUILDING     NEWS        aclocal.m4    common        iis         scripts
CHANGES      README      apache-1.3    configure     jni
Makefile.am  STATUS.txt  apache-2.0    configure.in  netscape
Makefile.in  TODO        buildconf.sh  docs          nt_service
 
[root@linux14 native]# ./buildconf.sh
rm autom4te.cache
libtoolize --force --automake --copy
aclocal
autoheader
automake -a --foreign --copy
configure.in:8: `automake requires `AM_CONFIG_HEADER', not `AC_CONFIG_HEADER'
configure.in: installing `scripts/build/unix/mkinstalldirs'
autoconf
rm autom4te.cache
 
□Apacheに連携モジュールを組み込むためMakefileの作成
[root@linux14 native]# ./configure --with-apxs=/usr/local/apache2/bin/apxs
 ※「apache2/bin/apxs」は拡張ツール
 
□連携モジュールのコンパイル
[root@linux14 native]# make
 
□連携モジュールのインストール
[root@linux14 native]# make install
 
□インストール済みの連携モジュールの確認
[root@linux14 native]# ls /usr/local/apache2/modules/
httpd.exp  mod_jk.so
 
□連携モジュール用の設定ファイルをApache用ディレクトリ配下へコピー
[root@linux14 native]# cd ../conf/
[root@linux14 conf]# ls
uriworkermap.properties  workers.properties  workers.properties.minimal
[root@linux14 conf]# cp workers.properties /usr/local/apache2/conf/
 
□Apacheの設定ファイルに連携モジュールを設定
[root@linux14 conf]# vi /usr/local/apache2/conf/httpd.conf
…
LoadModule jk_module modules/mod_jk.so  ※Apache起動時に連携モジュールを組み込む設定
JkMount /*.jsp ajp13 ※ApacheとTomcatの連携時にアプリケーションを読み込むためのURL指定
 
□Apacheの設定ファイルに連携先(APサーバ側)の「JDK」「Tomcat」を設定
[root@linux14 conf]# vi /usr/local/apache2/conf/workers.properties
…
#
# workers.tomcat_home should point to the location where you
# installed tomcat. This is where you have your conf, webapps and lib
# directories.
#
workers.tomcat_home=/usr/local/tomcat
 
#
# workers.java_home should point to your Java installation. Normally
# you should have a bin and lib directories beneath it.
#
workers.java_home=/usr/java/jdk1.5.0_11
 
 
□TOMCATの設定ファイルのバックアップ
[root@linux14 conf]# cd /usr/local/tomcat/conf/
[root@linux14 conf]# cp server.xml server.xml.bk
[root@linux14 conf]# cp web.xml web.xml.bk
 
[root@linux14 conf]# ls
Catalina             context.xml         server.xml        web.xml
catalina.policy      logging.properties  server.xml.bk     web.xml.bk
catalina.properties  server-minimal.xml  tomcat-users.xml
 
□TOMCAT側の設定ファイルの編集
[root@linux14 conf]# su - postgres
[postgres@linux14 postgres]$ vi /usr/local/tomcat/conf/server.xml
 
※TOMCATのWEBサーバ機能の停止(8080ポートの無効化)
<!--
    <Connector port="8080" maxHttpHeaderSize="8192"
               maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
               enableLookups="false" redirectPort="8443" acceptCount="100"
               connectionTimeout="20000" disableUploadTimeout="true" />
-->
 
※(Apache側からの)同時アクセス数の設定
<!-- Define an AJP 1.3 Connector on port 8009 -->
    <Connector port="8009"
               maxThreads="120" minSpareThreads="25" maxSpareThreads="100"
               enableLookups="false" redirectPort="8443" protocol="AJP/1.3" />
 
※maxThreads="120"…同時処理スレッドの最大数
※minSpareThreads="25" …待機スレッド数の最小値
※maxSpareThreads="100"…待機スレッド数の最大値
 
□設定値を有効にするための再ログイン
□Apacheの起動確認
[root@linux14 root]# /usr/local/apache2/bin/apachectl start
 
[root@linux14 root]# ps aux | grep httpd
root     29981  0.0  0.0  3832 1944 ?        S    17:16   0:00 /usr/local/apache2/bin/httpd -k start
daemon   29982  0.0  0.0  3832 1940 ?        S    17:16   0:00 /usr/
 
□TOMCAT起動ユーザ「postgres」に変更し、TOMCATの起動
[root@linux14 root]# su - postgres
[postgres@linux14 postgres]$ startup.sh
Using CATALINA_BASE:   /usr/local/tomcat
Using CATALINA_HOME:   /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME:       /usr/java/jdk1.5.0_11
 
□ブラウザよりApacheとTOMCATの接続連携の確認
http://localhost:8080/ →アクセス拒否OK
http://localhost/index.jsp →アクセス確認OK
 
□TOMCATの停止
[postgres@linux14 postgres]$ shutdown.sh
Using CATALINA_BASE:   /usr/local/tomcat
Using CATALINA_HOME:   /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME:       /usr/java/jdk1.5.0_11
 
※TOMCATユーザ「postgres」ではApacheの停止が出来ない
[postgres@linux14 postgres]$ /usr/local/apache2/bin/apachectl stop
httpd (pid 29981?) not running
 
[postgres@linux14 postgres]$ exit
logout
 
□Apacheの停止
[root@linux14 root]# /usr/local/apache2/bin/apachectl stop
[root@linux14 root]# ps aux | grep httpd
root     30198  0.0  0.0  4680  684 pts/0    S    17:30   0:00 grep httpd
 
 
?DBサーバの構築(PostgresSQLのインストール)?
□POSTGRES-SQLのインストール用ディレクトリの作成&所有者変更
[root@linux14 root]# mkdir /usr/local/pgsql
 
[root@linux14 root]# chown postgres:postgres /usr/local/pgsql/
 
□PostgresSQLの圧縮ファイルを指定したディレクトリへ解凍
[root@linux14 root]# tar zxvf postgresql-8.2.3.tar.gz -C /usr/local/src/
[root@linux14 root]# ls /usr/local/src/
httpd-2.2.4  postgresql-8.2.3  tomcat-connectors-1.2.20-src
 
□ファイルを解凍した後に生成されたディレクトリの所有者変更&移動
[root@linux14 root]# chown -R postgres:postgres /usr/local/src/postgresql-8.2.3/                                                                                
[root@linux14 root]# su - postgres
[postgres@linux14 postgres]$ cd /usr/local/src/postgresql-8.2.3/
[postgres@linux14 postgresql-8.2.3]$ ls
COPYRIGHT       HISTORY  Makefile  aclocal.m4  configure     contrib  src
GNUmakefile.in  INSTALL  README    config      configure.in  doc
 
□PostgresSQLをコンパイル&インストール用のMakefileを作成
  ※利用しているOSに的したMakefileの作成を行う
[postgres@linux14 postgresql-8.2.3]$ ./configure
checking build system type... i686-pc-linux-gnu
checking host system type... i686-pc-linux-gnu
checking which template to use... linux
checking whether to build with 64-bit integer date/time support... no
checking whether NLS is wanted... no
checking for default port number... 5432
checking for gcc... gcc
checking for C compiler default output file name...
…
 
□PostgresSQLのコンパイル
[postgres@linux14 postgresql-8.2.3]$ make all
make -C doc all
make[1]: 入ります ディレクトリ `/usr/local/src/postgresql-8.2.3/doc'
gzip -d -c man.tar.gz | /bin/tar xf -
for file in man1/*.1; do \
  mv $file $file.bak && \
  sed -e 's/\\fR(l)/\\fR(7)/' $file.bak >$file && \
  rm -f $file.bak || exit; \
done
/bin/sh ../config/mkinstalldirs man7
…
make[1]: 出ます ディレクトリ `/usr/local/src/postgresql-8.2.3/config'
All of PostgreSQL successfully made. Ready to install.
 
※なんとなく確認
[postgres@linux14 postgresql-8.2.3]$ ls
COPYRIGHT       HISTORY   README      config.log     configure.in  src
GNUmakefile     INSTALL   aclocal.m4  config.status  contrib
GNUmakefile.in  Makefile  config      configure      doc
 
□PostgresSQLのインストール
[postgres@linux14 postgresql-8.2.3]$ make install
make -C doc install
make[1]: 入ります ディレクトリ `/usr/local/src/postgresql-8.2.3/doc'
mkdir -p -- /usr/local/pgsql/doc/html
mkdir -p -- /usr/local/pgsql/man/man1 /usr/local/pgsql/man/man7
gzip -d -c ./postgres.tar.gz | ( cd /usr/local/pgsql/doc/html && /bin/tar xf - )for file in man1/*.1 man7/*.7 ; do \
  /bin/sh ../config/install-sh -c -m 644 $file /usr/local/pgsql/man/$file || exit; \
…
ake[1]: 出ます ディレクトリ `/usr/local/src/postgresql-8.2.3/config'
PostgreSQL installation complete.
 
※なんとなく確認
[postgres@linux14 postgresql-8.2.3]$ ls
COPYRIGHT       HISTORY   README      config.log     configure.in  src
GNUmakefile     INSTALL   aclocal.m4  config.status  contrib
GNUmakefile.in  Makefile  config      configure      doc
 
□PostgresSQLのマニュアルインストール
[postgres@linux14 postgresql-8.2.3]$ cd doc/
[postgres@linux14 doc]$ make install
gzip -d -c ./postgres.tar.gz | ( cd /usr/local/pgsql/doc/html && /bin/tar xf - )for file in man1/*.1 man7/*.7 ; do \
  /bin/sh ../config/install-sh -c -m 644 $file /usr/local/pgsql/man/$file || exit; \
done
 
※なんとなく確認
[postgres@linux14 doc]$ ls
FAQ         FAQ_SCO        FAQ_german     MISSING_FEATURES  man.tar.gz
FAQ_AIX     FAQ_Solaris    FAQ_hungarian  Makefile          man1
FAQ_CYGWIN  FAQ_brazilian  FAQ_japanese   README.mb.big5    man7
FAQ_DEV     FAQ_chinese    FAQ_polish     README.mb.jp      manl
FAQ_HPUX    FAQ_czech      FAQ_russian    TODO              postgres.tar.gz
FAQ_IRIX    FAQ_farsi      FAQ_turkish    TODO.detail       src
FAQ_MINGW   FAQ_french     KNOWN_BUGS     bug.template
 
□「postgres」ユーザで環境変数の編集
[postgres@linux14 postgres]$ pwd
/home/postgres
[postgres@linux14 postgres]$ vi .bashrc
…
# .bashrc
 
# User specific aliases and functions
 
# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi
export CATALINA_HOME=/usr/local/tomcat
export PATH=$PATH:$CATALINA_HOME/bin
export CLASSPATH=$CATALINA_HOME/common/lib/servlet-api.jar
 
export POSTGRES_HOME=/usr/local/pgsql
export PGDATA=$POSTGRES_HOME/data
export PGLIB=$POSTGRES_HOME/lib
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$PGLIB
export PATH=$PATH:$POSTGRES_HOME/bin
export MANPATH=$MANPATH:$POSTGRES_HOME/man
 
※環境変数の捕捉説明
POSTGRES_HOME…PostgreSQLをインストールをしたディレクトリの指定
PGDATA…データベース用のディレクトリの指定
PGLIB…PostgreSQLのライブラリがインストールをしたディレクトリの指定
LD_LIBRARY_PATH…PostgreSQLがライブラリを検索するディレクトリの指定
PATH…PostgreSQLがコマンドを検索するディレクトリの指定
MANPATH…manコマンドでマニュアルを検索するディレクトリの指定
 
□データベースの初期化
[postgres@linux14 doc]$ exit
logout
[root@linux14 root]# su - postgres
 
[postgres@linux14 postgres]$ initdb
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.
The database cluster will be initialized with locale ja_JP.eucJP.
The default database encoding has accordingly been set to EUC_JP.
creating directory /usr/local/pgsql/data ... ok
…
 
□PostgresSQLの設定ファイルのバックアップ
[postgres@linux14 postgres]$ cd /usr/local/pgsql/data/
[postgres@linux14 data]$ ls
PG_VERSION  global   pg_hba.conf    pg_multixact  pg_tblspc    pg_xlog
base        pg_clog  pg_ident.conf  pg_subtrans   pg_twophase  postgresql.conf
[postgres@linux14 data]$ cp postgresql.conf postgresql.conf.bk
 
□PostgresSQLの設定ファイルの編集
[postgres@linux14 data]$ vi postgresql.conf
…
listen_addresses = 'localhost,172.18.9.114'             # what IP address(es) to listen on;
…
port = 5432                             # (change requires restart)
max_connections = 100                   # (change requires restart)
…
shared_buffers = 24MB                   # min 128kB or max_connections*16kB
 
□
[postgres@linux14 data]$ exit
logout
 
[root@linux14 root]# su - postgres
[postgres@linux14 postgres]$
 
□Postgresデータベースの起動
[postgres@linux14 postgres]$ pg_ctl start
server starting
[postgres@linux14 postgres]$ LOG:  database system was shut down at 2011-06-15 11:09:47 JST
LOG:  checkpoint record is at 0/42C210
LOG:  redo record is at 0/42C210; undo record is at 0/0; shutdown TRUE
LOG:  next transaction ID: 0/593; next OID: 10820
LOG:  next MultiXactId: 1; next MultiXactOffset: 0
LOG:  database system is ready
 
 
□test用データベースの作成
[postgres@linux14 postgres]$ createdb -E EUC_JP testdb
CREATE DATABASE
 
□test用データベースへの接続&テーブル作成確認
[postgres@linux14 postgres]$ psql testdb
Welcome to psql 8.2.3, the PostgreSQL interactive terminal.
 
Type:  \copyright for distribution terms
       \h for help with SQL commands
       \? for help with psql commands
       \g or terminate with semicolon to execute query
       \q to quit
 
testdb=# CREATE TABLE test_table(
no integer not null,
name varchar(20),
id   varchar(1));
CREATE TABLE
 
testdb=# INSERT INTO test_table VALUES (
testdb(# 1,
testdb(# 'テスト用',
testdb(# 1);
INSERT 0 1
 
testdb=# SELECT * from test_table ;
 no |   name   | id
----+----------+----
  1 | テスト用 | 1
(1 row)
 
testdb=# \q
 
□データベースの停止
[postgres@linux14 postgres]$ pg_ctl stop
waiting for server to shut down....LOG:  received smart shutdown request
LOG:  shutting down
LOG:  database system is shut down
 done
server stopped
 
□PostgresSQLのディレクトリ構成
[root@linux14 root]# ls /usr/local/pgsql/
data…
 →base…
 →global…
 →pg_xlog…
 →pg_clog…
 →postgresql.conf…PostgresSQLの設定(ユーザ、接続IP、接続数、バッファサイズ、ログ)
 →postgresql.conf.bk…
 →pg_hba.conf…PostgresSQLへのアクセス制限
 →PG_VERSION…
 →pg_multixact…
 →pg_twophase…
 →pg_subtrans…
 →postmaster.opts…
 →pg_ident.conf…
 →pg_tblspc…
bin…
doc…
include…
lib…
man…
share…
 
?WEB/AP/DBサーバの連携テスト?
□サンプルプログラムの解凍展開
[root@linux14 root]# tar zxvf freemarknans.tgz -C /home/postgres
 
※DBサーバに関する作業
□データベースの起動
[root@linux14 root]# su - postgres
[postgres@linux14 postgres]$ pg_ctl start
server starting
[postgres@linux14 postgres]$ LOG:  database system was shut down at 2011-06-15 11:26:06 JST
LOG:  checkpoint record is at 0/43E2C8
LOG:  redo record is at 0/43E2C8; undo record is at 0/0; shutdown TRUE
LOG:  next transaction ID: 0/602; next OID: 16387
LOG:  next MultiXactId: 1; next MultiXactOffset: 0
LOG:  database system is ready
 
□テスト用テーブルの作成 ※サンプルSQLを実行
[postgres@linux14 postgres]$ psql -f createtable.sql testdb
ERROR:  index "madidx" does not exist
STATEMENT:  drop index madidx;
psql:createtable.sql:1: ERROR:  index "madidx" does not exist
ERROR:  table "stock" does not exist
STATEMENT:  drop table stock;
…
 
※APサーバに関する作業
□サンプルアプリケーション用データのTOMCAT配下のWEBAPPSに配置
[postgres@linux14 postgres]$ cp -r freemarknans  /usr/local/tomcat/webapps/
 
□データベースアクセス用JDBCドライバの導入
[postgres@linux14 postgres]$ cp postgresql-8.2-504.jdbc3.jar /usr/local/tomcat/webapps/freemarknans/WEB-INF/lib/
 
□サンプルアプリケーションにDBサーバのIPアドレスを設定
[postgres@linux14 postgres]$ vi /usr/local/tomcat/webapps/freemarknans/WEB-INF/classes/market/dao/DB.properties
…
DRIVERNAME=org.postgresql.Driver
URL=jdbc:postgresql://localhost:5432/testdb
USER=postgres
 
□WEBサーバ(Apache)側の設定ファイル(連携モジュール)に連携させるサンプルプログラムを設定
[postgres@linux14 postgres]$ exit
logout
 
[root@linux14 root]# vi /usr/local/apache2/conf/httpd.conf
…
LoadModule jk_module modules/mod_jk.so
JkMount /*.jsp ajp13
JkMount /freemarknans/* ajp13
 
□WEBサーバ(Apache)の起動
[root@linux14 root]# /usr/local/apache2/bin/apachectl start
[root@linux14 root]# ps aux | grep httpd
root     18418  0.0  0.0  3820 1940 ?        S    13:33   0:00 /usr/local/apache2/bin/httpd -k start
daemon   18419  0.0  0.0  3820 1936 ?        S    13:33   0:00 /usr/local/apache2/bin/httpd -k start
daemon   18420  0.0  0.0  3820 1936 ?        S    13:33   0:00 /usr/local/apache2/bin/httpd -k start
daemon   18421  0.0  0.0  3820 1936 ?        S    13:33   0:00 /usr/local/apache2/bin/httpd -k start
daemon   18422  0.0  0.0  3820 1936 ?        S    13:33   0:00 /usr/local/apache2/bin/httpd -k start
daemon   18423  0.0  0.0  3820 1936 ?        S    13:33   0:00 /usr/local/apache2/bin/httpd -k start
root     18425  0.0  0.0  4684  688 pts/0    S    13:33   0:00 grep httpd
 
□APサーバ(Tomcat)の起動
[root@linux14 root]# su - postgres
 
[postgres@linux14 postgres]$ startup.sh
Using CATALINA_BASE:   /usr/local/tomcat
Using CATALINA_HOME:   /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME:       /usr/java/jdk1.5.0_11
 
□ブラウザで接続確認
http://localhost/freemarknans/jsp/index.html
※「WEB-SV」→「AP-SV」→「DB-SV」への接続
 
 
?データのバックアップ&リストア(Postgres提供用、OS:Linux提供用)?
□接続先デバイスの事前確認
[postgres@linux14 postgres]$ df -k
Filesystem           1K-ブロック    使用   使用可 使用% マウント位置
/dev/hda2              5162828   2388452   2512116  49% /
/dev/hda1               101089     14768     81102  16% /boot
/dev/hda8              3099260     32828   2909000   2% /data
/dev/hda5              5162796     36952   4863588   1% /home
none                   1026388         0   1026388   0% /dev/shm
/dev/hda7              5162796    377244   4523296   8% /usr/local
/dev/hda6              5162796     92624   4807916   2% /var
 
□対象ファイルとバックアップファイル名
バックアップ対象DB:testdb
バックアップファイル名:testdb.bkup
 
□データベースの起動
[postgres@linux14 postgres]$ pg_ctl start
server starting
[postgres@linux14 postgres]$ LOG:  database system was shut down at 2011-06-15 14:16:02 JST
LOG:  checkpoint record is at 0/480080
LOG:  redo record is at 0/480080; undo record is at 0/0; shutdown TRUE
LOG:  next transaction ID: 0/901; next OID: 16432
LOG:  next MultiXactId: 1; next MultiXactOffset: 0
LOG:  database system is ready
 
□Postgres提供用バックアップコマンド
[postgres@linux14 postgres]$ pg_dump -U postgres -f testdb.bkup testdb
※「-U」指定ユーザで接続、「-f」指定ファイルで出力
 
[postgres@linux14 postgres]$ ls
createtable.sql  freemarknans  postgresql-8.2-504.jdbc3.jar  testdb.bkup
 
□Postgres提供用リストアコマンド
※一旦DB削除
[postgres@linux14 postgres]$ dropdb -U postgres testdb
DROP DATABASE
 
※その後、復元先DBの作成
[postgres@linux14 postgres]$ createdb -E EUC_JP -U postgres testdb
CREATE DATABASE
 
※復元先DBに接続し、データ存在しないことを確認
[postgres@linux14 postgres]$ psql testdb
Welcome to psql 8.2.3, the PostgreSQL interactive terminal.
Type:  \copyright for distribution terms
       \h for help with SQL commands
       \? for help with psql commands
       \g or terminate with semicolon to execute query
       \q to quit
testdb=# \d
No relations found.
testdb=# \q
 
※バックアップしたデータベースをリストア(復元)
[postgres@linux14 postgres]$ psql -d testdb -f testdb.bkup
 
※バックアップ後のデータベースの確認
[postgres@linux14 postgres]$ psql testdb
Welcome to psql 8.2.3, the PostgreSQL interactive terminal.
Type:  \copyright for distribution terms
       \h for help with SQL commands
       \? for help with psql commands
       \g or terminate with semicolon to execute query
       \q to quit
testdb=# \d
             List of relations
 Schema |    Name    |   Type   |  Owner
--------+------------+----------+----------
 public | category   | table    | postgres
 public | member     | table    | postgres
 public | membernum  | sequence | postgres
 public | ordernum   | sequence | postgres
 public | orders     | table    | postgres
 public | product    | table    | postgres
 public | stock      | table    | postgres
 public | test_table | table    | postgres
(8 rows)
 
 
□OS:Linux提供用バックアップコマンド
対象パーティション:「/usr/local/」=「/dev/hda7/」
 
□バックアップ対象DBの停止
[postgres@linux14 postgres]$ pg_ctl stop
waiting for server to shut down....LOG:  received smart shutdown request
LOG:  shutting down
LOG:  database system is shut down
 done
server stopped
 
□シングルユーザモードへ切替え
[root@linux14 root]# init 1
 ※「GUI画面」から「CUI画面」へ移行するためメモ不可
 
□
 
□
 
□
 
□
*********************************
□Linuxコマンド例
パッケージ関連のコマンド:rpm
パッケージインストール:rpm -ivh flm-1.2.3-4.i386.rpm
パッケージ確認:rpm -qa
パッケージ削除:rpm -e telnet-server
パッケージ更新:rpm -Uvh vsftpd-xxxx
パッケージ内ファイル一覧(DBから):rpm -ql flm
パッケージ情報表示(ファイルから):rpm -qlp flm-1.2.3-4.i386.rpm
 
ソースコードの展開:tar xvfz ファイル名
 
コンパイラやライブラリなどのコンパイル環境のCKとMakefileの作成:.configure
コンパイル:make
インストール:make install
 
LINUXユーザアカウントの削除:userdel -r xxx
LINUXユーザアカウントのパスワード有効期限設定:passwd -x 30 xxx
LINUXユーザアカウントのパスワード変更禁止期間:passwd -n 30 xxx
LINUXユーザアカウントのパスワード警告msg表示 :passwd -w 30 xxx
 
現在起動中のプロセス一覧の表示:ps
a…自分以外が実行したプロセスも表示
u…実行したユーザ名、CPUやメモリ使用率、開始時刻等も表示
x…制御端末のないプロセス(デーモン等)の情報も表示
 
全配下のフォルダ&ファイルの一覧表示: ls -R | grep httpd-mpm
 
環境設定ファイルも一覧表示: ls -a
 
環境設定値の表示確認: set
BASH=/bin/bash
BASH_ENV=/root/.bashrc
…
 
環境設定値の表示確認:echo $PATH
/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/root/bin
 
ファイル等の検索:which ls
alias ls='ls --color=tty'        /bin/ls
 
環境変数の追加:PATH=$PATH:$HOME ※指定の仕方に注意する事]
 
ファイル名の検索: find . -name index.jsp -print
 
LINUX提供バックアップコマンド(フォルダorファイル単位):※バックアップ&リストア両方
tar オプション アーカイブ名 バックアップ対象     
※オプション解説…[x][t][c]は同時否定負荷
x…解凍/展開する
t…一覧表示
c…アーカイブファイルを作成
v…実行過程を表示
f…アーカイブファイル名
z…圧縮/解凍
 
LINUX提供バックアップコマンド(パーティション単位):dump ※サービスの停止が必須
↓
1シングルユーザモードへの移行:「inti 1」
2アンマウントとファイルシステムCK:「umount /home; fsck -aV /dev/hda6」
3カートリッジテープにデータ退避:
「dump 0ut /def/st0 /dev/hda6」…[0]はフルダンプ
「dump 5ut /def/st0 /dev/hda6」…[5]は一週間分の増分ダンプ
「dump 9ut /def/st0 /dev/hda6」…[9]は9より低い値ところからの増分ダンプ
「dump 9ut /def/nst0 /dev/hda6」…[nst0]はテープの巻き戻し無し
※「df」コマンドで接続先を確認
 
LINUX提供リストアコマンド(パーティション単位):restore
例
「restore tf /dev/st0」テープ上の全てのダンプファイルを表示
「restore rf /dev/st0」フルリストア
「restore xf /dev/st0 ./user00」任意のファイルのリストア
「restore if /dev/st0」対話的にファイルのリストア
最終更新:2011年06月16日 22:45