环境:

系统硬件:vmware vsphere (CPU:2*4核,内存2G,双网卡)

系统版本:CentOS-7.0-1406-x86_64-DVD.iso

安装步骤:

1.准备

1.1 显示系统版本
[root@centos ~]# cat /etc/redhat-release
CentOS Linux release 7.0.1406 (Core)

[root@centos ~]# uname -a
Linux tCentos7 3.10.0-123.13.1.el7.x86_64 #1 SMP Tue Dec 9 23:06:09 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

1.2 安装基本软件包

[root@centos ~]# yum install vim wget lsof gcc gcc-c++ bzip2 -y

[root@centos ~]# yum install net-tools bind-utils -y

1.3 显示IP地址 (centos7需要先安装 net-tools bind-utils包)

[root@centos ~]# ifconfig|grep inet

inet 192.168.1.10 netmask 255.255.255.0 broadcast 192.168.1.255

2.编译安装nginx

2.1 下载包
[root@centos ~]# cd /usr/local/src/

[root@centos ~]# wget http://nginx.org/download/nginx-1.6.2.tar.gz

[root@centos ~]# wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.36.tar.gz

[root@centos ~]# wget http://zlib.net/zlib-1.2.8.tar.gz

[root@centos ~]# wget http://www.openssl.org/source/openssl-1.0.1j.tar.gz

[root@centos ~]# wget http://www.canonware.com/download/jemalloc/jemalloc-3.6.0.tar.bz2

2.2 安装依赖
[root@centos ~]# yum install zlib-devel openssl-devel -y

2.3 关闭selinux (不关有时会添加不了用户,或者重启后没法开机)
[root@centos ~]#  vim /etc/selinux/config

屏蔽以下两行

#SELINUX=enforcing

#SELINUXTYPE=targeted

添加以下一行

SELINUXTYPE=disabled

保存,退出

重启后,查询是否关闭(显示Disabled则表示关闭)

[root@centos ~]#  shutdown -r now

[root@centos ~]#  getenforce

Disabled

2.4 安装Pcre

[root@centos ~]# cd /usr/local/src/

[root@centos ~]# tar zvxf pcre-8.36.tar.gz

[root@centos ~]# cd pcre-8.36

[root@centos ~]# ./configure

[root@centos ~]# make && make install

2.5 安装openssl

[root@centos ~]# cd /usr/local/src/

[root@centos ~]# tar zvxf openssl-1.0.1j.tar.gz

[root@centos ~]# cd openssl-1.0.1j

[root@centos ~]# ./config

[root@centos ~]# make && make install

2.6 安装zlib

[root@centos ~]# cd /usr/local/src/

[root@centos ~]# tar zvxf zlib-1.2.8.tar.gz

[root@centos ~]# cd zlib-1.2.8

[root@centos ~]# ./configure

[root@centos ~]# make && make install

2.7 安装jemalloc

[root@centos ~]# cd /usr/local/src/

[root@centos ~]# tar xjf jemalloc-3.6.0.tar.bz2

[root@centos ~]# cd jemalloc-3.6.0

[root@centos ~]# ./configure

[root@centos ~]# make && make install

[root@centos ~]# echo '/usr/local/lib' > /etc/ld.so.conf.d/local.conf

[root@centos ~]# ldconfig

2.3 创建www用户和组,创建www虚拟主机使用的目录,以及Nginx使用的日志目录,并且赋予他们适当的权限

[root@centos ~]# groupadd www

[root@centos ~]# useradd -g www www -s /sbin/nologin

[root@centos ~]# mkdir -p /data/www

[root@centos ~]# chmod +w /data/www

[root@centos ~]# chown -R www:www /data/www

***如果没法创建用户,需要检查SELinux状态是否关闭

2.8 安装nginx

[root@centos ~]# cd /usr/local/src/

[root@centos ~]# tar zvxf nginx-1.6.2.tar.gz

[root@centos ~]# cd nginx-1.6.2

[root@centos ~]# ./configure --prefix=/opt/nginx --user=www --group=www --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-openssl=/usr/local/src/openssl-1.0.1j --with-zlib=/usr/local/src/zlib-1.2.8 --with-pcre=/usr/local/src/pcre-8.36 --with-ld-opt="-ljemalloc"

[root@centos ~]# make && make install

2.9 修改 nginx.conf

[root@centos ~]# vim /opt/nginx/conf/nginx.conf

修改前面几行为:

user www www;

worker_processes auto;

error_log logs/error.log crit;

pid logs/nginx.pid;

events{
  use epoll;
  worker_connections 65535;
}

找到,并修改 root 行的内容
location / {
root /data/www;
index index.html index.htm;
}

保存,退出

2.10 建立测试首页

[root@centos ~]# vim /data/www/index.html

<html>
<head><title>nginx index.html</title></head>
<body>
<h1>index.html</h1>
</body>
</html>

保存,退出

2.11 测试和运行

[root@centos ~]# cd /opt/nginx

[root@centos ~]# ldconfig

[root@centos ~]# ./sbin/nginx -c /opt/nginx/conf/nginx.conf -t

如果显示下面信息,即表示配置没问题

nginx: the configuration file /opt/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /opt/nginx/conf/nginx.conf test is successful

查看jemalloc是否生效,需要先启动nginx

[root@centos ~]# ./sbin/nginx -c /opt/nginx/conf/nginx.conf

[root@centos ~]# lsof -n | grep jemalloc

ginx 2346 root mem REG 253,1 1824470 51571788 /usr/local/lib/libjemalloc.so.1
nginx 2347 www mem REG 253,1 1824470 51571788 /usr/local/lib/libjemalloc.so.1
nginx 2348 www mem REG 253,1 1824470 51571788 /usr/local/lib/libjemalloc.so.1
nginx 2349 www mem REG 253,1 1824470 51571788 /usr/local/lib/libjemalloc.so.1
nginx 2350 www mem REG 253,1 1824470 51571788 /usr/local/lib/libjemalloc.so.1

2.12 防火墙添加80端口

[root@centos ~]# iptables -L|grep ACCEPT

[root@centos ~]# firewall-cmd --zone=public --add-port=80/tcp --permanent

[root@centos ~]# firewall-cmd --reload

[root@centos ~]# iptables -L|grep ACCEPT

2.13 浏览器打开

http://192.168.1.10

显示出欢迎内容,则表示成功

2.14 作为服务,开机后启动

[root@centos ~]# vim /usr/lib/systemd/system/nginx.service

增加以下内容

[Unit]
Description=The nginx HTTP and reverse proxy server
After=syslog.target network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/opt/nginx/logs/nginx.pid
ExecStartPre=/opt/nginx/sbin/nginx -c /opt/nginx/conf/nginx.conf -t
ExecStart=/opt/nginx/sbin/nginx -c /opt/nginx/conf/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target

:wq 保存退出

[root@centos ~]# systemctl enable nginx.service

[root@centos ~]# systemctl list-unit-files|grep enabled|grep nginx

2.15 启动服务

[root@centos ~]# ./sbin/nginx -s stop

[root@centos ~]# systemctl daemon-reload

[root@centos ~]# systemctl start nginx.service

[root@centos ~]# systemctl status nginx.service -l

[root@centos ~]# ps -ef|grep nginx

[root@centos ~]# lsof -n | grep jemalloc

CentOS7 编译安装 Nginx (实测 笔记 Centos 7.0 + nginx 1.6.2)的更多相关文章

  1. CentOS7 编译安装 Mongodb (实测 笔记 Centos 7.0 + Mongodb 2.6.6)

    环境: 系统硬件:vmware vsphere (CPU:2*4核,内存2G,双网卡) 系统版本:CentOS-7.0-1406-x86_64-DVD.iso 安装步骤: 1.准备 1.1 显示系统版 ...

  2. CentOS7 编译安装 Mariadb (实测 笔记 Centos 7.0 + Mariadb 10.0.15)

    环境: 系统硬件:vmware vsphere (CPU:2*4核,内存2G,双网卡) 系统版本:CentOS-7.0-1406-x86_64-DVD.iso 安装步骤: 1.准备 1.1 显示系统版 ...

  3. CentOS7 编译安装 Nodejs (实测 笔记 Centos 7.0 + node 0.10.33)

    环境: 系统硬件:vmware vsphere (CPU:2*4核,内存2G,双网卡) 系统版本:CentOS-7.0-1406-x86_64-DVD.iso 安装步骤: 1.准备 1.1 显示系统版 ...

  4. CentOS 编译安装 Redis (实测 笔记 Centos 7.3 + redis 3.2.8)

    环境: 系统硬件:vmware vsphere (CPU:2*4核,内存2G,双网卡) 系统版本:CentOS-7.0-1406-x86_64-DVD.iso 安装步骤: 1.准备 1.1 显示系统版 ...

  5. CentOS 编译安装 Nodejs (实测 笔记 Centos 7.3 + node 6.9.5)

    环境: 系统硬件:vmware vsphere (CPU:2*4核,内存2G,双网卡) 系统版本:CentOS-7.0-1406-x86_64-DVD.iso 安装步骤: 1.准备 1.1 显示系统版 ...

  6. Centos7 编译安装 Nginx PHP Mariadb Memcache扩展 ZendOpcache扩展 (实测 笔记 Centos 7.0 + Mariadb 10.1.9 + Nginx 1.9.9 + PHP 5.5.30)

    环境: 系统硬件:vmware vsphere (CPU:2*4核,内存2G,双网卡) 系统版本:CentOS-7-x86_64-Minimal-1503-01.iso 安装步骤: 1.准备 1.1 ...

  7. Cenos7 编译安装 Mariadb Nginx PHP Memcache ZendOpcache (实测 笔记 Centos 7.0 + Mariadb 10.0.15 + Nginx 1.6.2 + PHP 5.5.19)

    环境: 系统硬件:vmware vsphere (CPU:2*4核,内存2G,双网卡) 系统版本:CentOS-7.0-1406-x86_64-DVD.iso 安装步骤: 1.准备 1.1 显示系统版 ...

  8. CentOS7 编译安装LVS 互为主备 (实测 笔记 Centos 7.0 + ipvsadm 1.27 + keepalived 1.2.15 )

    环境: 系统硬件:vmware vsphere (CPU:2*4核,内存2G,双网卡) LVS服务器(两台): 系统:Centos7.0 64位(LVS+keepalived) LvsMaster:1 ...

  9. Centos7 编译安装 Nginx PHP Mariadb Memcached 扩展 ZendOpcache扩展 (实测 笔记 Centos 7.3 + Mariadb 10.1.20 + Nginx 1.10.2 + PHP 7.1.0 + Laravel 5.3 )

    环境: 系统硬件:vmware vsphere (CPU:2*4核,内存2G,双网卡) 系统版本:CentOS-7-x86_64-Minimal-1611.iso 安装步骤: 1.准备 1.0 查看硬 ...

随机推荐

  1. 【Tomcat 6.0官方文档翻译】—— 简介

    Tomcat作为使用最多的web容器,研究其原理过程,对掌握java web开发有很重要的影响. 因此下定决心,从官方文档入手,好好学学web相关的知识. 介绍     本篇是Apache Tomca ...

  2. 0、Web基本概念

    一.Web的概念: 本意是蜘蛛网和网的意思,在网页设计中我们称为网页的意思. 二.Web的分类:Internet上供外界访问的Web资源分为静态Web资源和动态Web资源两种. 1.静态Web资源:W ...

  3. SQLite的时候判断语句是否纯在:出现RuntimeException

    写SQLite的时候判断语句是否纯在: public boolean exist(long id) { String filter = FRIEND_KEY_ID + "=" + ...

  4. javascript数据结构-链表

    gihtub博客地址 链表 是一种物理存储单元上非连续.非顺序的存储结构,它既可以表示线性结构,也可以用于表示非线性结构,数据元素的逻辑顺序是通过链表中的指针链接次序实现的.链表由一系列结点(链表中每 ...

  5. linux各目录的作用

  6. hihoCoder 1196 高斯消元·二

    Description 一个黑白网格,点一次会改变这个以及与其连通的其他方格的颜色,求最少点击次数使得所有全部变成黑色. Sol 高斯消元解异或方程组. 先建立一个方程组. \(x_i\) 表示这个点 ...

  7. Angularjs 双向绑定机制解析

    文章转自:http://www.2cto.com/kf/201408/327594.html AngularJs 的元素与模型双向绑定依赖于循环检测它们之间的值,这种做法叫做脏检测,这几天研究了一下其 ...

  8. ul、li分列显示

    目的很简单:有一个 ul>li 列表,默认为单列显示,把它变为两列显示. 方法1,使用DIV+CSS代码: <style type="text/css"> .my ...

  9. 【python】引用其他目录文件

    假设有 目录/A(a.py), 目录/B(b.py), 括号里是目录中的文件 在目录/A中编写a2.py,里面可以import a,但是不能import b 解决方法 import sys sys.p ...

  10. node01-创建服务器

    node学习笔记目录:node01-创建服务器 node02-util node03-events node04-buffer node05-fs node06-path node07-http no ...