在线安装:
1.先安装依赖
yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel
pcre安装,可以选择在线或者离线,这里选择离线安装
1)将包上传至服务器
2)解压:tar -xzvf pcre-8.37.tar.gz
或者在线下载:
wget https://jaist.dl.sourceforge.net/project/pcre/pcre/8.42/pcre-8.37.tar.gz
2)配置,编译安装
cd pcre-8.37
./configure
make && make install
2.安装nginx
在线获取,或者本地上传
在线获取:
wget https://nginx.org/download/nginx-1.16.1.tar.gz
解压,配置,并安装
tar -xzvf nginx-1.16.1.tar.gz
cd nginx-1.16.1
./configure --prefix=/home/nginx --with-http_stub_status_module --with-http_ssl_module --with-threads
make && make install
配置时如果出现以下错误,按照图片中的解决办法即可,即使使用rpm -qa|grep openssl 等等存在的话也要执行
yum -y install pcre-devel
yum -y install openssl openssl-devel
完成
离线安装
rpm安装包如下:(离线安装时:版本按照自己的系统进行对应的下载即可)
下载地址:http://rpmfind.net/linux/rpm2html/search.php
下载完成后将
yum install和yum localinstall的区别
yum install会去yum仓库查找相应的软件并安装,仓库中的软件都是解决了依赖关系的,而yum localinstall是用来安装本地rpm包的命令,
首先rpm包要先下载到本地,然后在本地目录执行yum localinstall *.rpm,yum会自动搜寻依赖关系并安装而rmp -i *.rpm不会自行解决依赖关系,
缺少依赖就会报错。
参考链接:https://www.cnblogs.com/zhangshuaihui/p/12336509.html
其他安装方式:
rpm -ivh --nodeps --force *
-i(install):安装
-v(verbose):显示详细信息
-h(hash):显示进度
–nodeps:不检测依赖性
--force:强制安装
--nodeps就是安装时不检查依赖关系,比如你这个rpm需要A,但是你没装A,这样你的包就装不上,用了--nodeps你就能装上了。--force就是强制安装,比如你装过这个rpm的版本1,如果你想装这个rpm的版本2,就需要用--force强制安装
nginx详细的离线安装步骤见:https://www.cnblogs.com/z-qinfeng/p/12423246.html
./configure \
--prefix=/home/nginx \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-openssl=/usr/bin/openssl
安装nginx可能会出现错误信息,按照错误信息的提示,完善安装指令即可:
错误一:需要openssl库
./configure: error: SSL modules require the OpenSSL library.
You can either do not enable the modules, or install the OpenSSL library
into the system, or build the OpenSSL library statically from the source
with nginx by using --with-openssl=<path> option.
错误二:需要pcre模块
./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.
Configuration summary
+ PCRE library is not used
+ using OpenSSL library: /usr/bin/openssl
+ zlib library is not used
nginx path prefix: "/home/nginx"
nginx binary file: "/home/nginx/sbin/nginx"
nginx modules path: "/home/nginx/modules"
nginx configuration prefix: "/home/nginx/conf"
nginx configuration file: "/home/nginx/conf/nginx.conf"
nginx pid file: "/home/nginx/logs/nginx.pid"
nginx error log file: "/home/nginx/logs/error.log"
nginx http access log file: "/home/nginx/logs/access.log"
nginx http client request body temporary files: "client_body_temp"
nginx http proxy temporary files: "proxy_temp"
nginx http fastcgi temporary files: "fastcgi_temp"
nginx http uwsgi temporary files: "uwsgi_temp"
nginx http scgi temporary files: "scgi_temp"
编译安装:
make && make install
启动nginx时出现的错误以及解决办法如下:
1. nginx: [error] invalid PID number ; in /usr/local/nginx/logs/nginx.pid
1.nginx 重新加载命令./nginx -s reload,出现
nginx: [error] invalid PID number "" in "/usr/local/nginx/logs/nginx.pid"问题。
解决办法:
第一步:执行命令 killall -9 nginx 杀掉nginx 进程
第二步:执行命令 /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
重新加载配置文件
第三步:执行命令 ./nginx -s reload 重新启动nginx
注意第二步:我的nginx是安装在usr/local下的,执行第二步的时候根据你nginx安装路径来执行。
2. nginx安装后不能使用systemctl命令启动
linux下启动nginx出现Failed to start nginx.service:unit not found,错误的原因就是没有添加nginx服务,所以启动失败。
或者报错为没有权限
解决办法:
1. 创建一个nginx.service
在 /usr/lib/systemd/system/目录下面新建一个nginx.service文件:
vim /usr/lib/systemd/system/nginx.service
赋予该文件可执行权限:
chmod +x /usr/lib/systemd/system/nginx.service
2. 编辑nginx.service内容
[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/home/nginx/logs/nginx.pid
ExecStartPre=/home/nginx/sbin/nginx -t -c /home/nginx/conf/nginx.conf
ExecStart=/home/nginx/sbin/nginx -c /home/nginx/conf/nginx.conf
ExecReload=/home/nginx/sbin/nginx -s reload
ExecStop=/home/nginx/sbin/nginx -s quit
PrivateTmp=true
[Install]
WantedBy=multi-user.target
nginx.service内容解释:
[Unit] //对服务的说明
Description=nginx - high performance web server //描述服务
After=network.target remote-fs.target nss-lookup.target //描述服务类别
[Service] //服务的一些具体运行参数的设置
Type=forking //后台运行的形式
PIDFile=/usr/local/nginx/logs/nginx.pid //PID文件的路径
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf //启动准备
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf //启动命令
ExecReload=/usr/local/nginx/sbin/nginx -s reload //重启命令
ExecStop=/usr/local/nginx/sbin/nginx -s stop //停止命令
ExecQuit=/usr/local/nginx/sbin/nginx -s quit //快速停止 一般停止命令就直接使用quit
PrivateTmp=true //给服务分配临时空间
[Install]
WantedBy=multi-user.target //服务用户的模式
3. 启动服务
在启动服务之前,需要先重载systemctl命令
systemctl daemon-reload
启动nginx
systemctl start nginx.service
或者
systemctl start nginx
这样就解决了,出现该问题困扰了半天的时间,在网络上搜索,帖子很多,但是没有解决问题,记录一下解决问题的过程,方便以后查询,也让遇到该问题的朋友提供解决的思路。参考:https://www.cnblogs.com/wang-yaz/p/11350013.html