centos 7.0根目录 的目录构成
[root@localhost src]# wget http://nginx.org/download/nginx-1.7.9.tar.gz--2015-01-24 12:55:21-- http://nginx.org/download/nginx-1.7.9.tar.gz正在解析主机 nginx.org (nginx.org)... 206.251.255.63正在连接 nginx.org (nginx.org)|206.251.255.63|:80... 已连接。已发出 HTTP 请求,正在等待回应... 200 OK长度:827263 (808K) [application/octet-stream]正在保存至: “nginx-1.7.9.tar.gz”100%[======================================>] 827,263 154KB/s 用时 6.5s2015-01-24 12:55:28 (125 KB/s) - 已保存 “nginx-1.7.9.tar.gz” [827263/827263])[root@localhost src]# lsnginx-1.7.9.tar.gz
解压压缩包 .tar.gz
解压压缩包 到指定的目录
[root@localhost src]# tar zxvf nginx-1.7.9.tar.gz -C /usr/local/bin
结果查看
[root@localhost src]# cd /usr/local/bin
[root@localhost bin]# lsnginx-1.7.9进入解压目录查看
文件>文件>
安装gcc
[root@localhost nginx-1.7.9]# yum -y install gcc-c++
安装最基础的模块 pcre-devel
[root@localhost nginx-1.7.9]# yum -y install pcre-devel
安装gzip
zlib-devel
[root@localhost nginx-1.7.9]# yum -y install zlib-devel
下面开始编译nginx 最简单 最少的编辑
[root@localhost nginx-1.7.9]# ./configure --prefix=/usr/etc/ngin
make
[root@localhost nginx-1.7.9]# make
make install
[root@localhost nginx-1.7.9]# make install
启动nginx
[root@localhost nginx-1.7.9]# cd /usr/etc[root@localhost etc]# lsngin[root@localhost etc]# cd ngin[root@localhost ngin]# lsconf html logs sbin[root@localhost ngin]# cd sbin[root@localhost sbin]# lsnginx[root@localhost sbin]# ./nginx
查看进程 查看nginx是否启用
[root@localhost sbin]# ps -ef|grep nginxroot 13536 1 0 14:14 ? 00:00:00 nginx: master process ./nginxnobody 13537 13536 0 14:14 ? 00:00:00 nginx: worker processroot 13540 2281 0 14:16 pts/0 00:00:00 grep --color=auto nginx
lsof -i:80 安装root用户的才是 默认的nobody需要删除
[root@localhost sbin]# lsof -i:80COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAMEnginx 13536 root 6u IPv4 32434 0t0 TCP *:http (LISTEN)nginx 13548 nobody 6u IPv4 32434 0t0 TCP *:http (LISTEN)
重启nginx
[root@localhost sbin]# ./nginx -s reload
查看iptables表的规则 是否限制了80等、
[root@localhost sbin]# iptables -nL --line-numberChain INPUT (policy ACCEPT)num target prot opt source destination1 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 ctstate RELATED,ESTABLISHED2 ACCEPT all -- 0.0.0.0/0 0.0.0.0/03 INPUT_direct all -- 0.0.0.0/0 0.0.0.0/04 INPUT_ZONES_SOURCE all -- 0.0.0.0/0 0.0.0.0/05 INPUT_ZONES all -- 0.0.0.0/0 0.0.0.0/06 ACCEPT icmp -- 0.0.0.0/0 0.0.0.0/07 REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibitedChain FORWARD (policy ACCEPT)num target prot opt source destination1 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 ctstate RELATED,ESTABLISHED2 ACCEPT all -- 0.0.0.0/0 0.0.0.0/03 FORWARD_direct all -- 0.0.0.0/0 0.0.0.0/04 FORWARD_IN_ZONES_SOURCE all -- 0.0.0.0/0 0.0.0.0/05 FORWARD_IN_ZONES all -- 0.0.0.0/0 0.0.0.0/06 FORWARD_OUT_ZONES_SOURCE all -- 0.0.0.0/0 0.0.0.0/0 7 FORWARD_OUT_ZONES all -- 0.0.0.0/0 0.0.0.0/08 ACCEPT icmp -- 0.0.0.0/0 0.0.0.0/09 REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibitedChain OUTPUT (policy ACCEPT)num target prot opt source destination1 OUTPUT_direct all -- 0.0.0.0/0 0.0.0.0/0Chain FORWARD_IN_ZONES (1 references)num target prot opt source destination1 FWDI_public all -- 0.0.0.0/0 0.0.0.0/0 [goto]2 FWDI_public all -- 0.0.0.0/0 0.0.0.0/0 [goto]Chain FORWARD_IN_ZONES_SOURCE (1 references)num target prot opt source destinationChain FORWARD_OUT_ZONES (1 references)num target prot opt source destination1 FWDO_public all -- 0.0.0.0/0 0.0.0.0/0 [goto]2 FWDO_public all -- 0.0.0.0/0 0.0.0.0/0 [goto]Chain FORWARD_OUT_ZONES_SOURCE (1 references)num target prot opt source destinationChain FORWARD_direct (1 references)num target prot opt source destinationChain FWDI_public (2 references)num target prot opt source destination1 FWDI_public_log all -- 0.0.0.0/0 0.0.0.0/02 FWDI_public_deny all -- 0.0.0.0/0 0.0.0.0/03 FWDI_public_allow all -- 0.0.0.0/0 0.0.0.0/0Chain FWDI_public_allow (1 references)num target prot opt source destinationChain FWDI_public_deny (1 references)num target prot opt source destinationChain FWDI_public_log (1 references)num target prot opt source destinationChain FWDO_public (2 references)num target prot opt source destination1 FWDO_public_log all -- 0.0.0.0/0 0.0.0.0/02 FWDO_public_deny all -- 0.0.0.0/0 0.0.0.0/03 FWDO_public_allow all -- 0.0.0.0/0 0.0.0.0/0Chain FWDO_public_allow (1 references)num target prot opt source destinationChain FWDO_public_deny (1 references)num target prot opt source destinationChain FWDO_public_log (1 references)num target prot opt source destinationChain INPUT_ZONES (1 references)num target prot opt source destination1 IN_public all -- 0.0.0.0/0 0.0.0.0/0 [goto]2 IN_public all -- 0.0.0.0/0 0.0.0.0/0 [goto]Chain INPUT_ZONES_SOURCE (1 references)num target prot opt source destinationChain INPUT_direct (1 references)num target prot opt source destinationChain IN_public (2 references)num target prot opt source destination1 IN_public_log all -- 0.0.0.0/0 0.0.0.0/02 IN_public_deny all -- 0.0.0.0/0 0.0.0.0/03 IN_public_allow all -- 0.0.0.0/0 0.0.0.0/0Chain IN_public_allow (1 references)num target prot opt source destination1 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:22 ctstate NEWChain IN_public_deny (1 references)num target prot opt source destinationChain IN_public_log (1 references)num target prot opt source destinationChain OUTPUT_direct (1 references)num target prot opt source destination
查看规则
iptables -nL --line-number
iptables -nvL --line-number-L 查看当前表的所有规则,默认查看的是filter表,如果要查看NAT表,可以加上-t NAT参数-n 不对ip地址进行查,加上这个参数显示速度会快很多-v 输出详细信息,包含通过该规则的数据包数量,总字节数及相应的网络接口–line-number 显示规则的序列号,这个参数在删除或修改规则时会用到
现在访问http://192.168.1.103/ 无法访问 不知道什么情况额~ IP 肯定没错啊
[root@localhost sbin]# ip addr1: lo: mtu 65536 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever2: enp2s0: mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 6c:62:6d:73:e6:4a brd ff:ff:ff:ff:ff:ff inet 192.168.1.103/24 brd 192.168.1.255 scope global enp2s0 valid_lft forever preferred_lft forever inet6 fe80::6e62:6dff:fe73:e64a/64 scope link valid_lft forever preferred_lft forever
后记:
查询一个包是否被安装 # rpm -q < rpm package name>列出所有被安装的rpm package # rpm -qa
[root@localhost sbin]# rpm -qa
lsof 安装 查询端口启用情况 可以查询 nginx是否启用
具体使用
[root@localhost sbin]# lsof -i:80COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAMEnginx 13536 root 6u IPv4 32434 0t0 TCP *:http (LISTEN)nginx 13548 nobody 6u IPv4 32434 0t0 TCP *:http (LISTEN)
[root@localhost sbin]# yum -y install lsof已加载插件:fastestmirrorLoading mirror speeds from cached hostfile * base: mirrors.btte.net * extras: mirrors.hustunique.com * updates: mirrors.skyshe.cn正在解决依赖关系--> 正在检查事务---> 软件包 lsof.x86_64.0.4.87-4.el7 将被 安装--> 解决依赖关系完成依赖关系解决================================================================================ Package 架构 版本 源 大小================================================================================正在安装: lsof x86_64 4.87-4.el7 base 331 k事务概要================================================================================安装 1 软件包总下载量:331 k安装大小:927 kDownloading packages:lsof-4.87-4.el7.x86_64.rpm | 331 kB 00:00Running transaction checkRunning transaction testTransaction test succeededRunning transaction 正在安装 : lsof-4.87-4.el7.x86_64 1/1 验证中 : lsof-4.87-4.el7.x86_64 1/1已安装: lsof.x86_64 0:4.87-4.el7完毕!
使用vi命令
不保存退出:q!
保存退出:wq
插入数据 i
跳转到命令行 比如插入修改数据完成后 ESC 后输入 :wq 保存退出
[root@localhost /]# find -name nginx 查看根目录下的所有nginx./usr/etc/ngin/sbin/nginx./usr/local/bin/nginx-1.7.9/objs/nginx[root@localhost /]# yum remove nginx 尝试 删除默认yum安装的nginx已加载插件:fastestmirror参数 nginx 没有匹配不删除任何软件包
查询80端口
netstat -ano | grep 80 没有就先安装
yum -y install net-tools
[root@localhost sbin]# yum -y install net-tools已加载插件:fastestmirrorLoading mirror speeds from cached hostfile * base: mirrors.btte.net * extras: mirrors.hustunique.com * updates: mirrors.skyshe.cn正在解决依赖关系--> 正在检查事务---> 软件包 net-tools.x86_64.0.2.0-0.17.20131004git.el7 将被 安装--> 解决依赖关系完成依赖关系解决================================================================================ Package 架构 版本 源 大小================================================================================正在安装: net-tools x86_64 2.0-0.17.20131004git.el7 base 304 k事务概要================================================================================安装 1 软件包总下载量:304 k安装大小:917 kDownloading packages:net-tools-2.0-0.17.20131004git.el7.x86_64.rpm | 304 kB 00:00Running transaction checkRunning transaction testTransaction test succeededRunning transaction 正在安装 : net-tools-2.0-0.17.20131004git.el7.x86_64 1/1 验证中 : net-tools-2.0-0.17.20131004git.el7.x86_64 1/1已安装: net-tools.x86_64 0:2.0-0.17.20131004git.el7完毕![root@localhost sbin]# netstat -ano | grep 80tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN off (0.00/0/0)tcp 0 0 192.168.1.103:38036 114.247.56.117:80 TIME_WAIT timewait (0.00/0/0)unix 3 [ ] STREAM CONNECTED 16806 /var/run/dbus/system_bus_socketunix 3 [ ] STREAM CONNECTED 20180unix 3 [ ] STREAM CONNECTED 16805
最后的最后 居然是防火墙的问题
CentOS 7.0默认使用的是firewall作为防火墙
关闭防火墙
systemctl stop firewalld.service #停止firewall
在IP 访问一切正常
systemctl disable firewalld.service #禁止firewall开机启动
[root@localhost init.d]# systemctl start firewalld.service 开启防火墙firewall[root@localhost init.d]# firewall-cmd --state 查看防火墙firewall运行状态running
启动后增加端口 通过规则
[root@localhost init.d]# firewall-cmd --add-port=80/tcpsuccess
再次访问 http://192.168.1.103/ 正常
查看firewall 运行情况
[root@localhost init.d]# firewall-cmd --state
not running参考文章
firewall防火墙的介绍 上面的 添加端口 也是这里看到的~
http://linoxide.com/firewall/firewalld-centos-rhel/?utm_source=tuicool