Linux软件管理之编译安装与二进制安装

编译安装三部曲

第0步:安装依赖软件包,工具;
第一步:配置;./configure;安装到那个目录,不指定默认/usr/local下边,可以指定开启/关闭功能;
第二步:编译;make;把代码-->命令;
第三步:编译安装;make install;创建目录,复制配置,复制命令,复制到指定目录;
完成测试;

编译安装,可以自定义安装,yum就不可以自定义,如果yum没有安装源,也需要编译安装;

编译本质:源代码(C语言)-->命令;

案例1,编译安装cmatrix:

0)上传软件包并安装依赖;cmatrix-1.2a.tar.gz;
[root@web01 tools]# rz -E
解压,进入压缩包,安装依赖
[root@web01 tools]# tar xf cmatrix-1.2a.tar.gz
[root@web01 tools]# cd cmatrix-1.2a/
[root@web01 cmatrix-1.2a]# ll
[root@web01 cmatrix-1.2a]# yum install -y ncurses-devel //依赖

1)./configure配置,需要再代码目录下执行
[root@web01 cmatrix-1.2a]# ./configure
[root@web01 cmatrix-1.2a]# echo $?
0 //结果是0,说明./configure成功了
如果不是0,则可能出错了,需要根据错误来找解决方法;一般需要依赖

2)进行编译
[root@web01 cmatrix-1.2a]# make
[root@web01 cmatrix-1.2a]# echo $?
0
如果不是0,则可能出错了,需要根据错误来找解决方法;一般需要依赖;如果缺少依赖,需要安装完依赖,再次执行从解压包开始

3)make install
[root@web01 cmatrix-1.2a]# make install
[root@web01 cmatrix-1.2a]# echo $?
0 //如果第二步没问题,这一步很少有问题

4)运行检查
[root@web01 cmatrix-1.2a]# cmatrix

5)清理战场,清理掉软件包,解压目录,这时候可以执行命令了,其他东西都不需要了

[root@web01 cmatrix-1.2a]# which cmatrix
/usr/local/bin/cmatrix



案例2:编译安装nginx

编译安装nginx搭建小游戏网站
编译安装三步曲:
1,./configure,对软件进行功能配置,指定安装目录,开启或关闭功能;
2,make,根据上一步的配置进行编译(C语言代码->命令);
3,make install,安装(创建目录,命令,配置文件复制到指定目录);

1,下载nginx代码
wget -P /server/tools/ https://nginx.org/download/nginx-1.22.1.tar.gz
2,解压并进入目录
[root@web01 tools]# tar xf nginx-1.22.1.tar.gz
[root@web01 tools]# cd nginx-1.22.1/
进行./config --help //可查看帮助
--prefix=/app/nginx-1.22.1/ //指定到安装目录
--user=nginx --group=nginx //指定用户和组
--with-http_ssl_module
--with-http_v2_module
--with-http_stub_status_module
./configure --prefix=/app/nginx-1.22.1 --user=nginx --group=nginx --with-http_ssl_module --with-http_v2_module --with-http_stub_status_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.
解决:
yum -y install pcre-devel
yum -y install openssl-devel
都解决之后,编译成功
make
make install
编译安装完成!~
检查目录:
[root@web01 nginx-1.22.1]# ll /app/nginx-1.22.1/
创建用户:
[root@web01 nginx-1.22.1]# useradd -s /sbin/nologin -M nginx //先不管UID
创建软链接:
[root@web01 nginx-1.22.1]# ln -s /app/nginx-1.22.1/ /app/nginx

编译安装的软件无法用systemctl管理
管理编译安装的nginx
提示:需要关闭防火墙和selinux
[root@web01 nginx-1.22.1]# /app/nginx/sbin/nginx -V //查看版本编译信息
[root@web01 nginx-1.22.1]# /app/nginx/sbin/nginx //直接回车,就是启动
[root@web01 nginx-1.22.1]# ps -ef | grep nginx
[root@web01 nginx-1.22.1]# kill nginx_PID //关闭nginx,PID就是上一步查的PID
检查端口
[root@web01 nginx-1.22.1]# ss -lntup | grep nginx
访问:直接输入nginx的IP地址即可访问(需内网可连接访问)

代码目录:
/app/nginx/html/下面,默认显示index.html代码

 

案例3:二进制安装Tomcat

二进制方式安装Tomcat
1,部署tomcat
安装JDK(使用java程序或代码必备工具)
下载tomcat
解压
创建软链接
启动
查看

安装JDK
yum -y install java
下载tomcat
tomcat.apache.org
wget --no-check-certificate -P /server/tools https://dlcdn.apache.org/tomcat/tomcat-9/v9.0.70/bin/apache-tomcat-9.0.70.tar.gz //有提示,就加上--no-check-certificate
https://mirrors.aliyun.com/apache
wget -P /server/tools/tomcat https://mirrors.aliyun.com/apache/tomcat/tomcat-9/v9.0.70/bin/apache-tomcat-9.0.70.tar.gz
解压
[root@web01 tomcat]# tar xf apache-tomcat-9.0.70.tar.gz -C /app/
创建软链接
[root@web01 tomcat]# ln -s /app/apache-tomcat-9.0.70/ /app/tomcat
启动
[root@web01 tomcat]# /app/tomcat/bin/startup.sh
[root@web01 tomcat]# /app/tomcat/bin/shutdown.sh //关闭
检查
[root@web01 tomcat]# ps -ef | grep java //tomcat只是个壳,运行的是java代码
[root@web01 tomcat]# ss -lntup | grep java

访问:浏览器直接访问即可,记得加上端口号:8080

posted @ 2022-12-17 16:16  mclind  阅读(514)  评论(0编辑  收藏  举报