继上次linux程序包管理(2)之yum的配置及使用,大家都很疑惑不是有yum就行了吗干嘛还要学习源码安装,听说源码安装很费事也很麻烦,是的 yum是用起来简单方便,但是yum是直接写在镜像里面的,所以一些安装包的版本就有点低了。而且有些特性是编译选定的,如果编译未选定此特性,将无法使用;rpm包的版本会落后于源码包,甚至落后很多。俗话说有利必有一弊,对于一些安装包已经更新换代了,大家都在接受新事物你还在原地不动,这对于it农民工来说不合适吧,所以源码安装就解决了这个问题,两者的结合三字棒棒哒。不要怕麻烦小编这就将整理好的源码安装方法告诉你,跟着下面的学习再多加练习不怕你不会源码安装,哈哈。学会yum和源码安装走遍整个linux不成问题哦。下面就讲下二进制格式如何进行源码安装。
一.源码编译C源代码前提准备开发环境(编译环境):
1.开发环境:开发库,头文件
Glibc:标准库
2.开发工具: make,gcc等
通过“包组“提供开发组件:
Centos 6: “Development Tools“,Server Platform Development”
3.使用环境
C环境,C++,(纯静态语言)
Gcc:GUN C Complier, C
g++
二.源码安装需要的管理工具
1.make:项目管理工具,
makefile:定义了make(调用Gcc,G++)命令按何种次序去编译这些 源程序文件中的源程序
outomake,-à生成makefile.in(半成品)---.>makefile
outoconf(给项目生成脚本)---àconfigure
2.make install (编译安装)
三.编译安装的步骤
首先将源码包下载下来
1 ./configure 一般用到的选项各意义
--help 获取支持使用的选项
安装选项:
--prefix=/path/to/somewhere 软件默认安装位置(/usr/local)
-sysconfdir=/PATH/to/CONFFILE_PATH 指定配置文件路径(若不指定路径则安装在默认的路径下)
System types: 交叉编译时才会用的到
Options Features: 可选特性
--disable-FEATURE
--enable-FEATURE[=ARG]
Optional Packages:可选包即依赖到的包
--with-PACKAGE[=ARG]
--without-PACKAGE
/configure 选项功能:1>.让用户选定编译特性;2>.检查编译环境
2.开始编译安装
# tar xf “xxxxxxxx” # cd “XX”目录下 # ./configure --prefix=/user/local/”XX” --conf-path=/etc/”XX”/”XX.conf” # make # make install # /usr/local/”XX”/sbin/”xx”
3.安装后所需操作:
1>.导出为二进制程序目录至PATH环境变量中:
作用:修改PATH环境变量,以能够识别此程序的二进制文件路径:
编辑文件: /etc/profile.d/NAME.sh
Export PATH=/PATH/TO/BIN:$PATH
修改/etc/profile文件
在/etc/profile.d目录建立一个以.sh为名称后缀的文件,在里面定义export PATH=$PATH:/path/to/somewhere
也可在/etc/profile添加此路径
2>导出库文件:
作用:默认情况下,系统搜索文件的路径/lib, /usr/lib;要增添额外搜寻路径;
在/etc/ld.so.conf中创建以.conf为后缀名的文件,而后把要增添的路径直接写至此文件中;
ldconfig -v 让系统重新生成缓存
3>导出头文件:
默认: /usr/include
增添头文件搜寻路径,使用链接进行;
/usr/local/”xx”/include/ /usr/include/
两种方式:
ln -sv /usr/local/”xx”/include/* /usr/include/
ln -sv /usr/local/”xx”/include /usr/include/”xx”
4>导出帮助手册:
man 文件路径:安装在—prefix制定的目录下的man目录: /usr/share/man
1> man -M /PATH/to/MAN_DIR COMMAND
2> 在/etc/man.config 中添加一条MANPATH
练习:二进制源码编译安装httpd服务
l 首先将所需的源码包下载下来
1.检查 “Development Tools“,Server Platform Development”这两个包组是否被安装过
[[email protected] ~]# yum grouplist
2.开始编译安装
[[email protected] httpd-2.2.29]# ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd ............................................................................................ //因中间有许多繁多文件需要创建,所以此处省略部分内容 config.status: creating support/split-logfile config.status: creating build/rules.mk config.status: creating build/pkg/pkginfo config.status: creating build/config_vars.sh config.status: creating include/ap_config_auto.h config.status: include/ap_config_auto.h is unchanged config.status: executing default commands v [[email protected] httpd-2.2.29]# make v ........................................................................................ //此处省略n多内容 make[1]: Leaving directory `/root/httpd-2.2.29‘ v [[email protected] httpd-2.2.29]# make install ....................................................................................... //此处省略n多内容 [PRESERVING EXISTING ICONS SUBDIR: /usr/local/apache/icons] [PRESERVING EXISTING CGI SUBDIR: /usr/local/apache/cgi-bin] Installing header files Installing build system files Installing man pages and online manual make[1]: Leaving directory `/root/httpd-2.2.29‘ //安装ok
3.去已安装目录下查看文件
[[email protected] httpd-2.2.29]# cd /usr/local/apache/ [[email protected] apache]# ls bin build cgi-bin error htdocs icons include lib logs man manual modules //文件众多只需关注bin ,include, man , modules,就ok [[email protected] apache]# ls bin ab apu-1-config dbmmanage htcacheclean htpasswd logresolve apachectl apxs envvars htdbm httpd rotatelogs apr-1-config checkgid envvars-std htdigest httxt2dbm //可以看到有个httpd和apachectl文件,apachectl是控制httpd服务启动
4. 使用apachectl开启httpd服务
[[email protected] apache]# bin/apachectl start httpd: apr_sockaddr_info_get() failed for chang httpd: Could not reliably determine the server‘s fully qualified domain name, using 127.0.0.1 for ServerName //无关紧要
5.查看httpd服务是否开启
[[email protected] apache]# netstat -tnlp 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:22 0.0.0.0:* LISTEN 1807/sshd tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 1625/cupsd tcp 0 0 127.0.0.1:6010 0.0.0.0:* LISTEN 2236/sshd tcp 0 0 127.0.0.1:6011 0.0.0.0:* LISTEN 2265/sshd tcp 0 0 0.0.0.0:56271 0.0.0.0:* LISTEN 1593/rpc.statd tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1491/rpcbind tcp 0 0 :::22 :::* LISTEN 1807/sshd tcp 0 0 ::1:631 :::* LISTEN 1625/cupsd tcp 0 0 ::1:25 :::* LISTEN 1982/master tcp 0 0 ::1:6010 :::* LISTEN 2236/sshd tcp 0 0 ::1:6011 :::* LISTEN 2265/sshd tcp 0 0 :::40035 :::* LISTEN 1593/rpc.statd tcp 0 0 :::111 :::* LISTEN 1491/rpcbind tcp 0 0 :::80 :::* LISTEN 30160/httpd //此时httpd服务已经开启了
6.访问http服务
能够访问的到 Note:如果访问不到可能是防火墙和selinux没关此时关上即可 [[email protected] apache]# iptables -F [[email protected] apache]# setenforce 0
7.导出二进制文件
[[email protected] apache]# echo $PATH /usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin [[email protected] apache]# cd bin [[email protected] bin]# ls ab apu-1-config dbmmanage htcacheclean htpasswd logresolve apachectl apxs envvars htdbm httpd rotatelogs apr-1-config checkgid envvars-std htdigest httxt2dbm [[email protected] bin]# pwd /usr/local/apache/bin [[email protected] bin]# vim /etc/profile.d/httpd.sh [[email protected] bin]# source /etc/profile.d/httpd.sh
8.导出库文件
[[email protected] ~]# cd /etc/ld.so.conf.d/ [[email protected] ld.so.conf.d]# ls kernel-2.6.32-504.el6.x86_64.conf qt-x86_64.conf mysql-x86_64.conf xulrunner-64.conf [[email protected] ld.so.conf.d]# vim apache.conf [[email protected] ld.so.conf.d]# ldconfig -v /usr/local/apache: /usr/lib64/mysql: libmysqlclient.so.16 -> libmysqlclient.so.16.0.0 libmysqlclient_r.so.16 -> libmysqlclient_r.so.16.0.0 /usr/lib64/qt-3.3/lib: libqui.so.1 -> libqui.so.1.0.0 libqt-mt.so.3 -> libqt-mt.so.3.3.8 /usr/lib64/xulrunner: libmozsqlite3.so -> libmozsqlite3.so libmozalloc.so -> libmozalloc.so libxpcom.so -> libxpcom.so libxul.so -> libxul.so //此处省略n多库文件
9.导出头文件
[[email protected] apache]# ln -sv /usr/local/apache/include /usr/include/apache "/usr/include/apache" -> "/usr/local/apache/include"
10.导出man帮助文件