环境
centos7
redis4.0.6
step1. redis参考
yum install gcc && cd /usr/local && wget http://download.redis.io/releases/redis-4.0.6.tar.gz && tar -zxvf redis-4.0.6.tar.gz && cd redis-4.0.6 && make MALLOC=libc && cd src && make install
#修改redis.conf文件 **daemonize yes**
vim /usr/local/redis-4.0.6/redis.conf
# By default Redis does not run as a daemon. Use 'yes' if you need it.
# Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
daemonize yes
#制作开机启动服务
mkdir /etc/redis && cp /usr/local/redis-4.0.6/redis.conf /etc/redis/6379.conf && cp /usr/local/redis-4.0.6/utils/redis_init_script /etc/init.d/redisd
#redisd不支持chkconfig,需要设置如下
vim /etc/init.d/redisd
#请在第一行加入如下两行注释,保存退出
#!/bin/sh
# chkconfig: 2345 90 10
# description: Redis is a persistent key-value database
#执行开机自启命令
chkconfig redisd on
step2. 外网访问配置
vim /etc/redis/6379.conf
# 注释如下
# bind 127.0.0.1
################################## NETWORK #####################################
# By default, if no "bind" configuration directive is specified, Redis listens
# for connections from all the network interfaces available on the server.
# It is possible to listen to just one or multiple selected interfaces using
# the "bind" configuration directive, followed by one or more IP addresses.
#
# Examples:
#
# bind 192.168.1.100 10.0.0.1
# bind 127.0.0.1 ::1
#
# ~~~ WARNING ~~~ If the computer running Redis is directly exposed to the
# internet, binding to all the interfaces is dangerous and will expose the
# instance to everybody on the internet. So by default we uncomment the
# following bind directive, that will force Redis to listen only into
# the IPv4 lookback interface address (this means Redis will be able to
# accept connections only from clients running into the same computer it
# is running).
#
# IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES
# JUST COMMENT THE FOLLOWING LINE.
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# bind 127.0.0.1
step3. 设置密码
vim /etc/redis/6379.conf
################################## SECURITY ###################################
# Require clients to issue AUTH <PASSWORD> before processing any other
# commands. This might be useful in environments in which you do not trust
# others with access to the host running redis-server.
#
# This should stay commented out for backward compatibility and because most
# people do not need auth (e.g. they run their own servers).
#
# Warning: since Redis is pretty fast an outside user can try up to
# 150k passwords per second against a good box. This means that you should
# use a very strong password otherwise it will be very easy to break.
#
# requirepass foobared
requirepass 123456
step3. 服务开关命令
service redisd start
service redisd stop
step4. 停止服务报错:Waiting for Redis to shutdown
vim /etc/init.d/redisd
#将下面yourpassword替换成 上面设置的redis密码
#!/bin/sh
# chkconfig: 2345 90 10
# description: Redis is a persistent key-value database
#
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.
REDISPORT=6379
EXEC=/usr/local/bin/redis-server
CLIEXEC=/usr/local/bin/redis-cli
PIDFILE=/var/run/redis_${REDISPORT}.pid
CONF="/etc/redis/${REDISPORT}.conf"
case "$1" in
start)
if [ -f $PIDFILE ]
then
echo "$PIDFILE exists, process is already running or crashed"
else
echo "Starting Redis server..."
$EXEC $CONF
fi
;;
stop)
if [ ! -f $PIDFILE ]
then
echo "$PIDFILE does not exist, process is not running"
else
PID=$(cat $PIDFILE)
echo "Stopping ..."
$CLIEXEC -a "yourpassword" -p $REDISPORT shutdown
while [ -x /proc/${PID} ]
do
echo "Waiting for Redis to shutdown ..."
sleep 1
done
echo "Redis stopped"
fi
;;
*)
echo "Please use start or stop as first argument"
;;
esac
step5. 发布flask
pip install gunicorn
pip install lxml
pip install redis==3.2.0
pip install Flask==1.0.2
pip install Flask-APScheduler==1.11.0
pip install Flask-Caching==1.5.0