久久精品人人爽,华人av在线,亚洲性视频网站,欧美专区一二三

redis的搭建過程

142次閱讀
沒有評論

共計 4214 個字符,預計需要花費 11 分鐘才能閱讀完成。

本篇內容介紹了“redis 的搭建過程”的有關知識,在實際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓丸趣 TV 小編帶領大家學習一下如何處理這些情況吧!希望大家仔細閱讀,能夠學有所成!

redis 官網:http://download.redis.io/releases

redis 安裝包    redis-3.2.13.tar.gz

解壓:tar -xvf redis-3.2.13.tar.gz

把解壓的 redis 放在你準備的目錄下面,我放在根 / 下面。

cd redis-3.2.13
make

編譯好了,進入 src 文件下面;

[root@localhost src]# make install
Hint: It s a good idea to run make test )
   INSTALL install
   INSTALL install
   INSTALL install
   INSTALL install
   INSTALL install
[root@localhost src]#

返回上一層,

[root@localhost redis-3.2.13]# pwd

/redis-3.2.13

[root@localhost redis-3.2.13]# vim redis.conf

bind 0.0.0.0   如果別人要訪問修改成 0.0.0.0,默認是本機連接

daemonize yes   默認不是后臺啟動,我們修改成 yes

requirepass 123   去掉 #號,修改密碼,重啟生效,

timeout 10

現在啟動 redis,我們設置了后臺啟動的,所以不會顯示什么:

[root@localhost redis-3.2.13]# ./src/redis-server /redis-3.2.13/redis.conf

查看進程:

[root@localhost redis-3.2.13]# ps -ef|grep redis
root      4434     1  0 10:54 ?        00:00:00 ./src/redis-server 127.0.0.1:6379
root      4506   818  0 10:55 pts/2    00:00:00 grep –color=auto redis

進入 redis:

[root@localhost redis-3.2.13]# redis-cli -a 123
127.0.0.1:6379
127.0.0.1:6379 config get dir
1) dir
2) /redis-3.2.13
127.0.0.1:6379

下面可做可不做,方便后面維護而已:

進入 redis 安裝目錄:

[root@localhost ~]# cd /redis-3.2.13/utils/
[root@localhost utils]# ll
total 52
-rw-rw-r–. 1 root root  593 Mar 19 00:25 build-static-symbols.tcl
-rw-rw-r–. 1 root root 1303 Mar 19 00:25 cluster_fail_time.tcl
-rw-rw-r–. 1 root root 1070 Mar 19 00:25 corrupt_rdb.c
drwxrwxr-x. 2 root root   60 Mar 19 00:25 create-cluster
-rwxrwxr-x. 1 root root 2137 Mar 19 00:25 generate-command-help.rb
drwxrwxr-x. 2 root root   39 Mar 19 00:25 hashtable
drwxrwxr-x. 2 root root   70 Mar 19 00:25 hyperloglog
-rwxrwxr-x. 1 root root 8529 Mar 19 00:25 install_server.sh
drwxrwxr-x. 2 root root   39 Mar 19 00:25 lru
-rw-rw-r–. 1 root root 1277 Mar 19 00:25 redis-copy.rb
-rwxrwxr-x. 1 root root 1098 Mar 19 00:25 redis_init_script
-rwxrwxr-x. 1 root root 1047 Mar 19 00:25 redis_init_script.tpl
-rw-rw-r–. 1 root root 1762 Mar 19 00:25 redis-sha1.rb
drwxrwxr-x. 2 root root  114 Mar 19 00:25 releasetools
-rwxrwxr-x. 1 root root 3787 Mar 19 00:25 speed-regression.tcl
-rwxrwxr-x. 1 root root  693 Mar 19 00:25 whatisdoing.sh
[root@localhost utils]# vim redis_init_script
REDISPORT=6379
EXEC=/usr/local/bin/redis-server    – 找到 redis-server,我的在 /redis-3.2.13/src
CLIEXEC=/usr/local/bin/redis-cli    – 找到 redis-server,我的在 /redis-3.2.13/src
PIDFILE=/var/run/redis_${REDISPORT}.pid
CONF= /etc/redis/${REDISPORT}.conf     — 配置文件在安裝目錄下面 /redis-3.2.13,注意 redis.confg 名字
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 -p $REDISPORT shutdown    —- 注意密碼問題 -a password
               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

修改好了,就把這個文件 /etc/init.d 下面,改名 redis

[root@localhost utils]# mv redis_init_script /etc/init.d/redis
[root@localhost utils]# chmod +x /etc/init.d/redis

修改好了,停一下報錯,發現還沒有配置好:

[root@localhost utils]# service redis stop
Stopping …
(error) NOAUTH Authentication required.
Waiting for Redis to shutdown …
Waiting for Redis to shutdown …
Waiting for Redis to shutdown …
Waiting for Redis to shutdown …
Waiting for Redis to shutdown …
Waiting for Redis to shutdown …
Waiting for Redis to shutdown …
Waiting for Redis to shutdown …
Waiting for Redis to shutdown …
Waiting for Redis to shutdown …

找到問題了,原來是 /etc/init.d/redis 下面的腳本缺少 -a 密碼認證

[root@localhost init.d]# service redis stop
Stopping …
Redis stopped

配置下面的內核參數,否則 Redis 腳本在重啟或停止 redis 時,將會報錯,并且不能自動在停止服務前同步數據到磁盤上 /etc/sysctl.conf 加上  

#vim /etc/sysctl.conf

vm.overcommit_memory = 1 

#sysctl -p 

vi /etc/profile

export PATH= $PATH:/redis-3.2.13/src     這個位置就是 redis-server 和 redis-cli 的位置

redis 狀態監測:

[root@localhost init.d]# redis-cli -a 123 –stat

[root@localhost init.d]# redis-cli -a 123 –bigkeys -i 0.01

掃描大 key

主從同步:

1,先修改從庫的配置文件

slaveof 主庫 ip 端口

2,重啟從庫

3,登錄從庫,slaveof 主庫 ip 端口   —- 開啟主從同步

遇到的問題。

1,從庫配置文件添加了 slaveof,但是從主不同步,查看 info,

repl_backlog_active:0   顯示的為 0

解決辦法:重啟從庫,執行 slaveof no one,再執行 slaveof 主 ip+ 端口,

redis 使用命令:

127.0.0.1:6379 config get dir
1) dir
2) /apps/redis/data/master
127.0.0.1:6379

info 查看 redis 的基本信息

1、protected-mode

#protected-mode yes
#是否開啟保護模式,默認開啟。要是配置里沒有指定 bind 和密碼。開啟該參數后,redis 只會
本地進行訪問,拒絕外部訪問。要是開啟了密碼 和 bind,可以開啟。否 則最好關閉,設置為 no。

“redis 的搭建過程”的內容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業相關的知識可以關注丸趣 TV 網站,丸趣 TV 小編將為大家輸出更多高質量的實用文章!

正文完
 
丸趣
版權聲明:本站原創文章,由 丸趣 2023-07-28發表,共計4214字。
轉載說明:除特殊說明外本站除技術相關以外文章皆由網絡搜集發布,轉載請注明出處。
評論(沒有評論)
主站蜘蛛池模板: 军事| 江达县| 肃南| 绍兴市| 永康市| 惠安县| 长岭县| 宕昌县| 天门市| 佛教| 黎川县| 宁夏| 澄城县| 理塘县| 平遥县| 博爱县| 台北县| 缙云县| 双峰县| 喀什市| 容城县| 郎溪县| 惠州市| 赫章县| 正安县| 浦北县| 隆回县| 萍乡市| 溧阳市| 朝阳市| 黑河市| 阿瓦提县| 玛纳斯县| 保靖县| 东港市| 赫章县| 涿鹿县| 高安市| 买车| 监利县| 朝阳县|