Linux 安装Redis全过程日志
wget http://download.redis.io/redis-stable.tar.gz
tar xvzf redis-stable.tar.gz
cd redis-stable
make
?
前面3步應(yīng)該沒有問題,主要的問題是執(zhí)行make的時候,出現(xiàn)了異常。
異常一:
make[2]: cc: Command not found
異常原因:沒有安裝gcc
解決方案:yum install gcc-c++
異常二:
zmalloc.h:51:31: error: jemalloc/jemalloc.h: No such file or directory
異常原因:一些編譯依賴或原來編譯遺留出現(xiàn)的問題
解決方案:make distclean。清理一下,然后再make。
在make成功以后,需要make test。在make test出現(xiàn)異常。
異常一:
couldn't execute "tclsh8.5": no such file or directory
異常原因:沒有安裝tcl
解決方案:yum install -y tcl。
?
在make成功以后,會在src目錄下多出一些可執(zhí)行文件:redis-server,redis-cli等等。
方便期間用cp命令復(fù)制到usr目錄下運行。
cp redis-server /usr/local/bin/
cp redis-cli /usr/local/bin/
然后新建目錄,存放配置文件
mkdir /etc/redis
mkdir /var/redis
mkdir /var/redis/log
mkdir /var/redis/run
mkdir /var/redis/6379
在redis解壓根目錄中找到配置文件模板,復(fù)制到如下位置。
cp redis.conf /etc/redis/6379.conf
通過vim命令修改
daemonize yes
pidfile /var/redis/run/redis_6379.pid
logfile /var/redis/log/redis_6379.log
dir /var/redis/6379
最后運行redis:
$ redis-server /etc/redis/6379.conf
#################################開機(jī)自啟動配置#################################
#!/bin/sh
#
# chkconfig: ? 2345 90 10
# description: ?Redis is a persistent key-value database
# redis ? ?Startup script for redis processes
# processname: redis
redis_path="/usr/local/bin/redis-server"
redis_conf="/etc/redis/6379.conf"
redis_pid="/var/redis/run/redis_6379.pid"
# Source function library.
. /etc/rc.d/init.d/functions
[ -x $redis_path ] || exit 0
RETVAL=0
prog="redis"
# Start daemons.
start() {
if [ -e $redis_pid -a ! -z $redis_pid ];then
echo $prog" already running...."
exit 1
fi
echo -n $"Starting $prog "
# Single instance for all caches
$redis_path $redis_conf
RETVAL=$?
[ $RETVAL -eq 0 ] && {
touch /var/lock/subsys/$prog
success $"$prog"
}
echo
return $RETVAL
}
# Stop daemons.
stop() {
echo -n $"Stopping $prog "
killproc -d 10 $redis_path
echo
[ $RETVAL = 0 ] && rm -f $redis_pid /var/lock/subsys/$prog
RETVAL=$?
return $RETVAL
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status $prog
RETVAL=$?
;;
restart)
stop
start
;;
condrestart)
if test "x`pidof redis`" != x; then
stop
start
fi
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart}"
exit 1
esac
exit $RETVAL
-------------------------------------------------------
:wq! #保存退出
chmod 755 /etc/init.d/redis ?#添加腳本執(zhí)行權(quán)限
chkconfig --add redis ?#添加開啟啟動
chkconfig --level 2345 redis on ?#設(shè)置啟動級別
chkconfig --list redis ?#查看啟動級別
service redis restart ?#重新啟動redis
#################################設(shè)置redis配置文件參數(shù)##############################
mkdir -p /usr/local/redis/var ?#創(chuàng)建redis數(shù)據(jù)庫存放目錄
vim /etc/redis/6370.conf
daemonize yes ?#以后臺daemon方式運行redis
pidfile "/var/run/redis.pid" ?#redis以后臺運行,默認(rèn)pid文件路徑/var/run/redis.pid
port 6379 ?#默認(rèn)端口
bind 127.0.0.1 #默認(rèn)綁定本機(jī)所有ip地址,為了安全,可以只監(jiān)聽內(nèi)網(wǎng)ip
timeout 300 #客戶端超時設(shè)置,單位為秒
loglevel verbose ?#設(shè)置日志級別,支持四個級別:debug、notice、verbose、warning
logfile stdout ?#日志記錄方式,默認(rèn)為標(biāo)準(zhǔn)輸出,logs不寫文件,輸出到空設(shè)備/deb/null
logfile "/usr/local/redis/var/redis.log" ?#可以指定日志文件路徑
databases 16 ?#開啟數(shù)據(jù)庫的數(shù)量
save 900 1
save 300 10
save 60 10000
創(chuàng)建本地數(shù)據(jù)庫快照,格式:save * *
900秒內(nèi),執(zhí)行1次寫操作
300秒內(nèi),執(zhí)行10次寫操作
60秒內(nèi),執(zhí)行10000次寫操作
rdbcompression yes #啟用數(shù)據(jù)庫lzf壓縮,也可以設(shè)置為no
dbfilename dump.rdb ?#本地快照數(shù)據(jù)庫名稱
dir "/usr/local/redis/var/" ? #本地快照數(shù)據(jù)庫存放目錄
requirepass 123456 ?#設(shè)置redis數(shù)據(jù)庫連接密碼
maxclients 10000 #同一時間最大客戶端連接數(shù),0為無限制
maxmemory 1024MB #設(shè)定redis最大使用內(nèi)存,值要小于物理內(nèi)存,必須設(shè)置
appendonly yes ?#開啟日志記錄,相當(dāng)于MySQL的binlog
appendfilename "appendonly.aof" ? #日志文件名,注意:不是目錄路徑
appendfsync everysec #每秒執(zhí)行同步,還有兩個參數(shù)always、no一般設(shè)置為everysec,相當(dāng)于MySQL事物日志的寫方式
:wq! #保存退出
service redis restart #重啟
####################################測試redis數(shù)據(jù)庫####################################
redis-cli -a 123456 ?#連接redis數(shù)據(jù)庫,注意:-a后面跟redis數(shù)據(jù)庫密碼
set name 111cn.net ?#寫數(shù)據(jù)
get name ?#讀取數(shù)據(jù)
exit #退出redis數(shù)據(jù)庫控制臺
redis-benchmark -h 127.0.0.1 -p 6379 -c 1000 -n 100000 ?#1000個并發(fā)連接,100000個請求,測試127.0.0.1端口為6379的redis服務(wù)器性能
轉(zhuǎn)載于:https://www.cnblogs.com/duyinqiang/p/5696600.html
總結(jié)
以上是生活随笔為你收集整理的Linux 安装Redis全过程日志的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [js开源组件开发]图片放大镜
- 下一篇: Task 10 统计从1到某个整数之间出