聰明屋視角
關(guān)注互聯(lián)網(wǎng),關(guān)注技術(shù)開發(fā),透析與分享移動互聯(lián)網(wǎng)行業(yè)最新動態(tài)linux redis
時間:2019-02-17 13:33:29 閱讀:98916次 分類:解決方案
1、下載
wget http://download.redis.io/releases/redis-2.8.7.tar.gz下載后的文件在當(dāng)前目錄里 redis-2.8.7.tar.gz
2、編譯安裝
tar xf redis-2.8.7.tar.gz
cd redis-2.8.7make
make install
如果沒有安裝gcc的話會提示gcc not found 于是就需要安裝一下gcc: yum -y install gcc 因為剛開始把yum的源換成163的了,怎么都不行,后來逼迫無奈換回原來的,結(jié)果就好了 辛虧剛開始就備份了系統(tǒng)自帶的,可見備份配置文件的好處 其實最好的方法應(yīng)該是設(shè)置添加第三方的源并默認(rèn)選擇最快的,可以參考 裝好之后重新執(zhí)行一下上邊的
3、創(chuàng)建配置文件
mkdir /etc/rediscp redis.conf /etc/redis/redis.conf
4、調(diào)整下內(nèi)存分配使用方式并使其生效
echo “vm.overcommit_memory=1”>>/etc/sysctl.conf
此參數(shù)可用的值為0,1,2 #0表示當(dāng)用戶空間請求更多的內(nèi)存時,內(nèi)核嘗試估算出可用的內(nèi)存* *1表示內(nèi)核允許超量使用內(nèi)存直到內(nèi)存用完為止* *2表示整個內(nèi)存地址空間不能超過`swap+(vm.overcommit_ratio)%`的RAM值*
sysctl -p
5、 修改redis配置
vi /etc/redis/redis.conf
daemonize yes
redis以守護進程的方式運行, #no表示不以守護進程的方式運行(會占用一個終端) timeout 300 客戶端閑置多長時間后斷開連接,默認(rèn)為0關(guān)閉此功能 loglevel verbose 設(shè)置redis日志級別 logfile stdout 設(shè)置日志文件的輸出方式,如果以守護進程的方式運行redis 并且日志輸出設(shè)置為stdout,那么日志信息就輸出到/dev/null里面去了
6、啟動redis
redis-server /etc/redis/redis.conf
7、測試redis
[root@localhost redis]# redis-cli 127.0.0.1:6379> set name wayne
OK 127.0.0.1:6379> get name "wayne" 127.0.0.1:6379>
redis問題解決(MISCONF Redis is configured to save RDB snapshots)
(error) MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk. Commands that may modify the data set are disabled. Please check Redis logs for details about the error.
使用如下命令解決:
config set stop-writes-on-bgsave-error no
1、安裝編譯工具
yum install wget make gcc gcc-c++ zlib-devel openssl openssl-devel pcre-devel kernel keyutils patch perl
2、安裝tcl組件包(安裝Redis需要tcl支持)
下載:http://downloads.sourceforge.net/tcl/tcl8.6.1-src.tar.gz
上傳tcl8.6.1-src.tar.gz到/usr/local/src目錄
cd /usr/local/src #進入軟件包存放目錄
tar zxvf tcl8.6.1-src.tar.gz #解壓
cd tcl8.6.1 #進入安裝目錄
cd unix
./configure --prefix=/usr --without-tzdata --mandir=/usr/share/man $([ $(uname -m) = x86_64 ] && echo --enable-64bit) #配置
make #編譯
sed -e "s@^\(TCL_SRC_DIR='\).*@\1/usr/include'@" -e "/TCL_B/s@='\(-L\)\?.*unix@='\1/usr/lib@" -i tclConfig.sh
make install #安裝
make install-private-headers
ln -v -sf tclsh8.6 /usr/bin/tclsh
chmod -v 755 /usr/lib/libtcl8.6.so
3、安裝Redis
下載:http://download.redis.io/redis-stable.tar.gz
上傳redis-stable到/usr/local/src目錄
cd /usr/local/src
tar -zxvf redis-stable.tar.gz #解壓
mv redis-stable /usr/local/redis #移動文件到安裝目錄
cd /usr/local/redis #進入安裝目錄
make #編譯
make install #安裝
cd /usr/local/bin #查看是否有下面文件,如果沒有,拷貝下面文件到/usr/local/bin目錄
cd /usr/local/redis
mkdir -p /usr/local/bin
cp -p redis-server /usr/local/bin
cp -p redis-benchmark /usr/local/bin
cp -p redis-cli /usr/local/bin
cp -p redis-check-dump /usr/local/bin
cp -p redis-check-aof /usr/local/bin
ln -s /usr/local/redis/redis.conf /etc/redis.conf #添加配置文件軟連接
vi /etc/redis.conf #編輯
daemonize yes #設(shè)置后臺啟動redis
:wq! #保存退出
redis-server /etc/redis.conf #啟動redis服務(wù)
redis-cli shutdown #關(guān)閉redis
vi /etc/sysctl.conf #編輯,在最后一行添加下面代碼
vm.overcommit_memory = 1
:wq! #保存退出
sysctl -p #使設(shè)置立即生效
4、設(shè)置redis開機啟動
vi /etc/init.d/redis #編輯,添加以下代碼
#!/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.conf"
redis_pid="/var/run/redis.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
系統(tǒng)運維 www.osyunwei.com 溫馨提醒:qihang01原創(chuàng)內(nèi)容 版權(quán)所有,轉(zhuǎn)載請注明出處及原文鏈接
5、設(shè)置redis配置文件參數(shù)
mkdir -p /usr/local/redis/var #創(chuàng)建redis數(shù)據(jù)庫存放目錄
vi /etc/redis.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)綁定本機所有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ù)庫連接密碼
1、下載
wget http://download.redis.io/releases/redis-2.8.7.tar.gz下載后的文件在當(dāng)前目錄里 redis-2.8.7.tar.gz
2、編譯安裝
tar xf redis-2.8.7.tar.gz
cd redis-2.8.7make
make install
如果沒有安裝gcc的話會提示gcc not found 于是就需要安裝一下gcc: yum -y install gcc 因為剛開始把yum的源換成163的了,怎么都不行,后來逼迫無奈換回原來的,結(jié)果就好了 辛虧剛開始就備份了系統(tǒng)自帶的,可見備份配置文件的好處 其實最好的方法應(yīng)該是設(shè)置添加第三方的源并默認(rèn)選擇最快的,可以參考 裝好之后重新執(zhí)行一下上邊的
3、創(chuàng)建配置文件
mkdir /etc/rediscp redis.conf /etc/redis/redis.conf
4、調(diào)整下內(nèi)存分配使用方式并使其生效
echo “vm.overcommit_memory=1”>>/etc/sysctl.conf
此參數(shù)可用的值為0,1,2 #0表示當(dāng)用戶空間請求更多的內(nèi)存時,內(nèi)核嘗試估算出可用的內(nèi)存* *1表示內(nèi)核允許超量使用內(nèi)存直到內(nèi)存用完為止* *2表示整個內(nèi)存地址空間不能超過`swap+(vm.overcommit_ratio)%`的RAM值*
sysctl -p
5、 修改redis配置
vi /etc/redis/redis.conf
daemonize yes
redis以守護進程的方式運行, #no表示不以守護進程的方式運行(會占用一個終端) timeout 300 客戶端閑置多長時間后斷開連接,默認(rèn)為0關(guān)閉此功能 loglevel verbose 設(shè)置redis日志級別 logfile stdout 設(shè)置日志文件的輸出方式,如果以守護進程的方式運行redis 并且日志輸出設(shè)置為stdout,那么日志信息就輸出到/dev/null里面去了
6、啟動redis
redis-server /etc/redis/redis.conf
7、測試redis
[root@localhost redis]# redis-cli 127.0.0.1:6379> set name wayne
OK 127.0.0.1:6379> get name "wayne" 127.0.0.1:6379>
redis問題解決(MISCONF Redis is configured to save RDB snapshots)
(error) MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk. Commands that may modify the data set are disabled. Please check Redis logs for details about the error.
使用如下命令解決:
config set stop-writes-on-bgsave-error no
1、安裝編譯工具
yum install wget make gcc gcc-c++ zlib-devel openssl openssl-devel pcre-devel kernel keyutils patch perl
2、安裝tcl組件包(安裝Redis需要tcl支持)
下載:http://downloads.sourceforge.net/tcl/tcl8.6.1-src.tar.gz
上傳tcl8.6.1-src.tar.gz到/usr/local/src目錄
cd /usr/local/src #進入軟件包存放目錄
tar zxvf tcl8.6.1-src.tar.gz #解壓
cd tcl8.6.1 #進入安裝目錄
cd unix
./configure --prefix=/usr --without-tzdata --mandir=/usr/share/man $([ $(uname -m) = x86_64 ] && echo --enable-64bit) #配置
make #編譯
sed -e "s@^\(TCL_SRC_DIR='\).*@\1/usr/include'@" -e "/TCL_B/s@='\(-L\)\?.*unix@='\1/usr/lib@" -i tclConfig.sh
make install #安裝
make install-private-headers
ln -v -sf tclsh8.6 /usr/bin/tclsh
chmod -v 755 /usr/lib/libtcl8.6.so
3、安裝Redis
下載:http://download.redis.io/redis-stable.tar.gz
上傳redis-stable到/usr/local/src目錄
cd /usr/local/src
tar -zxvf redis-stable.tar.gz #解壓
mv redis-stable /usr/local/redis #移動文件到安裝目錄
cd /usr/local/redis #進入安裝目錄
make #編譯
make install #安裝
cd /usr/local/bin #查看是否有下面文件,如果沒有,拷貝下面文件到/usr/local/bin目錄
cd /usr/local/redis
mkdir -p /usr/local/bin
cp -p redis-server /usr/local/bin
cp -p redis-benchmark /usr/local/bin
cp -p redis-cli /usr/local/bin
cp -p redis-check-dump /usr/local/bin
cp -p redis-check-aof /usr/local/bin
ln -s /usr/local/redis/redis.conf /etc/redis.conf #添加配置文件軟連接
vi /etc/redis.conf #編輯
daemonize yes #設(shè)置后臺啟動redis
:wq! #保存退出
redis-server /etc/redis.conf #啟動redis服務(wù)
redis-cli shutdown #關(guān)閉redis
vi /etc/sysctl.conf #編輯,在最后一行添加下面代碼
vm.overcommit_memory = 1
:wq! #保存退出
sysctl -p #使設(shè)置立即生效
4、設(shè)置redis開機啟動
vi /etc/init.d/redis #編輯,添加以下代碼
#!/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.conf"
redis_pid="/var/run/redis.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
系統(tǒng)運維 www.osyunwei.com 溫馨提醒:qihang01原創(chuàng)內(nèi)容 版權(quán)所有,轉(zhuǎn)載請注明出處及原文鏈接
5、設(shè)置redis配置文件參數(shù)
mkdir -p /usr/local/redis/var #創(chuàng)建redis數(shù)據(jù)庫存放目錄
vi /etc/redis.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)綁定本機所有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ù)庫連接密碼
蕪湖市聰明屋智能科技有限公司(原中江網(wǎng)絡(luò)),成立于2005年,經(jīng)過10多年定制開發(fā)經(jīng)驗,積累了大量技術(shù)儲備和定制開發(fā)經(jīng)驗,率先創(chuàng)建安徽省內(nèi)自主研發(fā)的云計算平臺,具有大數(shù)據(jù)、高并發(fā)等高強度計算能力,為眾多政府、學(xué)校、公安部門、中小企業(yè)解決數(shù)據(jù)計算與管理難題。2013年公司內(nèi)部專門創(chuàng)建電商服務(wù)部,為企業(yè)提供全方位電商解決方案與配套服務(wù)。多次獲得國家、省市級領(lǐng)導(dǎo)接見,被國內(nèi)近20家電視臺、報紙媒體爭相報道。至今,聰明屋智能科技服務(wù)過上市公司、大型國企、各類私企超800家,為多家公司提供各類政務(wù)系統(tǒng)、app開發(fā)定制、微信小程序開發(fā)定制、智能家居、電商系統(tǒng)、連鎖收銀等技術(shù)解決方案服務(wù)。同時,聰明屋智能科技在智能硬件方面、區(qū)塊鏈應(yīng)用方面持續(xù)投入關(guān)注及創(chuàng)新。