安装Centos系统

此处略去N个字

更换Centos源

由于默认安装的Centos源大陆访问比较慢,所以可以考虑更换一下源
首先备份下原来的源

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

然后用vim新建一个文件CentOS-Base.repo

1
vim /etc/yum.repos.d/CentOS-Base.repo

记得进入vim后先按一下键盘i键,确保进入插入模式,然后再进行下面代码的复制粘贴
此处的代码是清华源,其他源同理,找到对应的,粘贴进去即可

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client. You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#

[base]
name=CentOS-$releasever – Base
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/os/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#released updates
[updates]
name=CentOS-$releasever – Updates
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/updates/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that may be useful
[extras]
name=CentOS-$releasever – Extras
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/extras/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever – Plus
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/centosplus/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

然后刷新缓存更新源

1
sudo yum makecache

完成。

安装gcc

Linux下需要编译源码安装,源码是c,所以需要安装gcc进行编译,默认centos安装的时候如果选了开发相关,应该会自带gcc。
此处安装略过,如有需要再补充

安装Redis

下载redis,新版的可以从这里找到http://redis.io/download
此处以6.0.8版本为例
wget下载

1
wget http://download.redis.io/releases/redis-6.0.8.tar.gz

然后

1
tar -zxvf redis-6.0.8.tar.gz

解压缩,然后make指令进行编译
然后进入到cd /usr/local/redis/bin/ 目录
然后运行redis进行测试

1
2
cd /usr/local/redis/bin/
./redis-server

注意点:

上面的方法可以正常运行server,但是如果用python等,链接redis服务的时候会报下面错误

DENIED Redis is running in protected mode because protected mode is enabled…………

配置文件redis.conf里面修改

tected-mode yes 为tected-mode no

然后启动的时候用下面命令指定你修改的那个配置文件进行启动即可解决。

./redis-server ./xxx/xxx/redis.conf

如果你使用的是虚拟机或其他服务器(不是本地电脑),可能会出现下面报错
!!前提是你要确保填写的服务器地址端口等信息,以及确保redis服务已启用的情况下(因为这种情况和上述情况的报错相同)

redis.exceptions.ConnectionError: Error 10061 connecting to 192.168.73.128:6379. 由于目标计算机积极拒绝,无法连接。

修改redis.conf,将其中的bind 127.0.0.1修改为bind 0.0.0.0,然后再指定配置文件启动即可。