=Start=
缘由:
不同的Linux发行版有不同的「包管理工具」,所以有时同一个软件对应的安装包名称和安装命令也都不一样(甚至同一发行版的不同版本之间也会有所不同),如果需要写类似于 LNMP 等兼容各Linux系统的一键安装工具时,是需要提前判断Linux系统的具体发行版信息的,然后根据对应的版本信息进行操作。这里我根据以往的一些经验记录一下常见Linux系统发行版的判断方法,作为备忘和参考。
正文:
准确判断Linux系统的发行版需要对LFS和各Linux发行版足够熟悉才行,下面是我碰到的一些常用的Linux发行版及对应包管理工具:
- Fedora / RedHat / CentOS
$ yum/rpm - Gentoo
$ emerge - Debian / Ubuntu
$ apt-get/dpkg - Arch
$ pacman
根据自己之前的一些经验,一般情况下可以根据如下3个文件来判断Linux系统的具体发行版本信息:
- /etc/*release
- /etc/*version
- /etc/*issue*
一个简单的Linux系统发行版本检测脚本:
function check_os_type() { local line line=`head -n 1 /etc/issue` if echo $line|grep "[Cc]ent[Oo][Ss]" >/dev/null; then br_os_type=1 elif echo $line|grep "[Rr]ed.Hat.Enterprise" >/dev/null; then br_os_type=2 elif echo $line|grep "[Uu]buntu" >/dev/null; then br_os_type=3 elif echo $line|grep "[Dd]ebian" >/dev/null; then br_os_type=4 elif echo $line|grep "[Ff]edora" >/dev/null; then br_os_type=5 else echo -e "unknown os type - $line is not supported." exit 0 fi echo -e "target os type - $line" echo $br_os_type }
一个较为通用的Linux系统版本信息检测脚本:
#!/bin/bash # Detects which OS and if it is Linux then it will detect which Linux Distribution. # https://www.novell.com/coolsolutions/feature/11251.html OS=`uname -s` REV=`uname -r` MACH=`uname -m` if [ "${OS}" = "SunOS" ] ; then OS=Solaris ARCH=`uname -p` OSSTR="${OS} ${REV}(${ARCH} `uname -v`)" elif [ "${OS}" = "AIX" ] ; then OSSTR="${OS} `oslevel` (`oslevel -r`)" elif [ "${OS}" = "Linux" ] ; then KERNEL=`uname -r` if [ -f /etc/redhat-release ] ; then DIST='RedHat' PSUEDONAME=`cat /etc/redhat-release | sed s/.*\(// | sed s/\)//` REV=`cat /etc/redhat-release | sed s/.*release\ // | sed s/\ .*//` elif [ -f /etc/SUSE-release ] ; then DIST=`cat /etc/SUSE-release | tr "\n" ' '| sed s/VERSION.*//` REV=`cat /etc/SUSE-release | tr "\n" ' ' | sed s/.*=\ //` elif [ -f /etc/mandrake-release ] ; then DIST='Mandrake' PSUEDONAME=`cat /etc/mandrake-release | sed s/.*\(// | sed s/\)//` REV=`cat /etc/mandrake-release | sed s/.*release\ // | sed s/\ .*//` elif [ -f /etc/debian_version ] ; then DIST="Debian `cat /etc/debian_version`" REV="" fi if [ -f /etc/UnitedLinux-release ] ; then DIST="${DIST}[`cat /etc/UnitedLinux-release | tr "\n" ' ' | sed s/VERSION.*//`]" fi OSSTR="${OS} ${DIST} ${REV}(${PSUEDONAME} ${KERNEL} ${MACH})" fi echo ${OSSTR}
参考链接:
- http://unix.stackexchange.com/questions/35183/how-do-i-identify-which-linux-distro-is-running
- http://unix.stackexchange.com/questions/6345/how-can-i-get-distribution-name-and-version-number-in-a-simple-shell-script
- http://www.unix.com/shell-programming-and-scripting/27932-how-know-linux-distribution-i-am-using.html
- https://www.novell.com/coolsolutions/feature/11251.html
- http://superuser.com/questions/80251/how-to-know-which-linux-distribution-im-using
- http://serverfault.com/questions/3331/how-do-i-find-out-what-version-of-linux-is-running/3334#3334
- http://superuser.com/questions/618660/how-can-i-determine-the-distro-of-linux-that-is-running-on-a-remote-server/618661
- http://www.cyberciti.biz/faq/command-to-show-linux-version/
- http://askubuntu.com/questions/459402/how-to-know-if-the-running-platform-is-ubuntu-or-centos-with-help-of-a-bash-scri
- http://unix.stackexchange.com/questions/92199/how-can-i-reliably-get-the-operating-systems-name/92218#92218
=END=
《 “如何判断Linux系统的具体发行版本信息” 》 有 3 条评论
一些神代码注释
https://blog.phpgao.com/no_comments.html #挺好玩的,以后加着试试
查看Hadoop组件版本
http://oitebody.iteye.com/blog/2320187
`
# 查看Hadoop版本
[root@datacube201 ~]# hadoop version
# 查看HBAse版本
[root@datacube201 ~]# hbase version
# 查看Hive版本
[root@datacube201 ~]# hive –version
`
Hadoop版本选型
https://staroon.pro/2017/11/05/HadoopSelect/
软件版本 (Software versioning)
https://en.wikipedia.org/wiki/Software_versioning
2.1.1 Which MySQL Version and Distribution to Install
https://dev.mysql.com/doc/refman/8.0/en/which-version.html
MongoDB Versioning
https://docs.mongodb.com/manual/reference/versioning/#release-version-numbers