linux主要目录
/boot /etc /usr /var /dev /lib /tmp /bin /sbin /proc /sys /mnt /media /home /root /misc /opt /srv /usr/share/man /etc, /bin, /sbin, /lib #系统启动就需要用到的程序,这些目录不能挂载额外的分区,必须在根文件系统的分区上 /usr/ #操作系统核心功能,可以单独分区 #单独分区,系统重装不影响软件使用 bin sbin lib /usr/local #第三方软件 bin sbin lib etc man /opt /proc /sys 不能单独分区,默认为空; /dev: 设备,不能单独分区; udev /root: 不能单独分区 /var:建议单独分区 /boot:内核,initrd(initramfs) 内核: POST-->BIOS(HD)-->(MBR)bootloader(文件系统结构,ext2, ext3, xfs)-->内核
Linux下rpm包x86、i386、i486、i586、i686和x86_64这些后缀含义
http://blog.csdn.net/iamlaosong/article/details/50114993
http://huanglianfeng.blog.51cto.com/4813074/1355429http://huanglianfeng.blog.51cto.com/4813074/1355429
软件包管理器的核心功能:
1、制作软件包;
2、安装、卸载、升级、查询、校验;
Redhat, SUSE, Debian Redhat, SUSE: RPM Redhat Package Manager PRM is Package Manager Debian: dpt
依赖关系:
X-->Y-->Z
X-->Y-->Z
前端工具:yum, apt-get
后端工具:RPM, dpt
yum: Yellowdog Update Modifier
rpm命令:
rpm:
数据库:/var/lib/rpm
rpmbuild:
安装、查询、卸载、升级、校验、数据库的重建、验正数据包等工作;
rpm命名:
包:组成部分
主包: bind-9.7.1-1.el5.i586.rpm 子包: bind-libs-9.7.1-1.el5.i586.rpm bind-utils-9.7.1-1.el5.i586.rpm 包名格式: name-version-release.arch.rpm bind-major.minor.release-release.arch.rpm
主版本号:重大改进
次版本号:某个子功能发生重大变化
发行号:修正了部分bug,调整了一点功能
[root@localhost ~]# uname -r 2.6.32-504.el6.x86_64 [root@localhost ~]# uname -a Linux localhost 2.6.32-504.el6.x86_64 #1 SMP Tue Sep 16 01:56:35 EDT 2014 x86_64 x86_64 x86_64 GNU/Linux [root@localhost ~]#
bind-9.7.1.tar.gz
rpm包:
二进制格式
rpm包作者下载源程序,编译配置完成后,制作成rpm包
bind-9.7.1-1.noarch.rpm
bind-9.7.1-1.ppc.rpm
rpm
1、安装
rpm -i /PATH/TO/PACKAGE_FILE -h: 以#显示进度;每个#表示2%; -v: 显示详细过程 -vv: 更详细的过程 rpm -ivh /PATH/TO/PACKAGE_FILE --nodeps: 忽略依赖关系; --replacepkgs: 重新安装,替换原有安装; --force: 强行安装,可以实现重装或降级;
2、查询
rpm -q PACKAGE_NAME: 查询指定的包是否已经安装 rpm -qa : 查询已经安装的所有包 rpm -qi PACKAGE_NAME: 查询指定包的说明信息; rpm -ql PACKAGE_NAME: 查询指定包安装后生成的文件列表; rpm -qc PACEAGE_NEME:查询指定包安装的配置文件; rpm -qd PACKAGE_NAME: 查询指定包安装的帮助文件; rpm -q --scripts PACKAGE_NAME: 查询指定包中包含的脚本 rpm -qf /path/to/somefile: 查询指定的文件是由哪个rpm包安装生成的; 如果某rpm包尚未安装,我们需查询其说明信息、安装以后会生成的文件; rpm -qpi /PATH/TO/PACKAGE_FILE rpm -qpl
3、升级
rpm -Uvh /PATH/TO/NEW_PACKAGE_FILE: 如果装有老版本的,则升级;否则,则安装; rpm -Fvh /PATH/TO/NEW_PACKAGE_FILE:如果装有老版本的,则升级;否则,退出; --oldpackage: 降级
4、卸载
rpm -e PACKAGE_NAME --nodeps
5、校验
rpm -V PACKAGE_NAME
6、重建数据库
rpm --rebuilddb: 重建数据库,一定会重新建立; --initdb:初始化数据库,没有才建立,有就不用建立;
7、检验来源合法性,及软件包完整性;
加密类型:
对称:加密解密使用同一个密钥
公钥:一对儿密钥,公钥,私钥;公钥隐含于私钥中,可以提取出来,并公开出去;
单向:
# ls /etc/pki/rpm-gpg/ RPM-GPG-KEY-redhat-release rpm -K /PAPT/TO/PACKAGE_FILE dsa, gpg: 验正来源合法性,也即验正签名;可以使用--nosignature,略过此项 sha1, md5: 验正软件包完整性;可以使用--nodigest,略过此项 rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release: 导入密钥文件
rpm包安装问题、cpio: read failed - Bad file descriptor (下载包格式不完整,需要重新下载)
[root@localhost Downloads]# rpm -ivh cpp-4.4.7-17.el6.x86_64.rpm warning: cpp-4.4.7-17.el6.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY Preparing... ########################################### [100%] 1:cpp ########################################### [100%] error: unpacking of archive failed on file /usr/libexec/gcc/x86_64-redhat-linux/4.4.4/cc1;58d83374: cpio: read failed - Bad file descriptor [root@localhost Downloads]# ls cloog-ppl-0.15.7-1.2.el6.x86_64.rpm gcc-4.4.7-17.el6.x86_64.rpm lftp-4.0.1.tar.bz2 mpfr-2.4.1-6.el6.x86_64.rpm cloog-ppl-0.15.7-1.2.el6.x86_64.rpm.1 gcc-4.5.1.tar.bz2 lftp-4.7.7.tar.xz ppl-0.10.2-11.el6.x86_64.rpm cpp-4.4.7-17.el6.x86_64.rpm gcc-c++-4.4.7-17.el6.x86_64.rpm libgcc-4.4.7-17.el6.x86_64.rpm readline-5.2.tar.gz cpp-4.4.7-17.el6.x86_64.rpm.1 gcc-c++-4.4.7-3.el6.x86_64.rpm libgomp-4.4.7-17.el6.x86_64.rpm [root@localhost Downloads]# rm -rf cpp-4.4.7-17.el6.x86_64.rpm.1 [root@localhost Downloads]# rm -rf cpp-4.4.7-17.el6.x86_64.rpm [root@localhost Downloads]# wget ftp://mirror.switch.ch/mirror/centos/6/os/x86_64/Packages/cpp-4.4.7-17.el6.x86_64.rpm --2017-03-26 14:33:44-- ftp://mirror.switch.ch/mirror/centos/6/os/x86_64/Packages/cpp-4.4.7-17.el6.x86_64.rpm => “cpp-4.4.7-17.el6.x86_64.rpm” Resolving mirror.switch.ch... 130.59.113.36, 2001:620:0:1002::20 Connecting to mirror.switch.ch|130.59.113.36|:21... connected. Logging in as anonymous ... Logged in! ==> SYST ... done. ==> PWD ... done. ==> TYPE I ... done. ==> CWD (1) /mirror/centos/6/os/x86_64/Packages ... done. ==> SIZE cpp-4.4.7-17.el6.x86_64.rpm ... 3908556 ==> PASV ... done. ==> RETR cpp-4.4.7-17.el6.x86_64.rpm ... done. Length: 3908556 (3.7M) (unauthoritative) 100%[=================================================================================================================>] 3,908,556 9.73K/s in 10m 33s 2017-03-26 14:44:26 (6.03 KB/s) - “cpp-4.4.7-17.el6.x86_64.rpm” saved [3908556] [root@localhost Downloads]# ls cloog-ppl-0.15.7-1.2.el6.x86_64.rpm gcc-4.5.1.tar.bz2 lftp-4.7.7.tar.xz ppl-0.10.2-11.el6.x86_64.rpm cloog-ppl-0.15.7-1.2.el6.x86_64.rpm.1 gcc-c++-4.4.7-17.el6.x86_64.rpm libgcc-4.4.7-17.el6.x86_64.rpm readline-5.2.tar.gz cpp-4.4.7-17.el6.x86_64.rpm gcc-c++-4.4.7-3.el6.x86_64.rpm libgomp-4.4.7-17.el6.x86_64.rpm gcc-4.4.7-17.el6.x86_64.rpm lftp-4.0.1.tar.bz2 mpfr-2.4.1-6.el6.x86_64.rpm [root@localhost Downloads]# rpm -ivh cpp-4.4.7-17.el6.x86_64.rpm warning: cpp-4.4.7-17.el6.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY Preparing... ########################################### [100%] 1:cpp ########################################### [100%] [root@localhost Downloads]#
rpm包安装问题2:安装ncurses-devel
http://rpm.pbone.net/index.php3
逐一安装依赖包
rpm包安装问题3:error while loading shared libraries
[root@localhost ~]# lftp root@192.168.1.18:22 lftp: error while loading shared libraries: libreadline.so.5: cannot open shared object file: No such file or directory tmux: error while loading shared libraries: libevent-1.4.so.2: cannot open shared object file: No such file or directory
原因一般有两个, 一个是操作系统里确实没有包含该共享库(lib*.so.*文件)或者共享库版本不对, 遇到这种情况那就去网上下载并安装上即可.
另外一个原因就是已经安装了该共享库, 但执行需要调用该共享库的程序的时候, 程序按照默认共享库路径找不到该共享库文件.
所以安装共享库后要注意共享库路径设置问题, 如下:
1) 如果共享库文件安装到了/lib或/usr/lib目录下, 那么需执行一下ldconfig命令
ldconfig命令的用途, 主要是在默认搜寻目录(/lib和/usr/lib)以及动态库配置文件/etc/ld.so.conf内所列的目录下, 搜索出可共享的动态链接库(格式如lib*.so*), 进而创建出动态装入程序(ld.so)所需的连接和缓存文件. 缓存文件默认为/etc/ld.so.cache, 此文件保存已排好序的动态链接库名字列表.
2) 如果共享库文件安装到了/usr/local/lib(很多开源的共享库都会安装到该目录下)或其它"非/lib或/usr/lib"目录下, 那么在执行ldconfig命令前, 还要把新共享库目录加入到共享库配置文件/etc/ld.so.conf中, 如下:
# cat /etc/ld.so.conf include ld.so.conf.d/*.conf # echo "/usr/local/lib" >> /etc/ld.so.conf # ldconfig
3) 如果共享库文件安装到了其它"非/lib或/usr/lib" 目录下, 但是又不想在/etc/ld.so.conf中加路径(或者是没有权限加路径). 那可以export一个全局变量LD_LIBRARY_PATH, 然后运行程序的时候就会去这个目录中找共享库.
LD_LIBRARY_PATH的意思是告诉loader在哪些目录中可以找到共享库. 可以设置多个搜索目录, 这些目录之间用冒号分隔开. 比如安装了一个mysql到/usr/local/mysql目录下, 其中有一大堆库文件在/usr/local/mysql/lib下面, 则可以在.bashrc或.bash_profile或shell里加入以下语句即可:
export LD_LIBRARY_PATH=/usr/local/mysql/lib:$LD_LIBRARY_PATH
一般来讲这只是一种临时的解决方案, 在没有权限或临时需要的时候使用.
4)如果程序需要的库文件比系统目前存在的村文件版本低,可以做一个链接
比如:
error while loading shared libraries: libncurses.so.4: cannot open shared object file: No such file or directory ls /usr/lib/libncu* /usr/lib/libncurses.a /usr/lib/libncurses.so.5 /usr/lib/libncurses.so /usr/lib/libncurses.so.5.3
可见虽然没有libncurses.so.4,但有libncurses.so.5,是可以向下兼容的
建一个链接就好了
ln -s /usr/lib/libncurses.so.5.3 /usr/lib/libncurses.so.4
HTML: HyperText Mark Language
XML: eXtended Mark Language
XML, JSON: 半结构化的数据
yum仓库中的元数据文件:
primary.xml.gz
所有RPM包的列表;
依赖关系;
每个RPM安装生成的文件列表;
filelists.xml.gz(全局视角)
当前仓库中所有RPM包的所有文件列表;
other.xml.gz
额外信息,RPM包的修改日志;
repomd.xml
记录的是上面三个文件的时间戳和校验和;
comps*.xml: RPM包分组信息
[root@localhost ~]# cat /etc/yum.conf #(查看yum仓库配置文件) [main] cachedir=/var/cache/yum/$basearch/$releasever keepcache=0 debuglevel=2 logfile=/var/log/yum.log exactarch=1 obsoletes=1 gpgcheck=1 plugins=1 installonly_limit=3 # This is the default, if you make this bigger yum won't see if the metadata # is newer on the remote and so you'll "gain" the bandwidth of not having to # download the new metadata and "pay" for it by yum not having correct # information. # It is esp. important, to have correct metadata, for distributions like # Fedora which don't keep old packages around. If you don't like this checking # interupting your command line usage, it's much better to have something # manually check the metadata once an hour (yum-updatesd will do this). # metadata_expire=90m # PUT YOUR REPOS HERE OR IN separate files named file.repo # (自行定义repo在/etc/yum.repos.d目录) # in /etc/yum.repos.d [root@localhost ~]# [root@localhost ~]# ll /etc/yum.repos.d/ total 12 -rw-r--r--. 1 root root 125 Feb 21 20:39 packagekit-media.repo -rw-r--r--. 1 root root 358 Jun 21 2015 redhat.repo -rw-r--r--. 1 root root 529 Sep 15 2014 rhel-source.repo [root@localhost ~]# #[root@localhost ~]# cat /etc/yum.repos.d/rhel-source.repo #(参考定义repo文件) [rhel-source] name=Red Hat Enterprise Linux $releasever - $basearch - Source baseurl=ftp://ftp.redhat.com/pub/redhat/linux/enterprise/$releasever/en/os/SRPMS/ enabled=0 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release [rhel-source-beta] name=Red Hat Enterprise Linux $releasever Beta - $basearch - Source baseurl=ftp://ftp.redhat.com/pub/redhat/linux/beta/$releasever/en/os/SRPMS/ enabled=0 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-beta,file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release [root@localhost ~]#
如何为yum定义repo文件
[Repo_ID]
name=Description (自定义yum仓库名称)
baseurl= (自定义yum仓库路径)
ftp:// (ftp服务器)
http:// (web服务器)
file:/// (本地文件路径)
enabled={1|0} (确认当前仓库是否使用)
gpgcheck={1|0} (校验是否合法)
gpgkey= (校验算法,如果gpgcheck开启,需要填写;)
[root@localhost yum.repos.d]# yum list | grep ree freetype.x86_64 2.3.11-14.el6_3.1 @anaconda-RedHatEnterpriseLinux-201409260744.x86_64/6.6 gnome-screensaver.x86_64 2.28.3-28.el6 @anaconda-RedHatEnterpriseLinux-201409260744.x86_64/6.6 gstreamer-plugins-bad-free.x86_64 0.10.19-3.el6_5 @anaconda-RedHatEnterpriseLinux-201409260744.x86_64/6.6 nss-softokn-freebl.x86_64 3.14.3-17.el6 @anaconda-RedHatEnterpriseLinux-201409260744.x86_64/6.6 paktype-tehreer-fonts.noarch 2.0-8.el6 @anaconda-RedHatEnterpriseLinux-201409260744.x86_64/6.6 sound-theme-freedesktop.noarch 0.7-3.el6 @anaconda-RedHatEnterpriseLinux-201409260744.x86_64/6.6 thai-scalable-waree-fonts.noarch 0.4.12-2.1.el6 @anaconda-RedHatEnterpriseLinux-201409260744.x86_64/6.6 z-push.noarch 2.2.9-1.el5.centos Free z-push-autodiscover.noarch 2.2.9-1.el5.centos Free z-push-combined.noarch 2.2.9-1.el5.centos Free z-push-imap.noarch 2.2.9-1.el5.centos Free z-push-maildir.noarch 2.2.9-1.el5.centos Free z-push-searchldap.noarch 2.2.9-1.el5.centos Free z-push-vcarddir.noarch 2.2.9-1.el5.centos Free z-push-zarafa.noarch 2.2.9-1.el5.centos Free
repolist: 显示repo列表及其简要信息
all
enabled: 默认
disabled
[root@localhost yum.repos.d]# yum repolist Loaded plugins: product-id, refresh-packagekit, security, subscription-manager This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register. repo id repo name status Free netrpm 8 Nofree netrpm 0 repolist: 8 [root@localhost yum.repos.d]# [root@localhost yum.repos.d]# yum repolist disable Loaded plugins: product-id, refresh-packagekit, security, subscription-manager This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register. repolist: 0 [root@localhost yum.repos.d]#
list: 列表
支持glob
all
available:可用的,仓库中有但尚未安装的
installed: 已经安装的
updates: 可用的升级
provides| whatprovides: 查看指定的文件或特性是由哪个包安装生成的;
[root@localhost yum.repos.d]# yum provides /etc/inittab Loaded plugins: product-id, refresh-packagekit, security, subscription-manager This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register. initscripts-9.03.46-1.el6.x86_64 : The inittab file and the /etc/init.d scripts Repo : installed Matched from: Other : Provides-match: /etc/inittab groupinfo [root@localhost yum.repos.d]# yum grouplist Loaded plugins: product-id, refresh-packagekit, security, subscription-manager This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register. Setting up Group Process Free/group_gz | 1.4 kB 00:00 Nofree/group_gz | 1.4 kB 00:00 Available Groups: Base (RPM Fusion Free) GNOME Desktop Environment (RPM Fusion Free) Hardware Support (RPM Fusion Free) Internet (RPM Fusion Free) KDE (K Desktop Environment) (RPM Fusion Free) Miscellaneous command line tools (RPM Fusion Free) Sound and Video (RPM Fusion Free) Done [root@localhost yum.repos.d]# grouplist groupinstall groupremove groupupdate
如何创建yum仓库:
createrepo /YYY (没有组的定义)
comps-rhel5-vt.xml(组信息)
createrepo -g /xxx/comps-rhel5-vt.xml /YYY
安装第三方yum仓库源EPEL
[root@localhost Downloads]# ll total 24 -rw-r--r--. 1 root root 14540 Mar 1 22:56 epel-release-6-8.noarch.rpm -rw-r--r--. 1 root root 6068 Mar 1 22:18 rpmfusion-free-release-6.noarch.rpm [root@localhost Downloads]# rpm -ivh epel-release-6-8.noarch.rpm (EPEL) warning: epel-release-6-8.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY Preparing... ########################################### [100%] 1:epel-release ########################################### [100%] [root@localhost Downloads]# rpm -ivh rpmfusion-free-release-6.noarch.rpm warning: rpmfusion-free-release-6.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID 849c449f: NOKEY Preparing... ########################################### [100%] 1:rpmfusion-free-release ########################################### [100%] [root@localhost etc]# cd yum.repos.d/ [root@localhost yum.repos.d]# ll total 32 -rw-r--r--. 1 root root 957 Nov 4 2012 epel.repo -rw-r--r--. 1 root root 1056 Nov 4 2012 epel-testing.repo -rw-r--r--. 1 root root 232 Feb 25 22:48 myrepo.repo -rw-r--r--. 1 root root 125 Mar 1 20:45 packagekit-media.repo -rw-r--r--. 1 root root 358 Jun 21 2015 redhat.repo -rw-r--r--. 1 root root 529 Sep 15 2014 rhel-source.repo -rw-r--r--. 1 root root 1002 May 14 2011 rpmfusion-free-updates.repo -rw-r--r--. 1 root root 1062 Jun 19 2012 rpmfusion-free-updates-testing.repo [root@localhost yum.repos.d]# cat epel.repo [epel] name=Extra Packages for Enterprise Linux 6 - $basearch #baseurl=http://download.fedoraproject.org/pub/epel/6/$basearch mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearch failovermethod=priority enabled=1 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6 [epel-debuginfo] name=Extra Packages for Enterprise Linux 6 - $basearch - Debug #baseurl=http://download.fedoraproject.org/pub/epel/6/$basearch/debug mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-debug-6&arch=$basearch failovermethod=priority enabled=0 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6 gpgcheck=1 [epel-source] name=Extra Packages for Enterprise Linux 6 - $basearch - Source #baseurl=http://download.fedoraproject.org/pub/epel/6/SRPMS mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-source-6&arch=$basearch failovermethod=priority enabled=0 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6 gpgcheck=1 [root@localhost yum.repos.d]# ll /etc/pki/rpm-gpg/ total 28 -rw-r--r--. 1 root root 1649 Nov 4 2012 RPM-GPG-KEY-EPEL-6 -rw-r--r--. 1 root root 3375 Sep 15 2014 RPM-GPG-KEY-redhat-beta -rw-r--r--. 1 root root 1990 Sep 15 2014 RPM-GPG-KEY-redhat-legacy-former -rw-r--r--. 1 root root 1164 Sep 15 2014 RPM-GPG-KEY-redhat-legacy-release -rw-r--r--. 1 root root 885 Sep 15 2014 RPM-GPG-KEY-redhat-legacy-rhx -rw-r--r--. 1 root root 3211 Sep 15 2014 RPM-GPG-KEY-redhat-release -rw-r--r--. 1 root root 1710 May 14 2011 RPM-GPG-KEY-rpmfusion-free-el-6 [root@localhost yum.repos.d]# [root@localhost yum.repos.d]# yum repolist Loaded plugins: product-id, refresh-packagekit, security, subscription-manager This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register. Free | 2.8 kB 00:00 Free/primary_db | 4.7 kB 00:00 Nofree | 2.8 kB 00:00 Nofree/primary_db | 1.1 kB 00:00 epel/metalink | 5.2 kB 00:00 epel | 4.3 kB 00:00 epel/primary_db | 5.9 MB 00:01 rpmfusion-free-updates | 3.0 kB 00:00 rpmfusion-free-updates/primary_db | 167 kB 00:00 repo id repo name status Free netrpm 8 Nofree netrpm 0 epel Extra Packages for Enterprise Linux 6 - x86_64 12,251 rpmfusion-free-updates RPM Fusion for EL 6 - Free - Updates 220 repolist: 12,479 [root@localhost yum.repos.d]# yum list | grep gimp gimp-dds-plugin.x86_64 2.2.1-3.el6 epel gimp-gap.x86_64 2.7.0-8.GITe75bd46.el6 epel gimp-layer-via-copy-cut.noarch 1.6-2.el6 epel gimp-paint-studio.noarch 2.0-8.el6 epel gimp-save-for-web.x86_64 0.29.3-1.el6 epel gimp-separate+.x86_64 0.5.8-16.el6 epel gimp-wavelet-denoise-plugin.x86_64 0.3.1-4.el6 epel
主要提供三种格式的mysql包:rpm格式、二进制格式、源码格式:(tar打包,gz压缩)
rpm格式: libjpeg-devel-6b-33.x86_64.rpm #rpm格式很好区分,
二进制包: mysql-3.23.58-pc-linux-i686.tar.gz #二进制格式的包名字很长,有版本号、适应平台、适应的硬件类型等,格式:mysql-<版本>-<OS>-tar.gz
源码包: php-5.2.14.tar.gz #而源码格式仅仅就是一个版本号的tar包。#cj 安装区别:解压、./config、make、make install
source code 是程序员写的码,
binary code 是机器跑的码。
source code 得经过 compile 才能成为 binary code 。
RPM 有分兩種:binary rpm 跟 source rpm 。
前者是編好的 binary ,安裝就可用。
後者是還沒編好的 source ,需 rebuild 之後才能安裝
源代码方式和二进制包是软件包的两种形式。二进制包里面包括了已经经过编译,可以马上运行的程序。你只需要下载和解包(安装)它们以后,就马上可以使用。源代码包里面包括了程序原始的程序代码,需要在你的计算机上进行编译以后才可以产生可以运行程序,所以从源代码安装的时间会比较长。
Linux下有个命令叫file,因为Linux并不是按照后缀名来判断文件类型的。所以一般在不清楚文件到底是什么类型的时候,就用file这个命令去判断。
file php-5.2.14.tar.gz
php-5.2.14.tar.gz: gzip compressed data, was "php-5.2.14.tar", from Unix, last modified: Wed Jul 21 22:32:34 2010, max compression
这个php-5.2.14.tar.gz 明显是个gzip的压缩包,这样的文件一般都是用tar zxvf 命令去解包然后去配置编译安装的,通常情况把这种安装方法叫做源码编译安装。
file libjpeg-devel-6b-33.x86_64.rpm
libjpeg-devel-6b-33.x86_64.rpm: RPM v3 bin i386 libjpeg-devel-6b-33
这个libjpeg-devel-6b-33.x86_64.rpm 文件,就是个标准的redhat系列发行版本所用的RPM格式软件包。一般在RHEL、CentOS、SUSE、OracleLinux下都可以安装类似的RPM包。标准的安装方法是rpm -ivh。
基本上红帽系列Linux发行版本安装软件就这两种方法了。还有经常被提起的yum,其实就是由yum自动判断rpm包的依赖,然后一次性把所有需要安装的N个rpm统一下载安装,其实原理和一个个的安装rpm没有什么本质区别。
一般在官网上下载的源码包都是以:tar.gz tar.bz2结尾的,经过编译的一般是以.rpm来结尾的,linux下的文件扩展名没有实际的意义,这样做只是为了方便你去查看是什么类型的包然后采取什么样的方式去安装和配置,当然有时候并不能从文件的扩展名去查看什么类型的包,因为文件名可以随意的去修改可以使用file这个命令去查看文件包的类型.
源码的安装一般由3个步骤组成:配置(configure)、编译(make)、安装(make install)。
Configure是一个可执行脚本,它有很多选项,在待安装的源码路径下使用命令./configure –help输出详细的选项列表。
其中--prefix选项是配置安装的路径,如果不配置该选项,安装后可执行文件默认放在/usr /local/bin,库文件默认放在/usr/local/lib,配置文件默认放在/usr/local/etc,其它的资源文件放在/usr /local/share,比较凌乱。
如果配置--prefix,如:
./configure --prefix=/usr/local/test
可以把所有资源文件放在/usr/local/test的路径中,不会杂乱。
用了—prefix选项的另一个好处是卸载软件或移植软件。当某个安装的软件不再需要时,只须简单的删除该安装目录,就可以把软件卸载得干干净净;移植软件只需拷贝整个目录到另外一个机器即可(相同的操作系统)。
当然要卸载程序,也可以在原来的make目录下用一次make uninstall,但前提是make文件指定过uninstall。
下载源码包
wget http://mirrors.hust.edu.cn/apache/httpd/httpd-2.2.32.tar.gz
[root@localhost ~]# tar xf httpd-2.2.32.tar.gz [root@localhost ~]# cd httpd-2.2.32 [root@localhost httpd-2.2.32]# ll total 1172 -rw-r--r--. 1 1001 1001 14882 Nov 21 2004 ABOUT_APACHE -rw-r--r--. 1 1001 1001 18613 Jul 6 2012 acinclude.m4 -rw-r--r--. 1 1001 1001 56952 Oct 5 2010 Apache.dsw drwxr-xr-x. 6 1001 1001 4096 Jan 9 09:36 build -rw-r--r--. 1 1001 1001 2644 Aug 23 2007 BuildAll.dsp -rw-r--r--. 1 1001 1001 2692 Jul 29 2009 BuildBin.dsp -rwxr-xr-x. 1 1001 1001 5786 Sep 19 2012 buildconf -rw-r--r--. 1 1001 1001 146529 Jan 9 08:23 CHANGES -rw-r--r--. 1 1001 1001 11701 Feb 27 2012 config.layout -rwxr-xr-x. 1 1001 1001 574593 Jan 9 09:36 configure -rw-r--r--. 1 1001 1001 24720 May 25 2015 configure.in drwxr-xr-x. 9 1001 1001 4096 Jan 9 09:36 docs -rw-r--r--. 1 1001 1001 403 Nov 21 2004 emacs-style -rw-r--r--. 1 1001 1001 1248 May 6 2011 httpd.dep -rw-r--r--. 1 1001 1001 4124 Jun 11 2008 httpd.dsp -rw-r--r--. 1 1001 1001 8994 May 6 2011 httpd.mak -rw-r--r--. 1 1001 1001 12053 Jan 9 09:36 httpd.spec drwxr-xr-x. 2 1001 1001 4096 Jan 9 09:36 include -rw-r--r--. 1 1001 1001 5129 Jan 9 08:33 INSTALL -rw-r--r--. 1 1001 1001 2909 Dec 7 2006 InstallBin.dsp -rw-r--r--. 1 1001 1001 5145 Nov 29 2005 LAYOUT -rw-r--r--. 1 1001 1001 30119 May 6 2011 libhttpd.dep -rw-r--r--. 1 1001 1001 17039 Jan 12 2007 libhttpd.dsp -rw-r--r--. 1 1001 1001 28503 May 6 2011 libhttpd.mak -rw-r--r--. 1 1001 1001 28690 Jan 18 2008 LICENSE -rw-r--r--. 1 1001 1001 8739 Nov 25 2008 Makefile.in -rw-r--r--. 1 1001 1001 34759 Jan 19 2014 Makefile.win drwxr-xr-x. 20 1001 1001 4096 Jan 9 09:36 modules -rw-r--r--. 1 1001 1001 828 Jan 2 08:16 NOTICE -rw-r--r--. 1 1001 1001 12894 Mar 15 2012 NWGNUmakefile drwxr-xr-x. 9 1001 1001 4096 Jan 9 09:36 os -rw-r--r--. 1 1001 1001 5954 Jan 9 2007 README -rw-r--r--. 1 1001 1001 4178 Aug 27 2014 README.platforms -rw-r--r--. 1 1001 1001 2553 Dec 20 2010 README-win32.txt -rw-r--r--. 1 1001 1001 10183 Mar 13 2005 ROADMAP drwxr-xr-x. 3 1001 1001 4096 Jan 9 09:36 server drwxr-xr-x. 5 1001 1001 4096 Jan 9 09:36 srclib drwxr-xr-x. 4 1001 1001 4096 Jan 9 09:36 support drwxr-xr-x. 2 1001 1001 4096 Jan 9 09:36 test -rw-r--r--. 1 1001 1001 8183 Oct 17 2005 VERSIONING [root@localhost httpd-2.2.32]# [root@localhost httpd-2.2.32]# ./configure --help #(查看可以支持的选项) `configure' configures this package to adapt to many kinds of systems. Usage: ./configure [OPTION]... [VAR=VALUE]... To assign environment variables (e.g., CC, CFLAGS...), specify them as VAR=VALUE. See below for descriptions of some of the useful variables. Defaults for the options are specified in brackets. Configuration: -h, --help display this help and exit --help=short display options specific to this package --help=recursive display the short help of all the included packages -V, --version display version information and exit -q, --quiet, --silent do not print `checking ...' messages --cache-file=FILE cache test results in FILE [disabled] -C, --config-cache alias for `--cache-file=config.cache' -n, --no-create do not create output files --srcdir=DIR find the sources in DIR [configure dir or `..'] Installation directories: --prefix=PREFIX install architecture-independent files in PREFIX #(指定安装路径) [/usr/local/apache2] --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX [PREFIX] By default, `make install' will install all the files in `/usr/local/apache2/bin', `/usr/local/apache2/lib' etc. You can specify an installation prefix other than `/usr/local/apache2' using `--prefix', for instance `--prefix=$HOME'. For better control, use the options below. Fine tuning of the installation directories: --bindir=DIR user executables [EPREFIX/bin] --sbindir=DIR system admin executables [EPREFIX/sbin] --libexecdir=DIR program executables [EPREFIX/libexec] --sysconfdir=DIR read-only single-machine data [PREFIX/etc] #(配置路径) --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com] --localstatedir=DIR modifiable single-machine data [PREFIX/var] --libdir=DIR object code libraries [EPREFIX/lib] --includedir=DIR C header files [PREFIX/include] --oldincludedir=DIR C header files for non-gcc [/usr/include] --datarootdir=DIR read-only arch.-independent data root [PREFIX/share] --datadir=DIR read-only architecture-independent data [DATAROOTDIR] --infodir=DIR info documentation [DATAROOTDIR/info] --localedir=DIR locale-dependent data [DATAROOTDIR/locale] --mandir=DIR man documentation [DATAROOTDIR/man] --docdir=DIR documentation root [DATAROOTDIR/doc/PACKAGE] --htmldir=DIR html documentation [DOCDIR] --dvidir=DIR dvi documentation [DOCDIR] --pdfdir=DIR pdf documentation [DOCDIR] --psdir=DIR ps documentation [DOCDIR] System types: --build=BUILD configure for building on BUILD [guessed] --host=HOST cross-compile to build programs to run on HOST [BUILD] --target=TARGET configure for building compilers for TARGET [HOST] [root@localhost httpd-2.2.32]# ./configure --prefix=/usr/local/httpd checking for chosen layout... Apache checking for working mkdir -p... yes checking build system type... x86_64-unknown-linux-gnu checking host system type... x86_64-unknown-linux-gnu checking target system type... x86_64-unknown-linux-gnu [BEGIN] 2017/3/4 22:58:51 [root@localhost httpd-2.2.32]# make Making all in srclib [root@localhost httpd-2.2.32]# make install Making install in srclib [root@localhost bin]# vim /etc/profile #(环境变量路径) [root@localhost ~]# echo $PATH /usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/httpd/bin:/root/bin [root@localhost ~]# 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 1747/sshd tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 1617/cupsd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1867/master tcp 0 0 :::22 :::* LISTEN 1747/sshd tcp 0 0 :::23 :::* LISTEN 1757/xinetd tcp 0 0 ::1:631 :::* LISTEN 1617/cupsd tcp 0 0 ::1:25 :::* LISTEN 1867/master tcp 0 0 :::80 :::* LISTEN 40411/httpd #(80端口,可以页面直接访问)
RPM安装:
二进制格式:
源程序-->编译-->二进制格式
有些特性是编译选定的,如果编译未选定此特性,将无法使用;
rpm包的版本会落后于源码包,甚至落后很多;bind-9.8.7, bind-9.7.2
定制:手动编译安装
编译环境,开发环境
开发库,开发工具
Linux: C,
GNU: C
C,C++:
gcc: GNU C Complier, C
g++:
make: 项目管理工具,
makefile: 定义了make(gcc,g++)按何种次序去编译这些源程序文件中的源程序
automake, --> makefile.in --> makefile
autoconf, --> configure
100个可选择特性,
make install
编译安装的三步骤:
前提:准备开发环境(编译环境)
安装"Development Tools"和"Development Libraries"
# tar
# cd
# ./configure
--help
--prefix=/path/to/somewhere
--sysconfdir=/PATH/TO/CONFFILE_PATH
功能:1、让用户选定编译特性;2、检查编译环境;
# make
# make install
# tar xf tengine-1.4.2.tar.gz
# cd tegnine-1.4.2
# ./configure --prefix=/usr/local/tengine --conf-path=/etc/tengine/tengine.conf
# make
# make install
# /usr/local/tengine/sbin/nginx
1、修改PATH环境变量,以能够识别此程序的二进制文件路径;
修改/etc/profile文件
在/etc/profile.d/目录建立一个以.sh为名称后缀的文件,在里面定义export PATH=$PATH:/path/to/somewhere
2、默认情况下,系统搜索库文件的路径/lib, /usr/lib; 要增添额外搜寻路径:
在/etc/ld.so.conf.d/中创建以.conf为后缀名的文件,而后把要增添的路径直接写至此文件中;
# ldconfig 通知系统重新搜寻库文件
-v: 显示重新搜寻库的过程
3、头文件:输出给系统
默认:/usr/include
增添头文件搜寻路径,使用链接进行:
/usr/local/tengine/include/ /usr/include/
两种方式:
ln -s /usr/local/tengine/include/* /usr/include/ 或
ln -s /usr/local/tengine/include /usr/include/tengine
4、man文件路径:安装在--prefix指定的目录下的man目录;/usr/share/man
1、man -M /PATH/TO/MAN_DIR COMMAND
2、在/etc/man.config中添加一条MANPATH
netstat命令:
-r: 显示路由表
-n: 以数字方式显示
-t: 建立的tcp连接
-u: 显示udp连接
-l: 显示监听状态的连接
-p: 显示监听指定的套接字的进程的进程号及进程名
[root@localhost htdocs]# netstat -tul Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 *:ssh *:* LISTEN (允许任意外来主机) tcp 0 0 localhost:ipp *:* LISTEN tcp 0 0 localhost:smtp *:* LISTEN tcp 0 0 *:ssh *:* LISTEN tcp 0 0 *:telnet *:* LISTEN tcp 0 0 localhost:ipp *:* LISTEN tcp 0 0 localhost:smtp *:* LISTEN tcp 0 0 *:http *:* LISTEN udp 0 0 *:bootpc *:* udp 0 0 *:ipp *:* [root@localhost htdocs]# [root@localhost htdocs]# netstat -tulnp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1747/sshd tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 1617/cupsd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1867/master tcp 0 0 :::22 :::* LISTEN 1747/sshd tcp 0 0 :::23 :::* LISTEN 1757/xinetd tcp 0 0 ::1:631 :::* LISTEN 1617/cupsd tcp 0 0 ::1:25 :::* LISTEN 1867/master tcp 0 0 :::80 :::* LISTEN 40411/httpd udp 0 0 0.0.0.0:68 0.0.0.0:* 1612/dhclient udp 0 0 0.0.0.0:631 0.0.0.0:* 1617/cupsd [root@localhost htdocs]#
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。