每個知識點本人都親身驗證過。
CentOS 6.4下載地址:http://mirrors.163.com/ 網易開源鏡像
我選擇的是迷你版300M大小
完成CentOS 6.4的安裝,下面開始設置:
一、設置IP地址
1、把虛擬機的網卡設成“橋接”
2、修改對應網卡的IP地址的配置文件
vi /etc/sysconfig/network-scripts/ifcfg-eth0
修改以下內容
DEVICE=eth0 #描述網卡對應的設備別名,例如ifcfg-eth0的文件中它爲eth0
BOOTPROTO=static #設置網卡獲得ip地址的方式,可能的選項爲static,dhcp或bootp,分別對應靜態指定的 ip地址,通過dhcp協議獲得的ip地址,通過bootp協議獲得的ip地址
BROADCAST=192.168.1.255 #對應的子網廣播地址
HWADDR=00:07:E9:05:E8:B4 #對應的網卡物理地址
IPADDR=192.168.1.2 #如果設置網卡獲得 ip地址的方式爲靜態指定,此字段就指定了網卡對應的ip地址
IPV6INIT=no
IPV6_AUTOCONF=no
NETMASK=255.255.255.0 #網卡對應的網絡掩碼
NETWORK=192.168.1.0 #網卡對應的網絡地址
ONBOOT=yes #系統啓動時是否設置此網絡接口,設置爲yes時,系統啓動時激活此設備
3、修改網關
修改對應網卡的網關的配置文件
vi /etc/sysconfig/network
修改以下內容
NETWORKING=yes(表示系統是否使用網絡,一般設置爲yes。如果設爲no,則不能使用網絡,而且很多系統服務程序將無法啓動)
HOSTNAME=centos(設置本機的主機名,這裏設置的主機名要和/etc/hosts中設置的主機名對應)
GATEWAY=192.168.1.1(設置本機連接的網關的IP地址。例如,網關爲10.0.0.2)
4、修改DNS
修改對應網卡的DNS的配置文件
vi /etc/resolv.conf
修改以下內容
nameserver 8.8.8.8 #google域名服務器
nameserver 8.8.4.4 #google域名服務器
5、重新啓動網絡配置
service network restart 或 /etc/init.d/network restart
6、其他技巧
修改 IP 地址
即時生效:
# ifconfig eth0 192.168.1.2 netmask255.255.255.0
啓動生效:
修改/etc/sysconfig/network-scripts/ifcfg-eth0
修改網關
即時生效:
# route add default gw 192.168.1.1 dev eth0
啓動生效:
修改 /etc/sysconfig/network
修改 DNS
修改/etc/resolv.conf
修改後可即時生效,啓動同樣有效
修改 hostname
即時生效:
# hostname centos1
啓動生效:
修改/etc/sysconfig/network
二、配置防火牆
1、防火牆的設置
關閉防火牆:/etc/init.d/iptables stop
打開防火牆:/etc/init.d/iptables start
重啓防火牆:/etc/init.d/iptables restart
查看防火牆:/etc/init.d/iptables status
永久關閉防火牆:chkconfig iptables off
打開指定端口:/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT #80爲指定端口
將更改進行保存:/etc/rc.d/init.d/iptables save
或直接在/etc/sysconfig/iptables中增加一行:
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
2、查看端口
看ipp協議默認使用的端口可以通過這個命令:
cat /etc/service|grep ipp
查看所有被打開的端口一個是netstat,一個是ss
netstat -tanp
t代表TCP協議,還有u(UDP)、w(RAW)、x(UNIX)
a代表全部(all)
n:直接顯示端口號,而不是根據“/etc/server”顯示端口對應的服務名稱
p:顯示佔用該端口號的進程。
l:顯示正在被監聽的端口。
三、安裝WEB服務器
1、安裝nginx
rpm -ivh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
yum info nginx #查看yum的nginx信息
yum install nginx #安裝nginx
service nginx start #啓動nginx
四、安裝其他程序
yum check-update
yum -y install mysql-server php-fpm php-cli php-pdo php-mysql php-mcrypt php-mbstring php-gd php-tidy php-xml php-xmlrpc php-pear php-pecl-memcache php-eaccelerator
添加nginx 默認主頁index.php
vim /etc/nginx/conf.d/default.conf
location / {
root /usr/share/nginx/html;
index index.html index.htm index.php;
}
配置nginx支持php
vim /etc/nginx/conf.d/default.conf
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ .php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;
include fastcgi_params;
}
配置php-fpm
vim /etc/php-fpm.d/www.conf
; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
; will be used.
; RPM: apache Choosed to be able to access some dir as httpd
user = nginx
; RPM: Keep a group allowed to write in log dir.
group = nginx
service nginx start #啓動nginx
/etc/rc.d/init.d/php-fpm start #啓動php-fpm