• 软件安装和配置
    • 使用包管理工具
    • 下载解压配置环境变量
    • 源代码构建安装

    软件安装和配置

    使用包管理工具

    1. yum - Yellowdog Updater Modified。
      • yum search:搜索软件包,例如yum search nginx
      • yum list installed:列出已经安装的软件包,例如yum list installed | grep zlib
      • yum install:安装软件包,例如yum install nginx
      • yum remove:删除软件包,例如yum remove nginx
      • yum update:更新软件包,例如yum update可以更新所有软件包,而yum update tar只会更新tar。
      • yum check-update:检查有哪些可以更新的软件包。
      • yum info:显示软件包的相关信息,例如yum info nginx
    2. rpm - Redhat Package Manager。
      • 安装软件包:rpm -ivh <packagename>.rpm
      • 移除软件包:rpm -e <packagename>
      • 查询软件包:rpm -qa,例如可以用rpm -qa | grep mysql来检查是否安装了MySQL相关的软件包。

    下面以Nginx为例,演示如何使用yum安装软件。

    1. [root ~]# yum -y install nginx
    2. ...
    3. Installed:
    4. nginx.x86_64 1:1.12.2-2.el7
    5. Dependency Installed:
    6. nginx-all-modules.noarch 1:1.12.2-2.el7
    7. nginx-mod-http-geoip.x86_64 1:1.12.2-2.el7
    8. nginx-mod-http-image-filter.x86_64 1:1.12.2-2.el7
    9. nginx-mod-http-perl.x86_64 1:1.12.2-2.el7
    10. nginx-mod-http-xslt-filter.x86_64 1:1.12.2-2.el7
    11. nginx-mod-mail.x86_64 1:1.12.2-2.el7
    12. nginx-mod-stream.x86_64 1:1.12.2-2.el7
    13. Complete!
    14. [root ~]# yum info nginx
    15. Loaded plugins: fastestmirror
    16. Loading mirror speeds from cached hostfile
    17. Installed Packages
    18. Name : nginx
    19. Arch : x86_64
    20. Epoch : 1
    21. Version : 1.12.2
    22. Release : 2.el7
    23. Size : 1.5 M
    24. Repo : installed
    25. From repo : epel
    26. Summary : A high performance web server and reverse proxy server
    27. URL : http://nginx.org/
    28. License : BSD
    29. Description : Nginx is a web server and a reverse proxy server for HTTP, SMTP, POP3 and
    30. : IMAP protocols, with a strong focus on high concurrency, performance and low
    31. : memory usage.
    32. [root ~]# nginx -v
    33. nginx version: nginx/1.12.2

    移除Nginx。

    1. [root ~]# yum -y remove nginx

    下面以MySQL为例,演示如何使用rpm安装软件。要安装MySQL需要先到MySQL官方网站下载对应的RPM文件,当然要选择和你使用的Linux系统对应的版本。MySQL现在是Oracle公司旗下的产品,在MySQL被收购后,MySQL的作者重新制作了一个MySQL的分支MariaDB,可以通过yum进行安装。

    1. [root mysql]# ls
    2. mysql-community-client-5.7.22-1.el7.x86_64.rpm
    3. mysql-community-common-5.7.22-1.el7.x86_64.rpm
    4. mysql-community-libs-5.7.22-1.el7.x86_64.rpm
    5. mysql-community-server-5.7.22-1.el7.x86_64.rpm
    6. [root mysql]# yum -y remove mariadb-libs
    7. [root mysql]# yum -y install libaio
    8. [root mysql]#rpm -ivh mysql-community-common-5.7.26-1.el7.x86_64.rpm
    9. ...
    10. [root mysql]#rpm -ivh mysql-community-libs-5.7.26-1.el7.x86_64.rpm
    11. ...
    12. [root mysql]#rpm -ivh mysql-community-client-5.7.26-1.el7.x86_64.rpm
    13. ...
    14. [root mysql]#rpm -ivh mysql-community-server-5.7.26-1.el7.x86_64.rpm
    15. ...

    说明:由于MySQL和MariaDB的底层依赖库是有冲突的,所以上面我们首先用yum移除了名为mariadb-libs的依赖库并安装了名为libaio支持异步I/O操作的依赖库。关于MySQL和MariaDB之间的关系,可以阅读维基百科上关于MariaDB的介绍。

    移除安装的MySQL。

    1. [root ~]# rpm -qa | grep mysql | xargs rpm -e

    下载解压配置环境变量

    下面以安装MongoDB为例,演示这类软件应该如何安装。

    1. [root ~]# wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-3.6.5.tgz
    2. --2018-06-21 18:32:53-- https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-3.6.5.tgz
    3. Resolving fastdl.mongodb.org (fastdl.mongodb.org)... 52.85.83.16, 52.85.83.228, 52.85.83.186, ...
    4. Connecting to fastdl.mongodb.org (fastdl.mongodb.org)|52.85.83.16|:443... connected.
    5. HTTP request sent, awaiting response... 200 OK
    6. Length: 100564462 (96M) [application/x-gzip]
    7. Saving to: mongodb-linux-x86_64-rhel70-3.6.5.tgz
    8. 100%[==================================================>] 100,564,462 630KB/s in 2m 9s
    9. 2018-06-21 18:35:04 (760 KB/s) - mongodb-linux-x86_64-rhel70-3.6.5.tgz saved [100564462/100564462]
    10. [root ~]# gunzip mongodb-linux-x86_64-rhel70-3.6.5.tgz
    11. [root ~]# tar -xvf mongodb-linux-x86_64-rhel70-3.6.5.tar
    12. mongodb-linux-x86_64-rhel70-3.6.5/README
    13. mongodb-linux-x86_64-rhel70-3.6.5/THIRD-PARTY-NOTICES
    14. mongodb-linux-x86_64-rhel70-3.6.5/MPL-2
    15. mongodb-linux-x86_64-rhel70-3.6.5/GNU-AGPL-3.0
    16. mongodb-linux-x86_64-rhel70-3.6.5/bin/mongodump
    17. mongodb-linux-x86_64-rhel70-3.6.5/bin/mongorestore
    18. mongodb-linux-x86_64-rhel70-3.6.5/bin/mongoexport
    19. mongodb-linux-x86_64-rhel70-3.6.5/bin/mongoimport
    20. mongodb-linux-x86_64-rhel70-3.6.5/bin/mongostat
    21. mongodb-linux-x86_64-rhel70-3.6.5/bin/mongotop
    22. mongodb-linux-x86_64-rhel70-3.6.5/bin/bsondump
    23. mongodb-linux-x86_64-rhel70-3.6.5/bin/mongofiles
    24. mongodb-linux-x86_64-rhel70-3.6.5/bin/mongoreplay
    25. mongodb-linux-x86_64-rhel70-3.6.5/bin/mongoperf
    26. mongodb-linux-x86_64-rhel70-3.6.5/bin/mongod
    27. mongodb-linux-x86_64-rhel70-3.6.5/bin/mongos
    28. mongodb-linux-x86_64-rhel70-3.6.5/bin/mongo
    29. mongodb-linux-x86_64-rhel70-3.6.5/bin/install_compass
    30. [root ~]# vim .bash_profile
    31. ...
    32. PATH=$PATH:$HOME/bin:$HOME/mongodb-linux-x86_64-rhel70-3.6.5/bin
    33. export PATH
    34. ...
    35. [root ~]# source .bash_profile
    36. [root ~]# mongod --version
    37. db version v3.6.5
    38. git version: a20ecd3e3a174162052ff99913bc2ca9a839d618
    39. OpenSSL version: OpenSSL 1.0.1e-fips 11 Feb 2013
    40. allocator: tcmalloc
    41. modules: none
    42. build environment:
    43. distmod: rhel70
    44. distarch: x86_64
    45. target_arch: x86_64
    46. [root ~]# mongo --version
    47. MongoDB shell version v3.6.5
    48. git version: a20ecd3e3a174162052ff99913bc2ca9a839d618
    49. OpenSSL version: OpenSSL 1.0.1e-fips 11 Feb 2013
    50. allocator: tcmalloc
    51. modules: none
    52. build environment:
    53. distmod: rhel70
    54. distarch: x86_64
    55. target_arch: x86_64

    说明:当然也可以通过yum来安装MongoDB,具体可以参照官方网站上给出的说明。

    源代码构建安装

    1. 安装Python 3.6。

      1. [root ~]# yum install gcc
      2. [root ~]# wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz
      3. [root ~]# gunzip Python-3.6.5.tgz
      4. [root ~]# tar -xvf Python-3.6.5.tar
      5. [root ~]# cd Python-3.6.5
      6. [root ~]# ./configure --prefix=/usr/local/python36 --enable-optimizations
      7. [root ~]# yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
      8. [root ~]# make && make install
      9. ...
      10. [root ~]# ln -s /usr/local/python36/bin/python3.6 /usr/bin/python3
      11. [root ~]# python3 --version
      12. Python 3.6.5
      13. [root ~]# python3 -m pip install -U pip
      14. [root ~]# pip3 --version

      说明:上面在安装好Python之后还需要注册PATH环境变量,将Python安装路径下bin文件夹的绝对路径注册到PATH环境变量中。注册环境变量可以修改用户主目录下的.bash_profile或者/etc目录下的profile文件,二者的区别在于前者相当于是用户环境变量,而后者相当于是系统环境变量。

    2. 安装Redis-3.2.12。

      1. [root ~]# wget http://download.redis.io/releases/redis-3.2.12.tar.gz
      2. [root ~]# gunzip redis-3.2.12.tar.gz
      3. [root ~]# tar -xvf redis-3.2.12.tar
      4. [root ~]# cd redis-3.2.12
      5. [root ~]# make && make install
      6. [root ~]# redis-server --version
      7. Redis server v=3.2.12 sha=00000000:0 malloc=jemalloc-4.0.3 bits=64 build=5bc5cd3c03d6ceb6
      8. [root ~]# redis-cli --version
      9. redis-cli 3.2.12