nginx源码编译安装和配置
Linux系统下Configure命令参数
configure脚本有大量的命令行选项.对不同的软件包来说,这些选项可能会有变化,但是许多基本的选项是不会改变的.带上'-- help'选项执行'configure'脚本可以看到可用的所有选项。
–prefix=PEWFIX
'–prefix’是最常用的选项。制作出的’Makefile’会查看随此选项传递的参数,当一个包在安装时可以彻底的重新安置他的结构独立部分。举一个例子,当安装一个包,例如说Emacs,下面的命令将会使Emacs Lisp file被安装到"/opt/gnu/share":
$ ./configure --prefix=/opt/gnu
–exec-prefix=EPREFIX
与’–prefix’选项类似,但是他是用来设置结构倚赖的文件的安装位置,编译好的’emacs’二进制文件就是这样一个问件。如果没有设置这个选项的话,默认使用的选项值将被设为和’–prefix’选项值一样。
一、安装nginx
安装分为三部:
1.配置
configure
脚本负责在你使用的系统上准备好软件的构建环境。确保接下来的构建和安装过程所需要的依赖准备好,并且搞清楚使用这些依赖需要的东西。2. 构建
当
configure
配置完毕后,可以使用make
命令执行构建。这个过程会执行在Makefile
文件中定义的一系列任务将软件源代码编译成可执行文件。载的源码包一般没有一个最终的
Makefile
文件,一般是一个模块文件Makefile.in
文件,然后configure
根据系统的参数生成一个定制化的Makefile
文件。3. 安装
现在软件已经被构建好并且可以执行,接下来要做的就是将可执行文件复制到最终的路径。
make install
命令就是将可执行文件、第三方依赖包和文档复制到正确的路径。此段参考:configure、 make、 make install 背后的原理(翻译) - 知乎
[root@server1 ~]# tar -zxvf nginx-1.20.1.tar.gz
[root@server1 ~]# cd nginx-1.20.1 ##注意:需要在此目录下执行configure
[root@server1 nginx-1.20.1]# ./configure --help ##可以看到可用参数[root@server1 nginx-1.20.1]# ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
checking for OS ##安装模块+ Linux 3.10.0-957.el7.x86_64 x86_64
checking for C compiler ... not found./configure: error: C compiler cc is not found ##提示没有下载编辑器,下载编辑器[root@server1 nginx-1.20.1]# yum install gcc -y
[root@server1 nginx-1.20.1]# ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
./configure: error: the HTTP rewrite module requires the PCRE library. ##提示没有库
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.[root@server1 nginx-1.20.1]# yum install -y pcre-devel ##下载库通常为库名+ -devel
同理,提示缺少OpenSSL库,下载OpenSSL
安装好模块之后,使用make指令
make指令,是在安装有GNU Make的计算机上的可执行指令。该指令是读入一个名为 ’Makefile’的文件,然后执行这个文件中指定的指令。
make完成之后,使用make install
命令将可执行文件、第三方依赖包和文档复制到正确的路径
此时安装完成,可以看到objs目录下有nginx,conf中放有配置文件
创建软链接到/usr/local/sbin/(这样在开启nginx服务的时候就不需要进到目录下开启,软连接的方式可以方便开启全局nginx)
如果想要使用systemctl 命令需要添加脚本,将nginx放进指定文件中
脚本如下:
[root@server1 nginx-1.20.1]# cd /usr/lib/systemd/system
[root@server1 system]# vim 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=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true[Install]
WantedBy=multi-user.target[root@server1 system]# systemctl daemon-reload ##刷新服务列表
二、优化配置
编辑主配置文件,优化nginx工作效率
修改进程数
[root@server1 ~]# cd /usr/local/nginx/conf
[root@server1 conf]# vim nginx.conf
user nginx;
worker_processes 2; ##根据cpu数最优,增加同时工作的进程数
worker_cpu_affinity 01 10;#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;#pid logs/nginx.pid;
修改open files值
可以看到此时的open files数为1024
我们想将open files值改为65535,需要两步:
1、修改主配置文件
2、修改文件/etc/security/limits.conf
[root@server1 conf]# vim nginx.conf
[root@server1 conf]# vim /etc/security/limits.conf
[root@server1 conf]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@server1 conf]# nginx -s reload
为安全和方便,我们为nginx添加一个用户
[root@server1 conf]# useradd nginx
[root@server1 conf]# usermod -s /sbin/nologin nginx ##一般管理软件的用户不需要登陆
切换用户 再次查询可看到open files 值更改为65535
在主配置文件添加负载均衡器和反向代理
vim nginx.conf
在真机中进行地址解析,curl可以看到负载均衡
添加备用机
[root@server1 conf]# vim /etc/httpd/conf/httpd.conf ##listen改为8080
[root@server1 conf]# systemctl start httpd
[root@server1 conf]# curl localhost:8080
[root@server1 conf]# vim nginx.confhttp {upstream westos {server 172.25.6.2:80;server 172.25.6.3:80;server 172.25.6.1:8080 backup; ##添加备份机}include mime.types;default_type application/octet-stream;[root@server1 conf]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@server1 conf]# nginx -s reload
关闭server2 server3的httpd服务,可以看到备用机启用
权重控制
可以看到访问server2更多
固定ip固定负载机
可以看到ip不变就一直访问同一个负载机
编译第三方模块
[root@server1 ~]# yum install unzip
[root@server1 ~]# unzip nginx-goodies-nginx-sticky-module-ng-08a395c66e42.zip[root@server1 nginx-1.20.1]# make clean
[root@server1 nginx-1.20.1]# ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --add-module=/root/nginx-goodies-nginx-sticky-module-ng-08a395c66e42
[root@server1 nginx-1.20.1]# make
隐藏版本号
[root@server1 nginx-1.20.1]# vim src/core/nginx.h
关闭debug
[root@server1 nginx-1.20.1]# vim auto/cc/gcc
nginx缩小
加入模块
[root@server1 objs]# cd /usr/local/nginx/sbin
[root@server1 sbin]# ls
nginx
[root@server1 sbin]# mv nginx nginx.old
[root@server1 sbin]# cd -
/root/nginx-1.20.1/objs
[root@server1 objs]# cp nginx /usr/local/nginx/sbin[root@server1 objs]# cd /usr/local/nginx/conf
[root@server1 conf]# vim nginx.conf
http {upstream westos {#ip_hash;sticky;server 172.25.6.2:80;server 172.25.6.3:80;#server 172.25.6.1:8080 backup;}
[root@server1 conf]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@server1 conf]# nginx -s reload
nginx源码编译安装和配置相关推荐
- Nginx基础篇-Nginx 源码编译安装与平滑升级
Nginx基础篇-Nginx 源码编译安装与平滑升级 Nginx官网下载地址 http://nginx.org/ 1.安装依赖包 yum -y install pcre-devel zlib-deve ...
- LNMP架构环境搭建之PHP、Nginx源码编译安装及其简单配置应用
LNMP架构中的Mysql见上一篇博文"LNMP架构环境搭建之mysql源码编译安装" 一.PHP简介 PHP(外文名:PHP: Hypertext Preprocessor,中文 ...
- CentOS 7上源码编译安装和配置LNMP Web+phpMyAdmin服务器环境
什么是LNMP? LNMP(别名LEMP)是指由Linux, Nginx, MySQL/MariaDB, PHP/Perl/Python组合成的动态Web应用程序和服务器,它是一组Web应用程序的基础 ...
- Nginx 源码编译安装
Nginx 源码编译安装环境 Centos7 Nginx1.8.1 下载地址:http://nginx.org/download/ 选择自己想要的版本 我这边使用1.8.1,下载地址:http: ...
- Nginx 源码编译安装配置
Nginx 源码安装 作者:闫涛 E-mail:coderyantao@qq.com 备注:实验环境为虚拟机,selinux.firewalld都已经关闭.此次安装面向新手,并没有提前把所有问题解决, ...
- (转)linux上nginx源码编译安装
亲测有效: 转: https://segmentfault.com/a/1190000007116797https://segmentfault.com/a/1190000007116797 ngi ...
- Linux 利用nginx源码编译安装nginx
环境 1, CentOS 7 2, nginx 1.13.6 步骤 1,编译前准备 yum install pcre* openssl openssl-devel zlib zlib-devel 2, ...
- MySQL5.7.17源码编译安装与配置
一.下载MySQL源码 官网: http://www.mysql.com 下载下来的文件为:mysql-boost-5.7.17.tar.gz 二.解压源码,准备环境 [root@server1 so ...
- nginx 源码编译、安装
nginx 源码编译安装 下载Nginx安装包,Nginx 官网下载,并解压 cd /usr/local/src wget http://nginx.org/download/nginx-1.21.5 ...
- Nginx 源码编译
1.首先在官网下载Nginx 发布版的源码, Nginx 官网下载的地址是 :http://www.nginx.org/en/download.html 因为Nginx官网支持SVN,可以简单方便的使 ...
最新文章
- 【Codeforces - 977F】Consecutive Subsequence(STLmap,输出路径,dp)
- 【51Nod - 1344】走格子 (思维)
- 【linux】Ubuntu 18.04 设置桌面快捷启动方式
- Eigen官网教程(2) Array类和元素级操作
- dex2jar官网和jdgui官网链接
- 游戏引擎Flax Engine分析(八)渲染
- android网络权限动态,Android权限详解(含6.0动态申请)
- HTML / CSS / JS 编程入门 —— 使用 Lightly 制作可切换主题的简单网页
- IOS小知识点5之内存警告、循环引用、交叉引用
- 爬取斗鱼直播平台的所有房间信息
- mathtype试用期到后继续使用
- Windows恢复文件的默认打开方式
- 闭环式数字孪生智慧交通管理系统平台应用及分析
- 一步一步理解 python web 框架,才不会从入门到放弃 -- 简单登录页面
- 开箱即用的 SQL Server Docker
- 【OpenCV】拾色器,拾取图片中某个像素点的颜色(BGR、HSV、GRAY)
- seo排名工具_网站排名优化常用工具
- 电脑启动时显示windows无法正常启动怎么解决
- RabbitMQ图文详解 | MQ_SpringAMQP | 系统性学习 | 无知的我费曼笔记
- MySQL 笛卡尔集
热门文章
- 斗鱼显示弹幕服务器连接失败,斗鱼看不到弹幕怎么办 斗鱼无法看到弹幕的解决方法...
- Hi3531D调试手记(六):IT6801实现HDMI转码BT1120输入VI
- 傅里叶变换与拉普拉斯变换
- php 坏了怎么修复,winload.exe丢失或损坏怎么办
- JAVA疯狂讲义 第四版 课后习题 第四章 4.5
- win7便签backup
- 支付设计白皮书:支付系统的概念与中国互联网支付清算体系
- 大样本OLS模型假设及R实现
- RN对接京东支付sdk(Android)
- 好看的php表格样式,HTML5制作表格样式