实验二:源代码软件的编译安装
3 源代码软件的编译安装
3.1 问题
RPM包相当于一个傻瓜化的程序,什么都预先定制、编译好了,从而大大简化了Linux 下应用软件安装的难度。但也正因为如此,RPM安装也存在一定的局限性:仅适用于特定系统环境、版本更新相对滞后、功能细节难以定制。于是,选择可“DIY”的源代码来定制安装就显得更加实用、高端、大气 …… :) 。
1.通过编译的方式安装httpd网站服务软件。
2.通过编译的方式安装aria2下载工具。
3.通过软件包的内置脚本安装Webmin管理套件。
3.2 方案
3.3 实现
1.确认开发环境,了解源码编译安装的基本过程
1)确认gcc、gcc-c++、make等开发环境
通过前一节的 yum-y groupinstall "开发工具" "开发库" 可准备好开发环境。
确认相关工具的版本:
1. [root@svr5 ~]# gcc--version //查看gcc编译器版本
2. gcc(GCC)4.1.220080704(Red Hat 4.1.2-54)
3. Copyright(C)2006 Free Software Foundation, Inc.
4. 本程序是自由软件;请参看源代码的版权声明。本软件没有任何担保;
5. 包括没有适销性和某一专用目的下的适用性担保。
6. [root@svr5 ~]# make --version //查看make工具版本
7. GNU Make 3.81
8. Copyright(C)2006 Free Software Foundation, Inc.
9. This is free software; see the source for copying conditions.
10.There is NO warranty; not even for MERCHANTABILITY or FITNESSFOR A
11.PARTICULAR PURPOSE.
12.
13.This program built for x86_64-redhat-linux-gnu
2)了解编译流程,其中各步骤的作用,如图-9所示
图-9
2.编译安装httpd网站服务器软件
1)解包、确认解包后的源码目录
1. [root@svr5 ~]# cd /root/Desktop/tools/
2. [root@svr5 tools]# tar zxf httpd-2.2.25.tar.gz //释放源码包
3. [root@svr5 tools]# cd httpd-2.2.25 //切换到源码目录
4. [root@svr5 httpd-2.2.25]#ls //查看源码包文件列表
5. ABOUT_APACHE config.layouthttpd.spec LICENSE README.platforms
6. acinclude.m4 configure include Makefile.in README-win32.txt
7. Apache.dsw configure.in INSTALL Makefile.win ROADMAP
8. build docs InstallBin.dsp modules server
9. BuildAll.dsp emacs-style LAYOUT NOTICE srclib
10.BuildBin.dsp httpd.deplibhttpd.depNWGNUmakefile support
11.buildconf httpd.dsp libhttpd.dsp os test
12.CHANGES httpd.mak libhttpd.mak README VERSIONING
使用less查看README文件可了解关于本软件的相关介绍,如图-10所示。
图-10
使用less查看INSTALL文件可了解本软件的安装及使用方法,如图-11所示。
图-11
2)配置,./configure
在正式配置之前,可先执行以下操作:
1. [root@svr5 httpd-2.2.25]# ./configure -help | less
2. ....
来了解本软件的详细配置参数,比如较通用的 --prefix= 用来指定将软件安装到哪一个文件夹,如图-12所示。
图-12
本例中做一个简单配置,将httpd软件包配置为安装到 /usr/local/httpd,对应的配置操作如下:
1. [root@svr5 httpd-2.2.25]# ./configure --prefix=/usr/local/httpd
2. ....
3. config.status: creating build/pkg/pkginfo
4. config.status: creating build/config_vars.sh
5. config.status: creating include/ap_config_auto.h
6. config.status: executing default commands
确保没有出现“Warning”、“Error”等异常情况,配置就算完成了。
3)编译,make
直接执行make操作,等待编译完成。gcc编译器会不断的输出各种过程信息,基本都可以忽略(除非出现警告、错误等情况):
1. [root@svr5 httpd-2.2.25]# make
2. ....
3. /root/Desktop/tools/httpd-2.2.25/srclib/apr/libapr-1.la -luuid-lrt-lcrypt-lpthread-ldl
4. make[1]: Leaving directory `/root/Desktop/tools/httpd-2.2.25'
4)安装,makeinstall
make编译完成后,源文件和编译好的.o文件、二进制程序等仍然只在源码目录下:
1. [root@svr5 httpd-2.2.25]# ls/usr/local/httpd/ //目标文件夹还不存在
2. ls:/usr/local/httpd/:没有那个文件或目录
需要执行makeinstall将相关文件部署到系统:
1. [root@svr5 httpd-2.2.25]# make install
2. ....
3. mkdir/usr/local/httpd/cgi-bin
4. Installing header files
5. Installing build systemfiles
6. Installing man pages andonline manual
7. mkdir/usr/local/httpd/man
8. mkdir/usr/local/httpd/man/man1
9. mkdir/usr/local/httpd/man/man8
10.mkdir/usr/local/httpd/manual
11.make[1]: Leaving directory `/root/Desktop/tools/httpd-2.2.25'
成功安装以后,再次确认安装目录:
1. [root@svr5 httpd-2.2.25]# ls/usr/local/httpd/ //安装后的程序目录
2. bin cgi-bin error icons lib man modules
3. build confhtdocs include logs manual
5)程序测试
切换到安装好的/usr/local/httpd/文件夹,通过bin/子目录下的服务控制脚本apachectl启动网站服务程序。
1. [root@svr5 httpd-2.2.25]# cd /usr/local/httpd/
2. [root@svr5 httpd]# bin/apachectl start
3. httpd:apr_sockaddr_info_get() failed for svr5.tarena.com
4. httpd: Could not reliablydetermine the server's fully qualified domain name, using 127.0.0.1 for ServerName
5. //因未作网站服务配置,所以提示以127.0.0.1做网站名称
启动完成后,通过本机的firefox浏览器访问 http://localhost/,应该能看到“IT Works! ”的默认网页,如图-13所示,说明httpd安装并运行成功。
图-13
上述网页显示的是安装目录下 htdocs/子目录下的index.html文件的内容,实际上htdocs/ 是源码编译安装的httpd服务的默认网站根目录:
1. [root@svr5 httpd]# cat /usr/local/httpd/htdocs/index.html
2. <html><body><h1>It works!</h1></body></html>
3. [root@svr5 httpd]#
3.编译安装aria2下载工具
1)解包、进入源码目录
1. [root@svr5 httpd]# cd /root/Desktop/tools/
2. [root@svr5 tools]# tar zxf aria2-1.17.1.tar.gz
3. [root@svr5 tools]# cd aria2-1.17.1
2)配置,./configure
1. [root@svr5 aria2-1.17.1]# ./configure
2. ....
3. Message Digest: yes
4. WebSocket: yes
5. Libaria2: no
6. bash_completiondir: ${datarootdir}/doc/${PACKAGE_TARNAME}/bash_completion
7. Static build:
3)编译、安装,make&& make install
1. [root@svr5 aria2-1.17.1]# make && make install
2. ....
3. make[2]: Entering directory `/root/Desktop/tools/aria2-1.17.1'
4. make[2]: Nothing to bedone for `install-exec-am'.
5. /bin/mkdir-p '/usr/local/share/doc/aria2'
6. /usr/bin/install -c -m 644 README README.rst'/usr/local/share/doc/aria2'
7. make[2]: Leaving directory `/root/Desktop/tools/aria2-1.17.1'
8. make[1]: Leaving directory`/root/Desktop/tools/aria2-1.17.1'
4)程序测试
在此前安装的httpd网站根目录下建立一个测试文件,比如可以将/boot/目录下vmlinuz开头的内核文件复制过去:
1. [root@svr5 aria2-1.17.1]# cp/boot/vmlinuz-2.6.18-348.el5 \
2. /usr/local/httpd/htdocs/vmlinuz.knl
3. [root@svr5 aria2-1.17.1]# ls-lh/usr/local/httpd/htdocs/vmlinuz.knl
4. -rw-r--r--1 root root2.1M 09-2717:30/usr/local/httpd/htdocs/vmlinuz.knl
然后使用aria2c下载vmlinuz.knl文件,下载格式“aria2c 文件的URL”,若成功下载所要的文件,说明程序顺利安装并可正常使用:
1. [root@svr5 aria2-1.17.1]# cd //返回root的宿主目录
2. [root@svr5 ~]# aria2c http://localhost/vmlinuz.knl //执行下载
3.
4. 09/2717:34:04[NOTICE] Download complete:/root/vmlinuz.knl
5.
6. 下载结果:
7. gid|stat|avg speed |path/URI
8. ======+====+===========+=======================================================
9. 48e71e|OK | 289MiB/s|/root/vmlinuz.knl
10.
11.状态标识:
12.(OK):完成下载。
13.[root@svr5 ~]# ls-lhvmlinuz.knl //确认下载结果
14.-rw-r--r--1 root root2.1M 09-2717:34vmlinuz.knl
3.4 扩展
1.编译安装webmin管理套件
Webmin 是用于从Web 界面管理Linux 主机的程序套件,主要使用Perl 语言开发。安装并运行Webmin 应用程序以后,管理员从浏览器中即可远程登录该系统,能够更轻松、便捷地完成各种系统管理任务。
1)解包、进入源码目录
1. [root@svr5 ~]# cd /root/Desktop/tools/
2. [root@svr5 tools]# tar zxf webmin-1.630.tar.gz
3. [root@svr5 tools]# cd webmin-1.630
2)执行安装脚本setup.sh
通过查看README文件可获知,安装webmin不需要./configure等过程,而是直接执行其提供的 setup.sh脚本即可,如图-14所示。
图-14
执行 setup.sh脚本后,会提示确认系列问题,基本上直接回车即可:
1. [root@svr5 webmin-1.630]# ./setup.sh
2. ***********************************************************************
3. * Welcome to the Webmin setup script, version 1.630*
4. ***********************************************************************
5. Webmin is a web-based interface that allows Unix-like operating
6. systems and common Unixservices to be easily administered.
7.
8. Installing Webmin in /root/Desktop/tools/webmin-1.630...
9.
10.***********************************************************************
11.Webmin uses separatedirectories for configuration files and log files.
12.Unless you want to runmultiple versions of Webmin at the same time
13.you can just accept thedefaults.
14.
15.Config file directory [/etc/webmin]: //按Enter键确认
16.Log file directory [/var/webmin]: //按Enter键确认
17.
18.***********************************************************************
19.Webmin is written entirelyin Perl. Please enter the full path to the
20.Perl 5 interpreter on your system.
21.
22.Full path to perl(default/usr/bin/perl): //按Enter键确认
23.
24.Testing Perl ...
25.Perl seems to be installedok
26.
27.***********************************************************************
28.Operating system name:Redhat Enterprise Linux
29.Operating system version:5
30.
31.***********************************************************************
32.Webmin uses its own passwordprotected web server to provideaccess
33.to the administrationprograms. The setup script needs to know :
34.- What port to run the webserver on. There must not be another
35.web server already using this port.
36.- The login name required toaccess the web server.
37.- The password required toaccess the web server.
38.- If the webserver should useSSL(if your system supports it).
39.- Whether to start webmin atboot time.
40.
41.Web server port(default10000): //默认端口10000,按Enter键确认
42.Login name(default admin): //管理员账号,默认为admin,按Enter键确认
43.Login password: //设置管理密码
44.Password again: //再次设置管理密码
45.The Perl SSLeay library isnot installed. SSL not available.
46.Start Webmin at boot time(y/n): y //是否开机启动webmin,输入y 是
47.....
48.Attempting to start Webminmini web server..
49.Starting Webmin server in /root/Desktop/tools/webmin-1.630
50.Pre-loaded WebminCore
51...done
52.
53.***********************************************************************
54.Webmin has been installedand started successfully. Use your web
55.browser to go to
56.
57. http://svr5.tarena.com:10000/
58.
59.and login with the name andpassword you entered previously.
3)测试webmin远程管理
通过本机浏览器访问http://localhost:10000,
或者从其他可连到本机的客户机访问 http://192.168.4.5:10000/,
将会可到Webmin管理套件的登录界面,如图-15所示,以安装时设置的管理员账号及密码登录。
图-15
成功登入后,通过左侧导航栏的“Webmin”-->“ChangeLanguage and Theme”可更改Web管理界面的语言,比如设为“Simplified Chinese(ZH_CN.UTF-8)”以使用中文界面,如图-16所示,注意要先勾选“Personal choice”自定义。
图-16
单击下方的“Make Changes”按钮保存语言设置,然后单击左侧导航栏底部的“Logout”按钮注销,回到登录界面重新登入,即可看到中文版的Webmin系统,如图-17所示。
图-17
通过Webmin管理平台可以完成许多系统管理任务,有兴趣的同学可自行探索。