CentOS+基本服務安裝程序

1 安裝 CentOS 作業系統

  1. CentOS 4.2 ServerCD 安裝 ← 後面將透過 yum update 升級至 CentOS 4 的最新版1)
  2. Language Selection : Chinese(Traditional) 繁體中文
  3. 鍵盤設定 : 美式英文
  4. 安裝類型 : 伺服器(S)
  5. 選擇磁碟分割方式 : 自動分割磁碟(A)
  6. 網路設定 :
    1. 開機時立即啟動 [v]
    2. 指定 IP/netmask
    3. 指定 Gateway / DNS
  7. 防火牆設定 :
    1. 啟用防火牆(E)

      [v] 遠端登入(SSH)

      [v] 網頁伺服器 (HTTP, HTTPS)

    2. 啟用 SELinux

      警告(安裝之後如果要更改 SELinux 的設定, 可編輯 /etc/selinux/config 然後 reboot 讓設定生效)

  8. 時區選擇 : 亞洲/台北
  9. 選擇最小化安裝
  10. 安裝完成後會自動退出 CD, 然後重新啟動進入 CentOS
啟用 SELinux : 警告 並非預設值, 所以常常會出現這部份沒設正確的狀況!!!

1.1 確認 CentOS 安裝完成

  1. 建立備援 root 帳號(Exp. misadm)
  2. 建立登入帳號 (Exp. jonathan)
  3. 網路可否正常運作 (ssh 到外部主機, 然後再 ssh 回來)

1.2 更新 CentOS 版本作業

  1. 使用 root 身分登入主機
  2. 安裝 yum 更新套件
  3. 使用 yum 更新到最新版本
  4. 重新啟動電腦讓新版的 kernel 生效

實際執行語法

如果之後要直接升級成 CentOS 5 記得先將 yum-plugin-fastestmirror 移除

rpm -e yum-plugin-fastestmirror

如果安裝 32bit 版本, 雖然主機記憶體安裝超過 4G, 實際抓到記憶體會出現大概 3G 多..
所以必須安裝 kernel-PAE 的 Kernel 版本 (就是之前的 kernel-hugemem)

yum install kernel-PAE

安裝之後, 再更改 /etc/grub.conf 內的開機預設版本 default 值. Exp.

:
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS (2.6.18-53.1.14.el5PAE)
        root (hd0,0)
        kernel /vmlinuz-2.6.18-53.1.14.el5PAE ro root=LABEL=/ rhgb quiet
        initrd /initrd-2.6.18-53.1.14.el5PAE.img
title CentOS (2.6.18-53.1.14.el5)
        root (hd0,0)
        kernel /vmlinuz-2.6.18-53.1.14.el5 ro root=LABEL=/ rhgb quiet
        initrd /initrd-2.6.18-53.1.14.el5.img
title CentOS (2.6.18-53.el5)
:

1.3 安裝其餘系統管理套件

yum install -y iptraf sysstat net-snmp mrtg

2 設定 snmp agent

su - root
cd /etc/snmp
vi snmpd.conf

編輯 snmpd.conf

com2sec notConfigUser  default       public

group   notConfigGroup v1           notConfigUser
group   notConfigGroup v2c           notConfigUser

view    systemview    included   .1.3.6.1.2.1.2
view    systemview    included   .1.3.6.1.2.1.1
view    systemview    included   .1.3.6.1.2.1.25.1.1
view    systemview    included   .1.3.6.1.2.1.2.2.1

access  notConfigGroup ""      any       noauth    exact  systemview none none

syslocation Unknown (edit /etc/snmp/snmpd.conf)
syscontact Root <root@localhost> (configure /etc/snmp/snmp.local.conf)

pass .1.3.6.1.4.1.4413.4.1 /usr/bin/ucd5820stat

啟動 snmpd 並設定開機可自動啟動

3 安裝與設定 ntpd

su - root
yum -y install ntp
cd /etc
vi ntp.conf

編輯 ntp.conf

第一次網路校時

啟動 ntpd

4 安裝與設定 apache

su - root
yum -y install httpd mod_ssl

依據實際狀況設定 httpd.conf 參數檔

啟動 httpd

設定每次開機自動啟動 httpd

5 安裝與設定 MySQL

su - root
yum -y install mysql-server mysql-devel
  • 第一次啟動 MySQL 並設定自動啟動
service mysqld start
chkconfig mysqld on
chkconfig --list | grep mysqld
  • 設定與確認 MySQL 內的 root 密碼
/usr/bin/mysqladmin -u root password 'newpassword'
mysql -u root -p

6 安裝與設定 PostgreSQL

如果是安裝 CentOS5 x86_64, 可以直接使用 yum 來下載安裝 8.1.xx 的版本

yum install postgresql-server postgresql-devel.x86_64

6.1 確認是否有安裝之前版本

確認是否有安裝之前版本, 如果有的話要移除
rpm -qa | grep postgresql

結果訊息

postgresql-libs-7.4.13-2.RHEL4.1 因為有其他 rpm 相依性, 所以不能移除. 

結果訊息

6.2 下載 PostgreSQL 最新 RPM 版本

要依照目前安裝的 CentOS 是 32 或 64 版本來決定下載哪個版本
su - root
mkdir pgsql
cd pgsql

64 Bit 版本

32 Bit 版本

6.3 安裝最新版的 PostgreSQL

yum install -y tcl
rpm -ivh postgresql*
升級處理方式

  1. 下載最新版的 PostgreSQL
    網址 : ftp://ftp3.tw.postgresql.org/pub/Unix/Database/postgresql/binary/

  2. 直接下 rpm -Uvh 會出現 php-pgsql-xxx 相依性問題, 所以要改下

    rpm --nodeps -Uvh postgresql-*

  3. 升級後原本 CentOS 附的 postgresql-libs-7 就不見了, 所以還要下載安裝回去

    wget http://ftp.isu.edu.tw/pub/Linux/CentOS/4.5/updates/i386/RPMS/postgresql-libs-7.4.17-1.RHEL4.1.i386.rpm
    rpm --force -ivh postgresql-libs-7.*

6.4 設定 PostgreSQL

  1. 第一次建立 PostgreSQL 資料目錄|
    service postgresql initdb

  2. 檢查 PostgreSQL 參數檔是否已產生

    cd /var/lib/pgsql/data
    ls -lt
    

    看結果內容

    [root@tryboxap07 data]# ls -lt
    total 116
    drwx------  5 postgres postgres  4096 Jan 25 03:29 base
    drwx------  2 postgres postgres  4096 Jan 25 03:29 global
    drwx------  2 postgres postgres  4096 Jan 25 03:29 pg_log
    drwx------  2 postgres postgres  4096 Jan 25 03:29 pg_clog
    -rw-------  1 postgres postgres  3200 Jan 25 03:29 pg_hba.conf
    -rw-------  1 postgres postgres  1460 Jan 25 03:29 pg_ident.conf
    drwx------  2 postgres postgres  4096 Jan 25 03:29 pg_subtrans
    drwx------  3 postgres postgres  4096 Jan 25 03:29 pg_xlog
    -rw-------  1 postgres postgres 15201 Jan 25 03:29 postgresql.conf
    drwx------  4 postgres postgres  4096 Jan 25 03:29 pg_multixact
    drwx------  2 postgres postgres  4096 Jan 25 03:29 pg_tblspc
    drwx------  2 postgres postgres  4096 Jan 25 03:29 pg_twophase
    -rw-------  1 postgres postgres     4 Jan 25 03:29 PG_VERSION
    
  3. 設定 PostgreSQL 參數檔 postgresql.conf 內容

    vi postgresql.conf

    :
    listen_addresses = '*'
    port = 5432
    max_connections = 750
    :
    shared_buffers = 24MB
    :
    stats_start_collector = on
    stats_command_string = on
    stats_block_level = on
    stats_row_level = on
    :
    autovacuum = on
    :
  4. 依據實際需要來修改 postgresql 登入權限檔 pg_hba.conf

    vi pg_hba.conf

    # IPv4 local connections:
    local    all         all                             ident sameuser
    host    all         all         127.0.0.1/32          md5
  5. 啟動 PostgreSQL

    service postgresql start

    如果無法成功啟動, 可能需要調整 Kernel 的參數

    vi /etc/sysctl.conf

    kernel.shmmax = 536870912
    kernel.shmmni = 4096
    kernel.shmall = 2097152
    # semaphores: semmsl, semmns, semopm, semmni
    kernel.sem = 250 32000 100 128
    fs.file-max = 65536
    net.ipv4.ip_local_port_range = 1024 65000
    net.core.rmem_default=262144
    net.core.rmem_max=262144
    net.core.wmem_default=262144
    net.core.wmem_max=262144
    /sbin/sysctl -p
  6. 設定每次開機自動啟動 postgresql

    su - root
    chkconfig postgresql on
    chkconfig --list | grep postgresql
    

    看結果內容

    [root@trybox-03 data]#  chkconfig --list | grep postgresql
    postgresql      0:off   1:off   2:on    3:on    4:on    5:on    6:off
    [root@trybox-03 data]# 
    

7 安裝 php

如果之前未安裝 postgresql-libs-7.4.xx, 就必須依照以下方式強制安裝上去.

強制安裝 postgresql-libs-7.4.xx 程序

  1. 安裝 php 與 php-mysql / php-pgsql 模組

    yum install -y php php-mysql php-pgsql
    
  2. 設定 php

    原則上 php 已經隨 apache 安裝上去, 所以只要驗證是否沒問題

    cd /var/www/html/
    vi php.php
    

    php.php

    <?php
    phpinfo();
    ?>
    service httpd restart
    
  3. 然後輸入網址, 應該可以看到 php 資訊網頁

    http://trybox-server-url/php.php

8 安裝 perl Module

安裝 gcc

使用 perl -MCPAN -e shell 來安裝與更新 Perl Module

需要再額外安裝 Module

手動下載安裝 perl Module

這部份是當無法經由 CPAN 的方式安裝才需要透過這方式處理
su - root
mkdir perl
cd perl

Text::Iconv

Digest::Perl::MD5

DBI

DBD::Pg

Mail::Sendmail

MIME::Base64

LWP

9 安裝 phpMyAdmin

至 www.sf.net 找 phpMyAdmin

  • 因為預設 MySQL root 並沒有設定密碼,所以安裝好 phpMyAdmin 之後應該要立即透過 phpMyAdmin 更改 root 密碼

設定 config.inc.php 參數檔

10 安裝 phpPgAdmin

至 www.sf.net 找 phpPgAdmin

設定參數檔 conf/config.inc.php

驗證 phpPgAdmin 安裝是否正確

建立 Reports 資料庫

11 安裝 SubVersion(svn)

11.1 安裝 SubVersion rpm 與編輯設定檔 subversion.conf

CentOS 內附的 SubVersion 並非最新版本, 壓力測試發現在同時 svnadmin export 與 svn update 時會出現 db 異常問題, 導致無法運作, 必須執行 svnadmin recover svndir 修復, 以下就是針對 trybox 所修復的範例:


cd /var/www/svn
svnadmin recover trybox
chown -R apache:apache trybox

實際安裝程序

11.2 依實際需要建立 svn 目錄與專案

mkdir /var/www/svn
cd /var/www/svn
svnadmin create trybox
chown -R apache:apache trybox

11.3 設定存取 subversion 用戶帳號密碼

htpasswd -c /var/www/passwdfile jonathan
htpasswd /var/www/passwdfile trybox
[root@tryboxap1 svn]# htpasswd -c /var/www/passwdfile jonathan
New password:
Re-type new password:
Adding password for user jonathan

[root@tryboxap1 svn]# htpasswd /var/www/passwdfile trybox
New password:
Re-type new password:
Adding password for user jonathan

11.4 重起 apache 讓 subversion 生效

service httpd restart

12 安裝 cronolog 讓 log 檔可自動依日期分檔

wget http://cronolog.org/download/cronolog-1.6.2.tar.gz
tar -zxvf cronolog-1.6.2.tar.gz
cd cronolog-1.6.2
./configure
make
make install
cd ..
rm -rf cronolog-1.6.2*

13 安裝 RRDTool

實際安裝程序

14 依實際需要設定 iptables

su - root
vi /etc/sysconfig/iptables

/etc/sysconfig/iptables

service iptables restart
1) 目前 CentOS 4 最新版為 4.6 — 蔡宗融 2008/01/04 09:02
 
回到頁頂
tech/centosinstall.txt · 上一次變更: 2008/10/06 19:31 來自 jonathan
chimeric.de = chi`s home Creative Commons License Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0