卧疾丰暇豫,翰墨时间作。这篇文章主要讲述源码安装及定制rpm包相关的知识,希望能为你提供帮助。
Linux中软件的安装方式
安装包 | 安装方式 |
rpm包 | rpm、yum |
源码包 | 源码安装 |
源码包 | 解压即用 |
windows安装.exe程序
Linux安装源码包例举安装nginx
1.去官网下载源码包nginx.org
2.下载
# 复制下载链接地址用wget下载,再查看
[root@ yjc < sub> ] # wget http://nginx.org/download/nginx-1.20.2.tar.gz
[root@ yjc < /sub> ] # ll
-rw-r--r-- 1 root root 1062124 Nov 16 22:51 nginx-1.20.2.tar.gz
# 还需要安装一个C语言环境的依赖包
[root@ yjc ~/nginx-1.20.2 ] # yum install -y pcre-devel openssl-devel gcc gcc-c++ glibc
zlib-devel
3.解压
[root@ yjc ~ ] #tar xf nginx-1.20.2.tar.gz
4.生成
./configure --prefix=/opt/nginx-1.20.2 --with-http_ssl_module --with-http_stub_status_module
# 查看是否执行成功
[root@ yjc /opt/nginx-1.20.2 ] # echo $?
0
## 报错解决:
# 报错一
./configure: error: C compiler cc is not found
报错原因:缺少C语言环境
解决方法:yum install -y gcc gcc-c++ glibc
# 报错二
./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.
报错原因:缺少pcre库文件
解决方法:yum install -y pcre-devel
# 报错三
./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.
报错原因:缺少openssl库文件
解决方法:yum install -y openssl-devel
5.编译
# 让系统能识别你的代码,并且把刚才指定的功能和路径编译到源码中
[root@ yjc ~/nginx-1.20.2 ] # make
6.安装
[root@ yjc ~/nginx-1.20.2 ] # make install
7.做成软连接
# 做成软连接并查看
[root@ yjc < sub> /nginx-1.20.2 ] # ln -s /opt/nginx-1.20.2/ /opt/nginx
[root@ yjc < /sub> /nginx-1.20.2 ] # ll /opt
lrwxrwxrwx1 root root18 Apr 27 18:06 nginx -> /opt/nginx-1.20.2/
drwxr-xr-x6 root root54 Apr 27 17:55 nginx-1.20.2
[root@ yjc /opt/nginx-1.20.2 ] # ll /opt/nginx/
total 0
drwxr-xr-x 2 root root 333 Apr 27 17:55 conf
drwxr-xr-x 2 root root40 Apr 27 17:55 html
drwxr-xr-x 2 root root6 Apr 27 17:55 logs
drwxr-xr-x 2 root root19 Apr 27 17:55 sbin
软连接做好nginx源码安装也就做好了
8.添加nginx的环境变量,让nginx程序可以直接运行
# 查看sbin下的nginx
[root@ yjc /opt/nginx-1.20.2 ] # ll /opt/nginx/sbin/
total 5888
-rwxr-xr-x 1 root root 6025760 Apr 27 17:55 nginx
# 运行nginx,直接用绝对路径
[root@ yjc /opt/nginx-1.20.2 ] # /opt/nginx/sbin/nginx
# 查看nginx服务
[root@ yjc /opt/nginx-1.20.2 ] # netstat -lntup
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local AddressForeign AddressStatePID/Program name
tcp00 0.0.0.0:800.0.0.0:*LISTEN9725/nginx:
# 关闭nginx
[root@ yjc /opt/nginx-1.20.2 ] # /opt/nginx/sbin/nginx -spstop
————————————————————————————————————————————————————
## 系统命令为什么可以直接执行?
因为在环境变量中,有个PATH,只要是PATH所有目录下的可执行程序,都可以直接执行,不需要写绝对路径
[root@localhost < sub> ]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/.local/bin:/root/bin
# 添加nginx的环境变量,让nginx程序可以直接运行
[root@ yjc < /sub> ] # vim /etc/profile.d/nginx.sh
export PATH="$PATH:/opt/nginx/sbin"
9.加载修改的环境变量
# 加载环境变量
[root@ yjc < sub> ] # source /etc/profile
# 查看是否可直接运行
[root@ yjc < /sub> ] # echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/opt/nginx/sbin
出现了/opt/nginx/sbin说明nginx可以直接运行
10.启动nginx
[root@ yjc ~ ] # nginx
11.检查nginx是否启动成功(端口)
[root@ yjc < sub> ] # netstat -lntup
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local AddressForeign AddressStatePID/Program name
tcp00 0.0.0.0:80
[root@ yjc < /sub> ] # netstat -lntup|grep nginx
tcp00 0.0.0.0:800.0.0.0:*LISTEN9773/nginx: master
12.检查nginx进程
[root@ yjc < sub> ] # ps -ef|grep nginx
root977310 22:03 ?00:00:00 nginx: master process nginx
nobody977497730 22:03 ?00:00:00 nginx: worker process
root978212910 22:13 pts/000:00:00 grep --color=auto nginx
[root@ yjc < /sub> ] # ps -ef|grep nginx|grep -v grep
root977310 22:03 ?00:00:00 nginx: master process nginx
nobody977497730 22:03 ?00:00:00 nginx: worker process
13.关闭防火墙
[root@ yjc ~ ] # systemctl stop firewalld
14.关闭selinx
[root@ yjc ~ ] #setenforce 0
打开浏览器访问:http://10.0.0.101/(虚拟机ip)
![1651054682878](C:\\Users\\86180\\AppData\\Roaming\\Typora\\typora-user-images\\1651054682878.png)
nginx网页
#站点目录
[root@ yjc /opt/nginx/html ] # pwd
/opt/nginx/html
# 代码文件
[root@ yjc /opt/nginx/html ] # vim index.html
作业用nginx来做yum仓库
1.到nginx配置文件
[root@ yjc /opt ] # cd /opt/nginx/conf/
2.编辑nginx配置文件
[root@ yjc /opt/nginx/conf ] # vim nginx.conf
server
listen80;
server_namelocalhost;
location /
#roothtml;
root/data/yum_data/;
#indexindex.html index.htm;
autoindex on;
access_log off;
3.重启nginx
[root@ yjc /opt/nginx-1.20.2/conf ] # nginx -s reload
4.创建mkdir /data/yum_data/centos/7/os/x86_64/Packages/目录
[root@ yjc /data/yum_data ] # mkdir centos/7/os/x86_64/Packages/ -p
5.复制rpm包到该目录下
[root@ yjc /data/yum_data/centos/7/os/x86_64/Packages ] # cp /mnt/Packages/xt295-3.el7.x86_64.rpm .
[root@ yjc /data/yum_data/centos/7/os/x86_64/Packages ] # cp /mnt/Packages/zi0-11.el7.x86_64.rpm.
[root@ yjc /data/yum_data/centos/7/os/x86_64/Packages ] # ll
total 716
-rw-r--r-- 1 root root 466100 Apr 28 04:50 xterm-295-3.el7.x86_64.rpm
-rw-r--r-- 1 root root 266160 Apr 28 04:50 zip-3.0-11.el7.x86_64.rpm
6.将该目录改为仓库
[root@ yjc ~ createrepo /data/yum_data/centos/7/os/x86_64/
Spawning worker 0 with 2 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete
【源码安装及定制rpm包】
推荐阅读
- 如何方便查看md文件内容 markdown
- ubuntu下使用ssr客户端
- ubuntu中node和npm的卸载与安装
- registry私有仓库搭建
- 一条链接获取你的照片附源码
- Mac怎么解决无法连接到iCloud的问题(6种修复方法)
- 如何修复Mac的鼠标光标消失问题 (解决办法教程)
- 虚拟机扩容(/dev/mapper/centos-root 空间不足)
- [转]使用rosbridge协议实现安卓跟ros的解耦