前言
今天学习Linux源码包管理,首先会介绍什么是源码包,认识源码包,学习怎么获取源码包,并且部署源码包安装的程序。
什么是源码包?
source code需要经过GCC,C++编译环境编译才能运行;可以设定个人设置,开关功能;但是配置复杂。
软件包示例:nginx-1.8.1.tar.gz
● nginx:包名。
●-1.8.1:版本号。
●.tar.gz:压缩格式。
获得源码包
从官方网站,可以获得最新的软件包:
● Apache:www.apache.org
● Nginx:www.nginx.org
● Tengine:tengine.taobao.org
今天以Tengine为例展示获得源码包。
1.下载tengine
使用wget命令下载源码包
命令:wget http://tengine.taobao.org/download/tengine-2.3.2.tar.gz
[root@localhost tengine]# wget http://tengine.taobao.org/download/tengine-2.3.2.tar.gz --2022-11-03 13:47:54-- http://tengine.taobao.org/download/tengine-2.3.2.tar.gz 正在解析主机 tengine.taobao.org (tengine.taobao.org)... 106.11.186.45, 203.119.245.120, 203.119.245.121, ... 正在连接 tengine.taobao.org (tengine.taobao.org)|106.11.186.45|:80... 已连接。 已发出 HTTP 请求,正在等待回应... 200 OK 长度:2835884 (2.7M) [application/octet-stream] 正在保存至: “tengine-2.3.2.tar.gz” 100%[=============================================>] 2,835,884 230KB/s 用时 10s 2022-11-03 13:48:04 (266 KB/s) - 已保存 “tengine-2.3.2.tar.gz” [2835884/2835884])
下载可能遇到的问题:
1)如果提示wget命令为找到,用yum -y install wget安装wget
2)可能提示wget: 无法解析主机地址 “tengine.taobao.org”可能是网络没有连接
1)如果提示wget命令为找到,用yum -y install wget安装wget
[root@localhost tengine]# yum -y install wget 已加载插件:fastestmirror, langpacks Loading mirror speeds from cached hostfile dvd | 3.6 kB 00:00:00 正在解决依赖关系 --> 正在检查事务 ---> 软件包 wget.x86_64.0.1.14-18.el7_6.1 将被 安装 --> 解决依赖关系完成 依赖关系解决 ======================================================================================= Package 架构 版本 源 大小 ======================================================================================= 正在安装: wget x86_64 1.14-18.el7_6.1 dvd 547 k 事务概要 ======================================================================================= 安装 1 软件包 总下载量:547 k 安装大小:2.0 M Downloading packages: Running transaction check Running transaction test Transaction test succeeded Running transaction 正在安装 : wget-1.14-18.el7_6.1.x86_64 1/1 验证中 : wget-1.14-18.el7_6.1.x86_64 1/1 已安装: wget.x86_64 0:1.14-18.el7_6.1 完毕!
2)可能提示wget: 无法解析主机地址 “tengine.taobao.org”可能是网络没有连接
2.准备编译环境如编译器
命令:yum -y install gcc make zlib-devel pcre-devel openssl-devl
gcc 、make、zlib-devel 、 pcre-devel 、 openssl-devl这些都是常见的编译工具。
[root@localhost tengine-2.3.2]# yum -y install gcc make zlib-devel pcre-devel openssl-devl 已加载插件:fastestmirror, langpacks Loading mirror speeds from cached hostfile 软件包 gcc-4.8.5-44.el7.x86_64 已安装并且是最新版本 软件包 1:make-3.82-24.el7.x86_64 已安装并且是最新版本 没有可用软件包 openssl-devl。 正在解决依赖关系 --> 正在检查事务 ---> 软件包 pcre-devel.x86_64.0.8.32-17.el7 将被 安装 ---> 软件包 zlib-devel.x86_64.0.1.2.7-18.el7 将被 安装 --> 解决依赖关系完成 依赖关系解决 ======================================================================================= Package 架构 版本 源 大小 ======================================================================================= 正在安装: pcre-devel x86_64 8.32-17.el7 dvd 480 k zlib-devel x86_64 1.2.7-18.el7 dvd 50 k 事务概要 ======================================================================================= 安装 2 软件包 总下载量:530 k 安装大小:1.6 M Downloading packages: --------------------------------------------------------------------------------------- 总计 1.5 MB/s | 530 kB 00:00 Running transaction check Running transaction test Transaction test succeeded Running transaction 正在安装 : pcre-devel-8.32-17.el7.x86_64 1/2 正在安装 : zlib-devel-1.2.7-18.el7.x86_64 2/2 验证中 : zlib-devel-1.2.7-18.el7.x86_64 1/2 验证中 : pcre-devel-8.32-17.el7.x86_64 2/2 已安装: pcre-devel.x86_64 0:8.32-17.el7 zlib-devel.x86_64 0:1.2.7-18.el7 完毕! [root@localhost tengine-2.3.2]# make make: *** 没有规则可以创建“default”需要的目标“build”。 停止。 [root@localhost tengine-2.3.2]# make make: *** 没有规则可以创建“default”需要的目标“build”。 停止。 [root@localhost tengine-2.3.2]# ^C [root@localhost tengine-2.3.2]# <pre>yum -y install gcc make zlib-devel pcre-devel openssl-devl bash: pre: 没有那个文件或目录 [root@localhost tengine-2.3.2]# yum -y install gcc make zlib-devel pcre-devel openssl-devl 已加载插件:fastestmirror, langpacks Loading mirror speeds from cached hostfile 软件包 gcc-4.8.5-44.el7.x86_64 已安装并且是最新版本 软件包 1:make-3.82-24.el7.x86_64 已安装并且是最新版本 软件包 zlib-devel-1.2.7-18.el7.x86_64 已安装并且是最新版本 软件包 pcre-devel-8.32-17.el7.x86_64 已安装并且是最新版本 没有可用软件包 openssl-devl。 无须任何处理 [root@localhost tengine-2.3.2]# yum -y install gcc make zlib-devel pcre-devel openssl-devel 已加载插件:fastestmirror, langpacks Loading mirror speeds from cached hostfile 软件包 gcc-4.8.5-44.el7.x86_64 已安装并且是最新版本 软件包 1:make-3.82-24.el7.x86_64 已安装并且是最新版本 软件包 zlib-devel-1.2.7-18.el7.x86_64 已安装并且是最新版本 软件包 pcre-devel-8.32-17.el7.x86_64 已安装并且是最新版本 正在解决依赖关系 --> 正在检查事务 ---> 软件包 openssl-devel.x86_64.1.1.0.2k-19.el7 将被 安装 --> 正在处理依赖关系 krb5-devel(x86-64),它被软件包 1:openssl-devel-1.0.2k-19.el7.x86_64 需要 --> 正在检查事务 ---> 软件包 krb5-devel.x86_64.0.1.15.1-50.el7 将被 安装 --> 正在处理依赖关系 libkadm5(x86-64) = 1.15.1-50.el7,它被软件包 krb5-devel-1.15.1-50.el7.x86_64 需要 --> 正在处理依赖关系 libverto-devel,它被软件包 krb5-devel-1.15.1-50.el7.x86_64 需要 --> 正在处理依赖关系 libselinux-devel,它被软件包 krb5-devel-1.15.1-50.el7.x86_64 需要 --> 正在处理依赖关系 libcom_err-devel,它被软件包 krb5-devel-1.15.1-50.el7.x86_64 需要 --> 正在处理依赖关系 keyutils-libs-devel,它被软件包 krb5-devel-1.15.1-50.el7.x86_64 需要 --> 正在检查事务 ---> 软件包 keyutils-libs-devel.x86_64.0.1.5.8-3.el7 将被 安装 ---> 软件包 libcom_err-devel.x86_64.0.1.42.9-19.el7 将被 安装 ---> 软件包 libkadm5.x86_64.0.1.15.1-50.el7 将被 安装 ---> 软件包 libselinux-devel.x86_64.0.2.5-15.el7 将被 安装 --> 正在处理依赖关系 libsepol-devel(x86-64) >= 2.5-10,它被软件包 libselinux-devel-2.5-15.el7.x86_64 需要 --> 正在处理依赖关系 pkgconfig(libsepol),它被软件包 libselinux-devel-2.5-15.el7.x86_64 需要 ---> 软件包 libverto-devel.x86_64.0.0.2.5-4.el7 将被 安装 --> 正在检查事务 ---> 软件包 libsepol-devel.x86_64.0.2.5-10.el7 将被 安装 --> 解决依赖关系完成 依赖关系解决 ======================================================================================= Package 架构 版本 源 大小 ======================================================================================= 正在安装: openssl-devel x86_64 1:1.0.2k-19.el7 dvd 1.5 M 为依赖而安装: keyutils-libs-devel x86_64 1.5.8-3.el7 dvd 37 k krb5-devel x86_64 1.15.1-50.el7 dvd 273 k libcom_err-devel x86_64 1.42.9-19.el7 dvd 32 k libkadm5 x86_64 1.15.1-50.el7 dvd 179 k libselinux-devel x86_64 2.5-15.el7 dvd 187 k libsepol-devel x86_64 2.5-10.el7 dvd 77 k libverto-devel x86_64 0.2.5-4.el7 dvd 12 k 事务概要 ======================================================================================= 安装 1 软件包 (+7 依赖软件包) 总下载量:2.3 M 安装大小:4.5 M Downloading packages: --------------------------------------------------------------------------------------- 总计 39 MB/s | 2.3 MB 00:00 Running transaction check Running transaction test Transaction test succeeded Running transaction 正在安装 : libkadm5-1.15.1-50.el7.x86_64 1/8 正在安装 : libsepol-devel-2.5-10.el7.x86_64 2/8 正在安装 : libselinux-devel-2.5-15.el7.x86_64 3/8 正在安装 : libcom_err-devel-1.42.9-19.el7.x86_64 4/8 正在安装 : libverto-devel-0.2.5-4.el7.x86_64 5/8 正在安装 : keyutils-libs-devel-1.5.8-3.el7.x86_64 6/8 正在安装 : krb5-devel-1.15.1-50.el7.x86_64 7/8 正在安装 : 1:openssl-devel-1.0.2k-19.el7.x86_64 8/8 验证中 : libselinux-devel-2.5-15.el7.x86_64 1/8 验证中 : keyutils-libs-devel-1.5.8-3.el7.x86_64 2/8 验证中 : libverto-devel-0.2.5-4.el7.x86_64 3/8 验证中 : krb5-devel-1.15.1-50.el7.x86_64 4/8 验证中 : 1:openssl-devel-1.0.2k-19.el7.x86_64 5/8 验证中 : libcom_err-devel-1.42.9-19.el7.x86_64 6/8 验证中 : libsepol-devel-2.5-10.el7.x86_64 7/8 验证中 : libkadm5-1.15.1-50.el7.x86_64 8/8 已安装: openssl-devel.x86_64 1:1.0.2k-19.el7 作为依赖被安装: keyutils-libs-devel.x86_64 0:1.5.8-3.el7 krb5-devel.x86_64 0:1.15.1-50.el7 libcom_err-devel.x86_64 0:1.42.9-19.el7 libkadm5.x86_64 0:1.15.1-50.el7 libselinux-devel.x86_64 0:2.5-15.el7 libsepol-devel.x86_64 0:2.5-10.el7 libverto-devel.x86_64 0:0.2.5-4.el7 完毕!
3.解压
下载的是个源码包是个压缩包,需要解压才能使用
命令:tar xvf tengine-2.2.0.tar.gz
//创建一个用户等会需要用 [root@localhost tengine]# useradd sure1 //解压tengine-2.3.2.tar.gz到当前目录(tengine) [root@localhost tengine]# tar xvf tengine-2.3.2.tar.gz [root@localhost tengine]# cd tengine-2.3.2/
不是安装每个程序都需要用户的,这里设置的时候需要,也可以不要。
4.配置
./configure --user=sure1 --group=sure1 --prefix=/usr/local/nginx
./configure是必要的后面配置可以选择
user:用户。
group:用户组。
prefix:安装路径。如果这里配置的时候配置错了,就把解压的文件上删除,重新解压压缩包,注意是删除解压后的文件不是压缩包。
[root@localhost tengine-2.3.2]# ./configure --user=sure1 --group=sure1 --prefix=/usr/local/nginx checking for OS + Linux 3.10.0-1160.el7.x86_64 x86_64 checking for C compiler ... found + using GNU C compiler + gcc version: 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) checking for gcc -pipe switch ... found checking for -Wl,-E switch ... found checking for gcc builtin atomic operations ... found checking for C99 variadic macros ... found checking for gcc variadic macros ... found checking for gcc builtin 64 bit byteswap ... found checking for unistd.h ... found checking for inttypes.h ... found checking for limits.h ... found checking for sys/filio.h ... not found checking for sys/param.h ... found checking for sys/mount.h ... found checking for sys/statvfs.h ... found checking for crypt.h ... found checking for Linux specific features checking for epoll ... found checking for EPOLLRDHUP ... found checking for EPOLLEXCLUSIVE ... not found checking for O_PATH ... found checking for sendfile() ... found checking for sendfile64() ... found checking for sys/prctl.h ... found checking for prctl(PR_SET_DUMPABLE) ... found checking for prctl(PR_SET_KEEPCAPS) ... found checking for capabilities ... found checking for crypt_r() ... found checking for sys/vfs.h ... found checking for poll() ... found checking for /dev/poll ... not found checking for kqueue ... not found checking for crypt() ... not found checking for crypt() in libcrypt ... found checking for F_READAHEAD ... not found checking for posix_fadvise() ... found checking for O_DIRECT ... found checking for F_NOCACHE ... not found checking for directio() ... not found checking for statfs() ... found checking for statvfs() ... found checking for dlopen() ... not found checking for dlopen() in libdl ... found checking for sched_yield() ... found checking for sched_setaffinity() ... found checking for SO_SETFIB ... not found checking for SO_REUSEPORT ... found checking for SO_ACCEPTFILTER ... not found checking for SO_BINDANY ... not found checking for IP_TRANSPARENT ... found checking for IP_BINDANY ... not found checking for IP_BIND_ADDRESS_NO_PORT ... found checking for IP_RECVDSTADDR ... not found checking for IP_SENDSRCADDR ... not found checking for IP_PKTINFO ... found checking for IPV6_RECVPKTINFO ... found checking for TCP_DEFER_ACCEPT ... found checking for TCP_KEEPIDLE ... found checking for TCP_FASTOPEN ... found checking for TCP_INFO ... found checking for accept4() ... found checking for eventfd() ... found checking for int size ... 4 bytes checking for long size ... 8 bytes checking for long long size ... 8 bytes checking for void * size ... 8 bytes checking for uint32_t ... found checking for uint64_t ... found checking for sig_atomic_t ... found checking for sig_atomic_t size ... 4 bytes checking for socklen_t ... found checking for in_addr_t ... found checking for in_port_t ... found checking for rlim_t ... found checking for uintptr_t ... uintptr_t found checking for system byte ordering ... little endian checking for size_t size ... 8 bytes checking for off_t size ... 8 bytes checking for time_t size ... 8 bytes checking for AF_INET6 ... found checking for setproctitle() ... not found checking for pread() ... found checking for pwrite() ... found checking for pwritev() ... found checking for sys_nerr ... found checking for localtime_r() ... found checking for clock_gettime(CLOCK_MONOTONIC) ... found checking for posix_memalign() ... found checking for memalign() ... found checking for mmap(MAP_ANON|MAP_SHARED) ... found checking for mmap("/dev/zero", MAP_SHARED) ... found checking for System V shared memory ... found checking for POSIX semaphores ... not found checking for POSIX semaphores in libpthread ... found checking for struct msghdr.msg_control ... found checking for ioctl(FIONBIO) ... found checking for struct tm.tm_gmtoff ... found checking for struct dirent.d_namlen ... not found checking for struct dirent.d_type ... found checking for sysconf(_SC_NPROCESSORS_ONLN) ... found checking for sysconf(_SC_LEVEL1_DCACHE_LINESIZE) ... found checking for openat(), fstatat() ... found checking for getaddrinfo() ... found checking for sysinfo() ... found checking for getloadavg() ... found checking for /proc/meminfo ... found checking for /proc/stat ... found checking for PCRE library ... found checking for PCRE JIT support ... found checking for OpenSSL library ... found checking for zlib library ... found creating objs/Makefile Configuration summary + using system PCRE library + using system OpenSSL library + using system zlib library + jemalloc library is disabled nginx path prefix: "/usr/local/nginx" nginx binary file: "/usr/local/nginx/sbin/nginx" nginx modules path: "/usr/local/nginx/modules" nginx configuration prefix: "/usr/local/nginx/conf" nginx configuration file: "/usr/local/nginx/conf/nginx.conf" nginx pid file: "/usr/local/nginx/logs/nginx.pid" nginx error log file: "/usr/local/nginx/logs/error.log" nginx http access log file: "/usr/local/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"
5.编译
命令:make //这就是刚刚安装的编译器
[root@localhost tengine-2.3.2]# make make -f objs/Makefile make[1]: 进入目录“/test/tengine/tengine-2.3.2” src/core/ngx_syslog.c cc -c -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -I src/core -I src/event -I src/event/modules -I src/os/unix -I src/proc -I objs \ -o objs/src/event/ngx_event.o \ src/event/ngx_event.c cc -c -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -I src/core -I src/event -I src/event/modules -I src/os/unix -I src/proc -I objs \ -o objs/src/event/ngx_event_timer.o \ src/event/ngx_event_timer.c cc -c -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -I src/core -I src/event -I src/event/modules -I src/os/unix -I src/proc -I objs \ -o objs/src/event/ngx_event_posted.o \ objs/src/http/ngx_http_file_cache.o \ objs/src/http/ngx_http_write_filter_module.o \ objs/src/http/ngx_http_header_filter_module.o \ objs/src/http/modules/ngx_http_chunked_filter_module.o \ objs/src/http/modules/ngx_http_range_filter_module.o \ objs/src/http/modules/ngx_http_gzip_filter_module.o \ objs/src/http/ngx_http_postpone_filter_module.o \ objs/src/http/modules/ngx_http_ssi_filter_module.o \ objs/src/http/modules/ngx_http_charset_filter_module.o \ objs/src/http/modules/ngx_http_userid_filter_module.o \ objs/src/http/modules/ngx_http_headers_filter_module.o \ objs/src/http/ngx_http_copy_filter_module.o \ objs/src/http/modules/ngx_http_not_modified_filter_module.o \ objs/src/http/modules/ngx_http_static_module.o \ objs/src/http/modules/ngx_http_autoindex_module.o \ objs/src/http/modules/ngx_http_index_module.o \ objs/src/http/modules/ngx_http_mirror_module.o \ objs/src/http/modules/ngx_http_try_files_module.o \ objs/src/http/modules/ngx_http_auth_request_module.o \ objs/src/http/modules/ngx_http_auth_basic_module.o \ objs/src/http/modules/ngx_http_access_module.o \ objs/src/http/modules/ngx_http_limit_conn_module.o \ objs/src/http/modules/ngx_http_limit_req_module.o \ objs/src/http/modules/ngx_http_geo_module.o \ objs/src/http/modules/ngx_http_map_module.o \ objs/src/http/modules/ngx_http_split_clients_module.o \ objs/src/http/modules/ngx_http_referer_module.o \ objs/src/http/modules/ngx_http_rewrite_module.o \ objs/src/http/modules/ngx_http_ssl_module.o \ objs/src/http/modules/ngx_http_proxy_module.o \ objs/src/http/modules/ngx_http_fastcgi_module.o \ objs/src/http/modules/ngx_http_upstream_zone_module.o \ objs/src/http/modules/ngx_http_stub_status_module.o \ objs/ngx_modules.o \ -ldl -lpthread -lcrypt -lpcre -lssl -lcrypto -ldl -lpthread -lz \ -Wl,-E sed -e "s|%%PREFIX%%|/usr/local/nginx|" \ -e "s|%%PID_PATH%%|/usr/local/nginx/logs/nginx.pid|" \ -e "s|%%CONF_PATH%%|/usr/local/nginx/conf/nginx.conf|" \ -e "s|%%ERROR_LOG_PATH%%|/usr/local/nginx/logs/error.log|" \ < man/nginx.8 > objs/nginx.8 make[1]: 离开目录“/test/tengine/tengine-2.3.2”
因为内容太多,我删了一部分,make编译会显示很多内容。
6.安装
命令:make install
[root@localhost tengine-2.3.2]# make install make -f objs/Makefile install make[1]: 进入目录“/test/tengine/tengine-2.3.2” test -d '/usr/local/nginx' || mkdir -p '/usr/local/nginx' test -d '/usr/local/nginx/sbin' \ || mkdir -p '/usr/local/nginx/sbin' test ! -f '/usr/local/nginx/sbin/nginx' \ || mv '/usr/local/nginx/sbin/nginx' \ '/usr/local/nginx/sbin/nginx.old' cp objs/nginx '/usr/local/nginx/sbin/nginx' test -d '/usr/local/nginx/conf' \ || mkdir -p '/usr/local/nginx/conf' cp conf/koi-win '/usr/local/nginx/conf' cp conf/koi-utf '/usr/local/nginx/conf' cp conf/win-utf '/usr/local/nginx/conf' test -f '/usr/local/nginx/conf/mime.types' \ || cp conf/mime.types '/usr/local/nginx/conf' cp conf/mime.types '/usr/local/nginx/conf/mime.types.default' test -f '/usr/local/nginx/conf/fastcgi_params' \ || cp conf/fastcgi_params '/usr/local/nginx/conf' cp conf/fastcgi_params \ '/usr/local/nginx/conf/fastcgi_params.default' test -f '/usr/local/nginx/conf/fastcgi.conf' \ || cp conf/fastcgi.conf '/usr/local/nginx/conf' cp conf/fastcgi.conf '/usr/local/nginx/conf/fastcgi.conf.default' test -f '/usr/local/nginx/conf/uwsgi_params' \ || cp conf/uwsgi_params '/usr/local/nginx/conf' cp conf/uwsgi_params \ '/usr/local/nginx/conf/uwsgi_params.default' test -f '/usr/local/nginx/conf/scgi_params' \ || cp conf/scgi_params '/usr/local/nginx/conf' cp conf/scgi_params \ '/usr/local/nginx/conf/scgi_params.default' test -f '/usr/local/nginx/conf/nginx.conf' \ || cp conf/nginx.conf '/usr/local/nginx/conf/nginx.conf' cp conf/nginx.conf '/usr/local/nginx/conf/nginx.conf.default' test -d '/usr/local/nginx/logs' \ || mkdir -p '/usr/local/nginx/logs' test -d '/usr/local/nginx/logs' \ || mkdir -p '/usr/local/nginx/logs' test -d '/usr/local/nginx/html' \ || cp -R html '/usr/local/nginx' test -d '/usr/local/nginx/logs' \ || mkdir -p '/usr/local/nginx/logs' make[1]: 离开目录“/test/tengine/tengine-2.3.2”
7.启动测试
可能之前的实验,安装过httpd服务。如果直接启动nginx会有冲突,确保关闭httpd
命令:systemctl stop httpd
/usr/local/nginx/sbin/nginx //启动
systemctl stop firewalld //关闭防火墙
[root@localhost tengine-2.3.2]# systemctl stop httpd [root@localhost tengine-2.3.2]# /usr/local/nginx/sbin/nginx [root@localhost tengine-2.3.2]# systemctl stop firewalld
使用浏览器访问本机ip:http://127.0.0.1,如果能看到NGINX的网页,说明部署成功。
总结
通过本文章了解源码包,学习获取源码包,安装程序,注意要联网,不然会下载失败的。