CentOS minimal 版的特點是小巧、純淨、安裝與啟動都很快,非常適合當作伺服器並做自動化部署。映像檔可自 centos.org 下載。
# vi /etc/sysconfig/network NETWORKING=yes HOSTNAME=www GATEWAY=192.168.3.1
NETWORKING 表示系統是否啟用網路,設為 no 會導致網路不可用且多數服務無法啟動。
# vi /etc/hosts
# vi /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE="eth0" BOOTPROTO="static" HWADDR=...... ONBOOT="yes" UUID=...... IPADDR=192.168.1.102 NETMASK=255.255.255.0 GATEWAY=192.168.1.1 DNS1=202.102.192.68 DNS2=8.8.8.8
重啟網卡:service network restart 或 /etc/init.d/network restart,重啟後會自動更新 /etc/resolv.conf。若 ifcfg-eth0 未設 DNS,需手動編輯 resolv.conf 加入 nameserver。
若是克隆出來的虛擬機,常遇到「Device eth0 does not seem to be present」的錯誤,原因是 MAC 位址對不上:
sudo rm -fr /etc/udev/rules.d/70-persistent-net.rules sudo reboot sudo vi /etc/sysconfig/network-scripts/ifcfg-eth0 # 修正 MAC,注意大小寫 sudo service network restart
date -R # 查看 cp -f /usr/share/zoneinfo/Asia/Shanghai /etc/localtime # 設時區 date -s "2012-08-01 00:00:00" # 設時間 sudo ntpdate us.pool.ntp.org # 同步 crontab -e 0-59/10 * * * * /usr/sbin/ntpdate us.pool.ntp.org | logger -t NTP sudo service crond restart
yum update -y
yum install gcc gcc-c++ make automake autoconf213 autoconf bison \ ncurses cmake libtool flex perl git subversion mercurial \ python-setuptools -y yum install openssl-devel pcre-devel zlib-devel libjpeg-devel \ libpng-devel freetype-devel ImageMagick-devel boost-devel \ libevent-devel libuuid-devel readline-devel bzip2-devel \ libxml2-devel libxslt-devel kernel-devel python-devel \ libpcap-devel sqlite-devel ncurses-devel libaio -y yum install wget vim lsof tcpdump screen p7zip unrar unzip \ sudo redhat-lsb ntpdate traceroute -y
useradd web passwd visudo -f /etc/sudoers # 在 root 那行下面加上: root ALL=(ALL) ALL web ALL=(ALL) ALL
測試:sudo whoami 輸出 root 即成功。
sudo vim /boot/grub/menu.lst timeout=0 # 原為 5
yum install gettext -y msgunfmt /usr/share/locale/zh_CN/LC_MESSAGES/wget.mo -o - \ | sed 's/eta(英國中部時間)/ETA/' \ | msgfmt - -o /tmp/zh_CN.mo cp /tmp/zh_CN.mo /usr/share/locale/zh_CN/LC_MESSAGES/wget.mo
reboot