源码包的部署
例:安装nginx
1、解压nginx
[root@fishman-160 ~]# tar -zxvf nginx-1.25.1.tar.gz
2、编译
[root@fishman-160 nginx-1.25.1]# ./configure --prefix=/usr/local/nginx #prefiex 指定安装路径
checking for OS
+ Linux 4.18.0-500.el8.x86_64 x86_64
checking for C compiler ... found
+ using GNU C compiler
+ gcc version: 8.5.0 20210514 (Red Hat 8.5.0-20) (GCC)
.....
--enable--ssl 开启
--disable --filter 关闭
--with-http_ssl_module 关联
编译报错的话需要清理
[root@fishman-160 nginx-1.25.1]# make clean
rm -rf Makefile objs
把源码文件编译成可执行的二进制
[root@fishman-160 nginx-1.25.1]# make -j4 #j4就是4线程
3、安装
root@fishman-160 nginx-1.25.1]# make install #安装
make -f objs/Makefile install
make[1]: 进入目录“/root/nginx-1.25.1”
......
[root@fishman-160 sbin]# ls
nginx
[root@fishman-160 sbin]# ./nginx 启动nginx
[root@fishman-160 sbin]# netstat -ntlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1/systemd
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 10934/nginx: master
tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN 1542/dnsmasq
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1007/sshd
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 1012/cupsd
tcp 0 0 127.0.0.1:6010 0.0.0.0:* LISTEN 5751/sshd: root@pts
tcp 0 0 127.0.0.1:6011 0.0.0.0:* LISTEN 8144/sshd: root@pts
tcp6 0 0 :::111 :::* LISTEN 1/systemd
tcp6 0 0 :::22 :::* LISTEN 1007/sshd
tcp6 0 0 ::1:631 :::* LISTEN 1012/cupsd
tcp6 0 0 ::1:6010 :::* LISTEN 5751/sshd: root@pts
tcp6 0 0 ::1:6011 :::* LISTEN 8144/sshd: root@pts
4、卸载
[root@fishman-160 local]# ls
bin etc games include lib lib64 libexec nginx sbin share src
[root@fishman-160 local]# rm -rf nginx #prefix指定了安装目录,递归删除就可以
[root@fishman-160 local]# ls
bin etc games include lib lib64 libexec sbin share src
5、扩展
安装时显示库已经安装,但是configure时又说找不到。怎么办?
解决:安装了库,显示找不到。这种情况下,需要安装库的开发文件
[root@fishman-160 Packages]# rpm -qpl e2fsprogs-devel-1.42.9-19.el7.x86_64.rpm
警告:e2fsprogs-devel-1.42.9-19.el7.x86_64.rpm: 头V3 RSA/SHA256 Signature, 密钥 ID f4a80eb5: NOKEY
/usr/include/e2p
/usr/include/e2p/e2p.h
/usr/include/ext2fs
/usr/include/ext2fs/bitops.h #.h的文件都是头文件,有了这些.h的头文件,才能找到对应的库文件。所以库文件和devel开发包都需要安装
/usr/include/ext2fs/ext2_err.h
/usr/include/ext2fs/ext2_ext_attr.h
/usr/include/ext2fs/ext2_fs.h
/usr/include/ext2fs/ext2_io.h
/usr/include/ext2fs/ext2_types-x86_64.h
/usr/include/ext2fs/ext2_types.h
/usr/include/ext2fs/ext2fs.h
/usr/include/ext2fs/ext3_extents.h
/usr/include/ext2fs/qcow2.h
/usr/include/ext2fs/tdb.h
6、集成到systemd
-
创建一个 systemd 服务文件:
在
/lib/systemd/system/
目录中创建一个新的 systemd 服务文件,例如nginx.service
,并使用 root 权限编辑它:sudo vim /lib/systemd/system/nginx.service
在这个文件中,添加以下内容:
[Unit] Description=The NGINX HTTP and reverse proxy server After=network.target remote-fs.target nss-lookup.target [Service] Type=forking ExecStart=/usr/local/nginx/sbin/nginx ExecReload=/usr/local/nginx/sbin/nginx -s reload ExecStop=/usr/local/nginx/sbin/nginx -s quit PrivateTmp=true [Install] WantedBy=multi-user.target
请确保
ExecStart
、ExecReload
和ExecStop
的路径正确指向你通过源码编译安装的 Nginx 二进制文件。 -
重新加载 systemd 配置:
使用以下命令重新加载 systemd 配置,以便它可以识别新的服务文件:
sudo systemctl daemon-reload
-
启动 Nginx 服务:
现在你可以使用 systemctl 命令来启动、停止、重新加载和查看 Nginx 服务的状态了:
-
启动 Nginx 服务:
sudo systemctl start nginx
-
停止 Nginx 服务:
sudo systemctl stop nginx
-
重新加载 Nginx 配置:
sudo systemctl reload nginx
-
查看 Nginx 服务状态:
sudo systemctl status nginx
-
设置 Nginx 开机自启动:
sudo systemctl enable nginx
-
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了