当然,首先要求是可以联网的CentOS系统,因为yum安装需要互联网连接。
1.为了追加 nginx 的 yum 仓库,需要创建一个文件 /etc/yum.repos.d/nginx.repo,并将下面的内容复制进去:
1
2
3
4
5
|
[nginx]
name=nginxrepo
baseurl=http://nginx.org/packages/centos/
$releasever
/
$basearch
/
gpgcheck=0
enabled=1
|
2.编辑并保存/etc/yum.repos.d/nginx.repo文件后,在命令行下执行
1
2
3
|
[root
@localhost
~]
#yumlist|grepnginx
nginx.i3861.4.7-1.el6.ngx
@nginx
nginx-debug.i3861.4.7-1.el6.ngxnginx
|
会发现就是最新的稳定版
于是直接执行
1
|
yum-yinstallnginx
|
安装即可
3.这种安装和从源代码编译Nginx的安装,文件所处的位置不一样,安装完执行下面的命令
1
2
3
4
|
[root
@localhost
~]
#find/-name*nginx*
/etc/nginx/nginx.conf
[root
@localhost
~]
#whereisnginx
nginx:/usr/sbin/nginx/etc/nginx/usr/share/nginx
|
你会发现主要文件安装到了/etc/nginx下
接下来是启动Nginx服务,可以执行
1
2
|
[root
@localhost
~]
#servicenginxstart
正在启动nginx:[确定]
|
接着查看Nginx的进程
1
2
3
4
5
6
7
8
|
[root
@localhost
~]
#netstat-lntp|grepnginx
tcp000.0.0.0:800.0.0.0:*LISTEN7910/nginx
[root
@localhost
~]
#ps-ef|grepnginx
root79101023:43?00:00:00nginx:masterprocess/usr/sbin/nginx-c
/etc/nginx/nginx.conf
nginx79127910023:43?00:00:00nginx:workerprocess
root79422459023:52pts/100:00:00
grep
nginx
|
缺省是一个master,一个slave,可以在配置nginx.conf文件里调整
4.设置开机自动启动
在centos6.5下测试了一下,不用设置
1
|
chkconfignginxon
|
可以自行开机自动启动