回到顶部

CONTENTS

centos7 之 python3, git, nginx, redis 安装

本篇所有命令均在 root 权限下执行

安装 python3

安装依赖包:

yum -y install gcc gcc-c++

yum -y install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel

下载安装包:

# 官网 https://www.python.org/downloads/source/

wget https://www.python.org/ftp/python/3.6.8/Python-3.6.8.tgz

解压安装包:

tar zxvf Python-3.6.8.tgz

cd 到解压目录:

cd Python-3.6.8

执行 configure 文件:

./configure --prefix=/usr/local/python3

编译和安装:

make && make install

创建短连接:

cd /usr/bin

ln -s /usr/local/python3/bin/python3.6 python3

ln -s /usr/local/python3/bin/pip3 pip3

ln -s /usr/local/python3/bin/virtualenv virtualenv(安装 virtualenvwrapper 后执行)

 

安装 virtualenvwrapper

pip 安装 virtualenvwrapper(会自动安装 virtualenv):

pip3 install virtualenvwrapper

创建虚拟环境的主目录:

mkdir $HOME/.envs

在 ~/.bashrc 添加环境变量:

vim ~/.bashrc

# 添加如下内容

VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3

export WORKON_HOME=$HOME/.envs

source /usr/local/python3/bin/virtualenvwrapper.sh

保存退出:

wq

刷新 ~/.bashrc:

source ~/.bashrc

新建虚拟环境:

mkvirtualenv djangoblog

删除虚拟环境:

rmvirtualenv djangoblog

进入虚拟环境:

workon djangoblog

导出 虚拟环境 的安装包:

pip freeze > requirements.txt

安装 虚拟环境 导出的安装包:

pip install -r requirements.txt

退出虚拟环境:

deactivate

 

安装 git

安装依赖包:

yum -y install gcc gcc-c++

yum -y install curl-devel expat-devel gettext-devel openssl-devel zlib-devel yum -y install gcc perl-ExtUtils-MakeMaker

下载安装包:

# 官网 https://git-scm.com/downloads

wget https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.20.1.tar.gz

解压安装包:

tar zxvf git-2.20.1.tar.gz

cd 到解压目录:

cd git-2.20.1

执行 configure 文件:

./configure --prefix=/usr/local/git-2.20.1

编译和安装:

make && make install

创建短连接:

cd /usr/bin

ln -s /usr/local/git-2.20.1/bin/git git

 

安装 nginx

安装依赖包:

yum -y install gcc gcc-c++ autoconf automake make

yum -y install zlib zlib-devel openssl openssl-devel pcre pcre-devel

下载安装包:

# 官网 https://nginx.org/en/download.html

wget http://nginx.org/download/nginx-1.14.2.tar.gz

解压安装包:

tar zxvf nginx-1.14.2.tar.gz

cd 到解压目录:

cd nginx-1.14.2

执行配置文件:(第二条是含 ssl 模块)

./configure --prefix=/usr/local/nginx-1.14.2

./configure --prefix=/usr/local/nginx-1.14.2 --with-http_ssl_module

编译和安装:

make && make install

创建短连接:

cd /usr/bin

ln -s /usr/local/nginx-1.14.2/sbin/nginx nginx

 

安装 redis

安装依赖包:

yum install -y gcc-c++

下载安装包:

# 官网 https://redis.io/download

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

解压安装包:

tar xzf redis-5.0.5.tar.gz

cd 到解压目录:

cd redis-5.0.5

编译和安装:

make install PREFIX=/usr/local/redis-5.0.5

创建配置文件目录:

mkdir /etc/redis

复制 redis-5.0.5 下的 redis.config 到 /etc/redis:

cp redis.conf /etc/redis/redis.conf

修改 /etc/redis/redis.conf:

vim /etc/redis/redis.conf

将 daemonize no 改为 yes(即守护进程,还可配置外网访问、密码访问、分配内存大小等)

指定 redis.conf 文件启动 redis:

cd /usr/local/redis-5.0.5/bin

./redis-server /etc/redis/redis.conf

[root@taiwan-ss bin]# ./redis-server /etc/redis/redis.conf
6105:C 25 Jul 2019 07:22:02.426 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
6105:C 25 Jul 2019 07:22:02.427 # Redis version=5.0.5, bits=64, commit=00000000, modified=0, pid=6105, just started
6105:C 25 Jul 2019 07:22:02.427 # Configuration loaded

进入和退出 redis 命令行模式:

cd /usr/local/redis-5.0.5/bin

[root@taiwan-ss bin]# redis-cli
127.0.0.1:6379> exit

Centos7 设置开机启动:

cd /etc/systemd/system

vim redis.service

[Unit]
Description=Redis Server Manager
After=network.target
 
[Service]
Type=notify
User=root
Group=root
PIDFile=/var/run/redis_6379.pid
ExecStart=/usr/local/redis-5.0.5/bin/redis-server /etc/redis/redis.conf --supervised systemd
ExecStop=/usr/local/redis-5.0.5/bin/redis-cli shutdown
Restart=always

[Install]
WantedBy=multi-user.target
# 重载系统服务,因添加了 redis.server
sudo systemctl daemon-reload
# 启动 redis
sudo systemctl start redis
# 停止 redis
sudo systemctl stop redis
# 查看 redis 状态
sudo systemctl status redis
# 设置开机启动
sudo systemctl enable redis
# 取消开机启动
sudo systemctl disable redis

Centos6 设置开机启动:

# 将 redis 的启动脚本复制一份放到 /etc/init.d 目录下
cp redis-5.0.5/utils/redis_init_script /etc/init.d/redisd
chkconfig redisd on

如果显示 service redisd does not support chkconfig  解决方法:
vim 编辑 redisd 文件,在第一行加入如下两行注释,保存退出
# chkconfig:   2345 90 10
# description:  Redis is a persistent key-value database
注释的意思是,redis 服务必须在运行级 2,3,4,5下被启动或关闭,启动的优先级是 90,关闭的优先级是 10。
再次执行开机自启命令 chkconfig redisd on,这个时候应该就能成功了

启动 redis:service redisd start

关闭 redis:service redisd stop

 

# redis 在 centos7 下配置开机启动参考的资料

# 来张图鼓励下自己(redis 在 centos7 配置开机自启时入了几个坑)

^_^
请喝咖啡 ×

前一篇: centos7 之 sshd,iptables,firewall,fail2ban 常用操作
下一篇: windows 之 bat 实现进程守护