1. 程式人生 > >編譯安裝redis

編譯安裝redis

bsp med alt server mar cst add 宋體 watermark


redis官網

http://www.redis.cn/download.html


1)安裝詳細步驟

[root@liujihaoth ~]# wget http://download.redis.io/releases/redis-4.0.10.tar.gz

[root@liujihaoth soft]# tar xzf redis-4.0.10.tar.gz

技術分享圖片

[root@liujihaoth redis-4.0.10] make && make install

Copy生成文件至指定目錄

[root@liujihaoth redis-4.0.10] cp src/redis-* /usr/local/bin/


至此,redis已經安裝完成。 接下來是配置開機啟動及將期添加至systemctl下進行管理

2)新增redis用戶及組

[root@liujihaoth redis-4.0.10] groupadd redis

[root@liujihaoth redis-4.0.10] useradd -c Redis Server -s /sbin/nologin

3)增加服務

vim /usr/lib/systemd/system/redis.service

技術分享圖片

[Unit]
Description=Redis persistent key-value database
After=network.target
[Service]
ExecStart=/usr/local/bin/redis-server /etc/redis.conf --daemonize no
ExecStop=/usr/local/bin/redis-cli  shutdown
User=redis
Group=redis
RuntimeDirectory=redis
RuntimeDirectoryMode=0755
[Install]
WantedBy=multi-user.target



4)開機啟動和 測試服務

[root@liujihaoth redis-4.0.10] chkconfig --add redis

[root@liujihaoth redis-4.0.10] systemctl enable redis.service

[root@liujihaoth redis-4.0.10] systemctl status redis.service

[root@liujihaoth redis-4.0.10] /usr/bin/redis-cli -h 127.0.0.1 -p 6379


5)開啟遠程連接

[root@liujihaoth redis-4.0.10]# vim /etc/redis.conf

技術分享圖片

[root@liujihaoth redis-4.0.10] systemctl restart redis.service


6)PHP連接測試

$ip = "xx.xxx.xx";//改成自己的服務器地址
$port = 6379;
$redis = new Redis();
$redis->pconnect($ip, $port, 1);
$key = "test";
$value = "this is test";

$redis->set($key, $value);
$d = $redis->get($key);
var_dump($d);



編譯安裝redis