Linux CentOS 6.5 yum安装MongoDB的操作

安装mongodb-3.6.4版本

执行命令

wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel62-3.6.4.tgz

如果出现错误,则在root下更新wget,执行

yum upgrade wget

再去执行以上wget命令即可。

下载完成后,进行解压

tar -zxvf mongodb-linux-x86_64-rhel62-3.6.4.tgz

如果嫌解压后文件名称过长,可以进行重命名

mv mongodb-linux-x86_64-rhel62-3.6.4 mongodb

进入到mongodb目录下

cd mongodb

创建db和日志目录

mkdir data
mkdir -p data/db
mkdir -p data/logs

在logs目录下创建mongodb.log文件

touch mongodb.log

在data目录下创建mongodb.conf文件

cd mongodb/data
vi mongodb.conf
port=8087

dbpath=/opt/mongodb/mongodb/data/db

logpath=/opt/mongodb/mongodb/data/logs/mongodb.log

fork=true

logappend=true

启动

在mongodb目录下执行

./bin/mongod --config /opt/mongodb/mongodb/data/mongodb.conf

可以看到以下内容:

未分类

进入到mongodb进行操作

./bin/mongo

无法连接 127.0.01:27017,经过分析,是防火墙端口没有开放。

未分类

可以看到有很多警告信息,没有关系,因为接下来要创建用户,mongodb默认情况下没有用户,需要创建,授权。

> use admin
switched to db admin
> db.system.users.find();

没有任何输出,这时则创建用户,我创建的是一个超级用户

db.createUser(
... {
... user:"root",
... pwd:"554466",
... roles:[{role:"root",db:"admin"}]
... }
... )
Successfully added user: {
    "user" : "root",
    "roles" : [
        {
            "role" : "root",
            "db" : "admin"
        }
    ]

}

然后关闭mongodb,执行命令db.shutdownServer();

exit;退出mongodb客户端,重新编辑配置文件vi data/mongodb.conf

加入一行auth=true,保存退出,再次启动mongodb,此时就不会出现警告信息,进入客户端,进行用户验证。

未分类

CentOS 更新 yum 源

设置yum源

将yum源设置为国内yum源,可以提升软件包安装和更新的速度,同时避免一些常见软件版本无法找到。 国内源:可以使用wget获取或者直接下载

1.网易:

2.中科大的yum源:

3.sohu的yum源:

安装步骤

1.首先备份CentOS-Base.repo

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

2.下载对应版本的CentOS-Base.repo, 放入/etc/yum.repos.d/ (可以直接cd /etc/yum.repos.d/ 然后使用wget下载)

3.运行以下命令生成缓存

yum clean all
yum makecache

CentOS 7.x yum 方式安装 MariaDB(MySQL)

MariaDB 是 MySQL 的一个分支,采用 GPL 授权许可证,目前主要由开源社区在维护。MariaDB的目的是完全兼容MySQL,包括 API 和命令行,是之能轻松成为 MySQL 的替代品。

通过 yum 方式安装 MariaDB 非常简单,执行如下命令即可。

# yum install mariadb-server mariadb
# rpm -q mariadb mariadb-server
mariadb-5.5.56-2.el7.x86_64
mariadb-server-5.5.56-2.el7.x86_64

安装完成后,将 MariaDB 设置为开机启动,操作如下:

# systemctl enable mariadb

输出类似如下:

Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.

接着,启动 MariaDB,执行如下命令:

# systemctl start mariadb

最后,登录 MariaDB,执行如下命令:

# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or g.
Your MariaDB connection id is 2
Server version: 5.5.56-MariaDB MariaDB Server

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

MariaDB [(none)]>

从这里可以看到,在 MariaDB 中,默认的登录方式跟 MySQL 数据库一样,root 密码默认为空。
对 MariaDB 服务进行管理,可以通过 systemctl 命令实现。例如:

关闭 MariaDB 

# systemctl stop mariadb

重启 MariaDB 

# systemctl restart  mariadb

检查 MariaDB 服务运行状态

# systemctl status  mariadb

MariaDB 通过内置的安全脚本可实现对数据库的安全保护,执行“/usr/bin/mysql_secure_installation”命令,加固 MariaDB 数据库,操作过程如下:

# mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):  // 这里输入目前 MariaDB 数据库的 root 密码,默认为空
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] y      // 这里询问是否是之 root 密码,输入 y  给 root 用户设置一个新密码
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y  //这里询问是否删除 anonymous 用户,输入 "Y" 
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y   // 这里询问是否关闭 root 用户远程登录权限 输入 "Y"
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y  // 这里询问是否删除测试数据库及其权限 输入 "Y"
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y   // 这里询问是否重新载入授权表 输入 "Y"
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

至此,MariaDB 数据库安转完成了。

CentOS 6.9/7通过yum安装指定版本的Nginx

说明:通过yum好处其实很多,环境变量不用配置,配置文件放在大家都熟悉的地方,通过rpm -ql nginx可以知道全部文件的地方等等。

Nginx(1.12.2)

一、安装和配置

1、安装

# rpm -ivh http://nginx.org/packages/centos/6/x86_64/RPMS/nginx-1.12.2-1.el6.ngx.x86_64.rpm

备注:其实根据上面这个网址(http://nginx.org/packages/)可以进去其nginx官方的的包管理列表,选择合适的系统和包

2、启动

# nginx
// 验证是否启动成功
# curl http://127.0.0.1:80
// 正常会返回html代码

3、设置开机启动服务

# chkconfig nginx on

4、服务常用操作

// 服务状态
# service nginx status
// 服务启动
# service nginx start
// 服务停止
# service nginx stop
// 服务重启
# service nginx restart

CentOS 7:

1、安装

# rpm -ivh http://nginx.org/packages/centos/7/x86_64/RPMS/nginx-1.12.2-1.el7_4.ngx.x86_64.rpm

2、启动

# systemctl start nginx
// 验证是否启动成功
# curl http://127.0.0.1:80
// 正常会返回html代码

3、设置开机启动服务

# systemctl enable nginx

4、服务常用操作

// 服务状态
# systemctl status nginx
// 服务启动
# systemctl start nginx
// 服务停止
# systemctl stop nginx
// 服务重启
# systemctl restart nginx

centos下使用yum 安装percona xtrabackup

配置percona的yum仓库

一、先安装依赖

yum install perl-DBI

yum install perl-DBD-MySQL

yum install perl-Time-HiRes

yum install perl-IO-Socket-SSL

二、配置yum源

方法1、自动安装percona的yum仓库(以下分别为x86_64和i386平台)

#rpm -ivh http://www.percona.com/downloads/percona-release/percona-release-0.0-1.x86_64.rpm
#rpm -ivh http://www.percona.com/redir/downloads/percona-release/percona-release-0.0-1.i386.rpm

方法2、手动yum仓库

创建文件/etc/yum.repos.d/Percona.repo内容如下:

[percona]
name = CentOS $releasever - Percona
baseurl=http://repo.percona.com/centos/$releasever/os/$basearch/
enabled = 1
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-percona
gpgcheck = 1

获取和保存key

#wget http://www.percona.com/redir/downloads/percona-release/RPM-GPG-KEY-percona

#cp RPM-GPG-KEY-percona /etc/pki/rpm-gpg/RPM-GPG-KEY-percona

安装 percona xtrabackup
下面我们就可以安装percona一系列工具了:

安装xtrabackup    
#yum -y install percona-xtrabackup    
安装toolkit
#yum -y install percona-toolkit

将Centos的yum源更换为国内的阿里云源

由于centos默认的Yum源速度太慢,在使用的时候不方便,于是将yum源改成阿里的源。

备份

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

下载新的CentOS-Base.repo 到/etc/yum.repos.d/

  • CentOS 5
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-5.repo

或者

curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-5.repo
  • CentOS 6
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo

或者

curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
  • CentOS 7
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

或者

curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

生成yum缓存

yum clean all
yum makecache

添加其他源

添加EPEL源

  • Centos6
wget -O /etc/yum.repos.d/epel-6.repo http://mirrors.aliyun.com/repo/epel-6.repo
  • Centos7
wget -O /etc/yum.repos.d/epel-7.repo http://mirrors.aliyun.com/repo/epel-7.repo `
  • 清理缓存并生成新的缓存
yum clean all  
yum makecache 

CentOS 7简单的利用yum源安装Nginx

未分类

项目需求要使用80端口部署静态html5的官网,为了稳定高效和后续的扩充,故使用轻巧又强大的Nginx来作80端口的服务器。
  
下面就简单介绍一下简单的利用yum源安装Nginx,并申请阿里云免费提供的的SymantecSSL证书,来开启SSL加密的443端口https。

安装环境:CentOS7 64位 Minimal版(VMware)

配置网卡

使用桥接,开启网卡并设置:静态ip、网关、子网掩码、DNS

# 编辑网卡配置
vi /etc/sysconfig/network-scripts/ifcfg-eno16777736

未分类

TYPE=Ethernet
BOOTPROTO=static
IPADDR=192.168.0.200
GATEWAY=192.168.0.1
NETMASK=255.255.255.0
DNS1=192.168.0.1
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
NAME=eno16777736
UUID=11b992a7-1630-4a26-bd62-8ce65e3e5c78
DEVICE=eno16777736
ONBOOT=yes
# 重启网络服务
systemctl restart network
# 查看ip
ip addr

配置防火墙

http协议默认端口为80端口,SSL加密的https协议的默认端口为443端口。
远程访问,需要打开防火墙。CentOS 7 中默认防火墙是firewalld,默认为关闭状态。

# 启动Firewall
systemctl start firewalld
# 设置开机自启动
systemctl enable firewalld
# 开放http80端口
firewall-cmd --permanent --add-port=80/tcp
# 开放https443端口
firewall-cmd --permanent --add-port=443/tcp
# 重载防火墙配置
firewall-cmd --reload

# 查看所有已开放端口
firewall-cmd --list-ports

# 若无firewall-cmd命令则先安装firewalld
yum install firewalld -y

先安装nginx的yum源
http://nginx.org/en/linux_packages.html#stable 找到链接,安装:

rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

未分类

查看:

yum info nginx

未分类

安装:

yum install nginx

未分类

安装完成后nginx就已经启动了,可以查看进程:

ps -ef | grep nginx

未分类

如果一切进展顺利的话,现在你可以通过你的域名或IP来访问你的Web页面来预览一下Nginx的默认页面

未分类

如果看到这个页面,那么说明你的CentOS 7 中 web服务器已经正确安装。

开机自启:

systemctl enable nginx

Nginx配置信息

# 网站文件存放默认目录
/usr/share/nginx/html
# 网站默认站点配置
/etc/nginx/conf.d/default.conf
# 自定义Nginx站点配置文件存放目录
/etc/nginx/conf.d/
# Nginx全局配置
/etc/nginx/nginx.conf

启动nginx:

systemctl start nginx

Nginx手动启动

nginx -c nginx.conf

在这里你可以改变设置用户运行Nginx守护程序进程一样,和工作进程的数量得到了Nginx正在运行,等等。

据运维同学反馈,通过yum源安装之后,在安装插件时会有所限制。但针对目前学习,已经足够了。

通过apache创建一个yum仓库

通过Apache创建一个自己的yum仓库,当然你也可以使用ftp,本文只是一个简单的演示。

当前演示环境,Centos7.4,关闭selinux,关闭防火墙,当前ip192.168.1.108

1、挂载光盘镜像

mount /dev/cdrom /mnt

2、安装Apache并启动服务

yum install httpd -y
systemctl start httpd
systemctl enable httpd

此时打开http://192.168.1.108即可看到Testing 123..

3、拷贝光盘镜像文件

这里你可以拷贝光盘镜像文件到/var/www/html目录,我这里直接使用了软连接

ln -sv /mnt/ /var/www/html/

此时打开http://192.168.1.108/mnt即可看到如下页面

未分类

4、配置yum仓库

vi /etc/yum.repos.d/isoyum.repo
[isoyum]
name=isoyum
baseurl=http://192.168.1.108/mnt/
gpqcheck=1
gpqkey=http://192.168.1.108/mnt/RPM-GPG-KEY-CentOS-7

配置完成后执行,即可看到新添加的yum仓库已经生效了

yum clean all && yum makecache

未分类

在 RHEL/CentOS 系统上使用 YUM history 命令回滚升级操作

为服务器打补丁是 Linux 系统管理员的一项重要任务,为的是让系统更加稳定,性能更加优化。厂商经常会发布一些安全/高危的补丁包,相关软件需要升级以防范潜在的安全风险。

Yum (Yellowdog Update Modified) 是 CentOS 和 RedHat 系统上用的 RPM 包管理工具,yum history 命令允许系统管理员将系统回滚到上一个状态,但由于某些限制,回滚不是在所有情况下都能成功,有时 yum 命令可能什么都不做,有时可能会删掉一些其他的包。

我建议你在升级之前还是要做一个完整的系统备份,而 yum history 并不能用来替代系统备份的。系统备份能让你将系统还原到任意时候的节点状态。

某些情况下,安装的应用程序在升级了补丁之后不能正常工作或者出现一些错误(可能是由于库不兼容或者软件包升级导致的),那该怎么办呢?

与应用开发团队沟通,并找出导致库和软件包的问题所在,然后使用 yum history 命令进行回滚。

注意:

  • 它不支持回滚 selinux,selinux-policy-*,kernel,glibc (以及依赖 glibc 的包,比如 gcc)。
  • 不建议将系统降级到更低的版本(比如 CentOS 6.9 降到 CentOS 6.8),这会导致系统处于不稳定的状态
    让我们先来看看系统上有哪些包可以升级,然后挑选出一些包来做实验。
#yum update
Loaded plugins: fastestmirror, security
Setting up UpdateProcess
Loading mirror speeds from cached hostfile
epel/metalink |12 kB 00:00
* epel: mirror.csclub.uwaterloo.ca
base |3.7 kB 00:00
dockerrepo |2.9 kB 00:00
draios |2.9 kB 00:00
draios/primary_db |13 kB 00:00
epel |4.3 kB 00:00
epel/primary_db |5.9 MB 00:00
extras |3.4 kB 00:00
updates |3.4 kB 00:00
updates/primary_db |2.5 MB 00:00
ResolvingDependencies
-->Running transaction check
--->Packagegit.x86_64 0:1.7.1-8.el6 will be updated
--->Packagegit.x86_64 0:1.7.1-9.el6_9 will be an update
--->Package httpd.x86_64 0:2.2.15-60.el6.centos.4 will be updated
--->Package httpd.x86_64 0:2.2.15-60.el6.centos.5 will be an update
--->Package httpd-tools.x86_64 0:2.2.15-60.el6.centos.4 will be updated
--->Package httpd-tools.x86_64 0:2.2.15-60.el6.centos.5 will be an update
--->Package perl-Git.noarch 0:1.7.1-8.el6 will be updated
--->Package perl-Git.noarch 0:1.7.1-9.el6_9 will be an update
-->FinishedDependencyResolution
DependenciesResolved
=================================================================================================
PackageArchVersionRepositorySize
=================================================================================================
Updating:
git x86_64 1.7.1-9.el6_9 updates 4.6 M
httpd x86_64 2.2.15-60.el6.centos.5 updates 836 k
httpd-tools x86_64 2.2.15-60.el6.centos.5 updates 80 k
perl-Git noarch 1.7.1-9.el6_9 updates 29 k
TransactionSummary
=================================================================================================
Upgrade4Package(s)
Total download size:5.5 M
Isthis ok [y/N]: n

你会发现 git 包可以被升级,那我们就用它来实验吧。运行下面命令获得软件包的版本信息(当前安装的版本和可以升级的版本)。

#yumlistgit
Loaded plugins: fastestmirror, security
Setting up UpdateProcess
Loading mirror speeds from cached hostfile
* epel: mirror.csclub.uwaterloo.ca
InstalledPackages
git.x86_64 1.7.1-8.el6@base
AvailablePackages
git.x86_64 1.7.1-9.el6_9 updates

运行下面命令来将 git 从 1.7.1-8 升级到 1.7.1-9。

#yum update git
Loaded plugins: fastestmirror, presto
Setting up UpdateProcess
Loading mirror speeds from cached hostfile
* base: repos.lax.quadranet.com
* epel: Fedora.mirrors.pair.com
* extras: mirrors.seas.harvard.edu
* updates: mirror.sesp.northwestern.edu
ResolvingDependencies
-->Running transaction check
--->Packagegit.x86_64 0:1.7.1-8.el6 will be updated
-->ProcessingDependency:git=1.7.1-8.el6forpackage: perl-Git-1.7.1-8.el6.noarch
--->Packagegit.x86_64 0:1.7.1-9.el6_9 will be an update
-->Running transaction check
--->Package perl-Git.noarch 0:1.7.1-8.el6 will be updated
--->Package perl-Git.noarch 0:1.7.1-9.el6_9 will be an update
-->FinishedDependencyResolution
DependenciesResolved
=================================================================================================
PackageArchVersionRepositorySize
=================================================================================================
Updating:
git x86_64 1.7.1-9.el6_9 updates 4.6 M
Updatingfor dependencies:
perl-Git noarch 1.7.1-9.el6_9 updates 29 k
TransactionSummary
=================================================================================================
Upgrade2Package(s)
Total download size:4.6 M
Isthis ok [y/N]: y
DownloadingPackages:
Setting up and reading Presto delta metadata
Processing delta metadata
Package(s) data still to download:4.6 M
(1/2):git-1.7.1-9.el6_9.x86_64.rpm |4.6 MB 00:00
(2/2): perl-Git-1.7.1-9.el6_9.noarch.rpm |29 kB 00:00
-------------------------------------------------------------------------------------------------
Total5.8 MB/s |4.6 MB 00:00
Running rpm_check_debug
RunningTransactionTest
TransactionTestSucceeded
RunningTransaction
Updating: perl-Git-1.7.1-9.el6_9.noarch1/4
Updating:git-1.7.1-9.el6_9.x86_64 2/4
Cleanup: perl-Git-1.7.1-8.el6.noarch3/4
Cleanup:git-1.7.1-8.el6.x86_64 4/4
Verifying:git-1.7.1-9.el6_9.x86_64 1/4
Verifying: perl-Git-1.7.1-9.el6_9.noarch2/4
Verifying:git-1.7.1-8.el6.x86_64 3/4
Verifying: perl-Git-1.7.1-8.el6.noarch4/4
Updated:
git.x86_64 0:1.7.1-9.el6_9
DependencyUpdated:
perl-Git.noarch 0:1.7.1-9.el6_9
Complete!

验证升级后的 git 版本.

#yumlistgit
InstalledPackages
git.x86_64 1.7.1-9.el6_9@updates
或
# rpm -q git
git-1.7.1-9.el6_9.x86_64

现在我们成功升级这个软件包,可以对它进行回滚了。步骤如下。

使用 YUM history 命令回滚升级操作

首先,使用下面命令获取 yum 操作的 id。下面的输出很清晰地列出了所有需要的信息,例如操作 id、谁做的这个操作(用户名)、操作日期和时间、操作的动作(安装还是升级)、操作影响的包数量。

#yum history
或
#yum history list all
Loaded plugins: fastestmirror, presto
ID |Login user |Dateandtime|Action(s)|Altered
-------------------------------------------------------------------------------
13| root |2017-08-1813:30|Update|2
12| root |2017-08-1007:46|Install|1
11| root |2017-07-2817:10| E, I, U |28 EE
10| root |2017-04-2109:16| E, I, U |162 EE
9| root |2017-02-0917:09| E, I, U |20 EE
8| root |2017-02-0210:45|Install|1
7| root |2016-12-1506:48|Update|1
6| root |2016-12-1506:43|Install|1
5| root |2016-12-0210:28| E, I, U |23 EE
4| root |2016-10-2805:37| E, I, U |13 EE
3| root |2016-10-1812:53|Install|1
2| root |2016-09-3010:28| E, I, U |31 EE
1| root |2016-07-2611:40| E, I, U |160 EE

上面命令显示有两个包受到了影响,因为 git 还升级了它的依赖包 perl-Git。 运行下面命令来查看关于操作的详细信息。

#yum history info13
Loaded plugins: fastestmirror, presto
Transaction ID :13
Begintime:FriAug1813:30:522017
Begin rpmdb :420:f5c5f9184f44cf317de64d3a35199e894ad71188
Endtime:13:30:542017(2 seconds)
End rpmdb :420:d04a95c25d4526ef87598f0dcaec66d3f99b98d4
User: root
Return-Code:Success
CommandLine: update git
Transaction performed with:
Installed rpm-4.8.0-55.el6.x86_64 @base
Installedyum-3.2.29-81.el6.centos.noarch @base
Installedyum-plugin-fastestmirror-1.1.30-40.el6.noarch@base
Installedyum-presto-0.6.2-1.el6.noarch@anaconda-CentOS-201207061011.x86_64/6.3
PackagesAltered:
Updatedgit-1.7.1-8.el6.x86_64 @base
Update1.7.1-9.el6_9.x86_64 @updates
Updated perl-Git-1.7.1-8.el6.noarch@base
Update1.7.1-9.el6_9.noarch@updates
history info

运行下面命令来回滚 git 包到上一个版本。

#yum history undo 13
Loaded plugins: fastestmirror, presto
Undoing transaction 53,fromFriAug1813:30:522017
Updatedgit-1.7.1-8.el6.x86_64 @base
Update1.7.1-9.el6_9.x86_64 @updates
Updated perl-Git-1.7.1-8.el6.noarch@base
Update1.7.1-9.el6_9.noarch@updates
Loading mirror speeds from cached hostfile
* base: repos.lax.quadranet.com
* epel: fedora.mirrors.pair.com
* extras: repo1.dal.innoscale.net
* updates: mirror.vtti.vt.edu
ResolvingDependencies
-->Running transaction check
--->Packagegit.x86_64 0:1.7.1-8.el6 will be a downgrade
--->Packagegit.x86_64 0:1.7.1-9.el6_9 will be erased
--->Package perl-Git.noarch 0:1.7.1-8.el6 will be a downgrade
--->Package perl-Git.noarch 0:1.7.1-9.el6_9 will be erased
-->FinishedDependencyResolution
DependenciesResolved
=================================================================================================
PackageArchVersionRepositorySize
=================================================================================================
Downgrading:
git x86_64 1.7.1-8.el6 base 4.6 M
perl-Git noarch 1.7.1-8.el6 base 29 k
TransactionSummary
=================================================================================================
Downgrade2Package(s)
Total download size:4.6 M
Isthis ok [y/N]: y
DownloadingPackages:
Setting up and reading Presto delta metadata
Processing delta metadata
Package(s) data still to download:4.6 M
(1/2):git-1.7.1-8.el6.x86_64.rpm |4.6 MB 00:00
(2/2): perl-Git-1.7.1-8.el6.noarch.rpm |29 kB 00:00
-------------------------------------------------------------------------------------------------
Total3.4 MB/s |4.6 MB 00:01
Running rpm_check_debug
RunningTransactionTest
TransactionTestSucceeded
RunningTransaction
Installing: perl-Git-1.7.1-8.el6.noarch1/4
Installing:git-1.7.1-8.el6.x86_64 2/4
Cleanup: perl-Git-1.7.1-9.el6_9.noarch3/4
Cleanup:git-1.7.1-9.el6_9.x86_64 4/4
Verifying:git-1.7.1-8.el6.x86_64 1/4
Verifying: perl-Git-1.7.1-8.el6.noarch2/4
Verifying:git-1.7.1-9.el6_9.x86_64 3/4
Verifying: perl-Git-1.7.1-9.el6_9.noarch4/4
Removed:
git.x86_64 0:1.7.1-9.el6_9 perl-Git.noarch 0:1.7.1-9.el6_9
Installed:
git.x86_64 0:1.7.1-8.el6 perl-Git.noarch 0:1.7.1-8.el6
Complete!

回滚后,使用下面命令来检查降级包的版本。

#yumlistgit
或
# rpm -q git
git-1.7.1-8.el6.x86_64

使用YUM downgrade 命令回滚升级

此外,我们也可以使用 YUM downgrade 命令回滚升级。

#yum downgrade git-1.7.1-8.el6 perl-Git-1.7.1-8.el6
Loaded plugins: search-disabled-repos, security, ulninfo
Setting up DowngradeProcess
ResolvingDependencies
-->Running transaction check
--->Packagegit.x86_64 0:1.7.1-8.el6 will be a downgrade
--->Packagegit.x86_64 0:1.7.1-9.el6_9 will be erased
--->Package perl-Git.noarch 0:1.7.1-8.el6 will be a downgrade
--->Package perl-Git.noarch 0:1.7.1-9.el6_9 will be erased
-->FinishedDependencyResolution
DependenciesResolved
=================================================================================================
PackageArchVersionRepositorySize
=================================================================================================
Downgrading:
git x86_64 1.7.1-8.el6 base 4.6 M
perl-Git noarch 1.7.1-8.el6 base 29 k
TransactionSummary
=================================================================================================
Downgrade2Package(s)
Total download size:4.6 M
Isthis ok [y/N]: y
DownloadingPackages:
(1/2):git-1.7.1-8.el6.x86_64.rpm |4.6 MB 00:00
(2/2): perl-Git-1.7.1-8.el6.noarch.rpm |28 kB 00:00
-------------------------------------------------------------------------------------------------
Total3.7 MB/s |4.6 MB 00:01
Running rpm_check_debug
RunningTransactionTest
TransactionTestSucceeded
RunningTransaction
Installing: perl-Git-1.7.1-8.el6.noarch1/4
Installing:git-1.7.1-8.el6.x86_64 2/4
Cleanup: perl-Git-1.7.1-9.el6_9.noarch3/4
Cleanup:git-1.7.1-9.el6_9.x86_64 4/4
Verifying:git-1.7.1-8.el6.x86_64 1/4
Verifying: perl-Git-1.7.1-8.el6.noarch2/4
Verifying:git-1.7.1-9.el6_9.x86_64 3/4
Verifying: perl-Git-1.7.1-9.el6_9.noarch4/4
Removed:
git.x86_64 0:1.7.1-9.el6_9 perl-Git.noarch 0:1.7.1-9.el6_9
Installed:
git.x86_64 0:1.7.1-8.el6 perl-Git.noarch 0:1.7.1-8.el6
Complete!

注意: 你也需要降级依赖包,否则它会删掉当前版本的依赖包而不是对依赖包做降级,因为 downgrade 命令无法处理依赖关系。

至于 Fedora 用户

命令是一样的,只需要将包管理器名称从 yum 改成 dnf 就行了。

# dnf listgit
# dnf history
# dnf history info
# dnf history undo
# dnf listgit
# dnf downgrade git-1.7.1-8.el6 perl-Git-1.7.1-8.el6

CentOS 7,使用yum安装Nginx

当使用以下命令安装Nginx时,发现无法安装成功

yum install -y nginx

需要做一点处理。

安装Nginx源

执行以下命令:

rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

安装该rpm后,我们就能在/etc/yum.repos.d/ 目录中看到一个名为nginx.repo 的文件。

安装Nginx

安装完Nginx源后,就可以正式安装Nginx了。

yum install -y nginx

Nginx默认目录

输入命令:

whereis nginx

即可看到类似于如下的内容:

nginx: /usr/sbin/nginx /usr/lib64/nginx /etc/nginx /usr/share/nginx

以下是Nginx的默认路径:

(1) Nginx配置路径:/etc/nginx/
(2) PID目录:/var/run/nginx.pid
(3) 错误日志:/var/log/nginx/error.log
(4) 访问日志:/var/log/nginx/access.log
(5) 默认站点目录:/usr/share/nginx/html

事实上,只需知道Nginx配置路径,其他路径均可在/etc/nginx/nginx.conf 以及/etc/nginx/conf.d/default.conf 中查询到。

常用命令

(1) 启动:

nginx

(2) 测试Nginx配置是否正确:

nginx -t

(3) 优雅重启:

nginx -s reload

(4) 查看nginx的进程号:

ps -ef |grep nginx

(5)nginx服务停止

nginx -s stop
kill -9 pid

当然,Nginx也可以编译源码安装,步骤相对要繁琐一些,总的来说,还是比较简单的,本文不作赘述