1. 程式人生 > 實用技巧 >使用者登入與註冊

使用者登入與註冊

redis官網:https://redis.io/download下載選擇穩定版本

1、在 /usr/local/ 下建立 redis ⽂件夾並進⼊

cd /usr/local/
mkdir redis
cd redis

2、將 Redis 安裝包解壓到 /usr/local/redis 中即可

tar -zxvf redis-6.0.6.tar.gz

3、安裝redis之前要先安裝8版本的gcc、gcc-c++、gdb工具鏈(toolchian)低版本的安裝會報錯,類似下面這種錯誤

server.c:1031:23: 錯誤:‘struct redisServer’沒有名為‘verbosity’的成員
     
if (level < server.verbosity) return; ^ server.c:1033:47: 錯誤:‘struct redisServer’沒有名為‘logfile’的成員 fp = log_to_stdout ? stdout : fopen(server.logfile,"a"); ^ server.c:1046:47: 錯誤:‘struct redisServer’沒有名為‘timezone’的成員 nolocks_localtime(
&tm,tv.tv_sec,server.timezone,server.daylight_active);

gcc、gcc-c++、gdb工具鏈(toolchian)

//安裝scl源
yum install centos-release-scl scl-utils-build
//列出scl可用源
yum list all --enablerepo='centos-sclo-rh'
//安裝8版本的gcc、gcc-c++、gdb工具鏈(toolchian)
yum install -y devtoolset-8-toolchain
scl enable devtoolset-8 bash
//檢視版本號 gcc --version

4、安裝redis

cd redis-6.0.6/
make && make install

5、啟動redis

cd utils/
./install_server.sh

這步有可能會報錯:
This systems seems to use systemd. Please take a look at the provided example service unit files in this directory, and adapt and install t hem. Sorry!

vi ./install_server.sh

把下面的這個註釋掉

#bail if this system is managed by systemd
#_pid_1_exe="$(readlink -f /proc/1/exe)"
#if [ "${_pid_1_exe##*/}" = systemd ]
#then
#       echo "This systems seems to use systemd."
#       echo "Please take a look at the provided example service unit files in this directory, and adapt and install them. Sorry!"
#       exit 1
#fi
#unset _pid_1_exe

然後重新執行./install_server.sh即可。

6、檢視REDIS服務啟動情況

直接執⾏如下命令來檢視Redis的啟動結果:

systemctl status redis_6379.service

啟動⾃帶的 redis-cli 客戶端,測試通過:

但是此時只能在本地訪問,⽆法遠端連線,因此還需要做部分設定

7、設定訪問密碼

編輯 redis 配置⽂件
vim /etc/redis/6379.conf

找到內容:#requirepass foobared,去掉註釋,將 foobared 修改為⾃⼰想要的密碼,儲存即可。

requirepass 123456

儲存,重啟 Redis 服務即可

systemctl restart redis_6379.service

8、設定允許遠端連線

編輯 redis 配置⽂件
vim /etc/redis/6379.conf

bind 127.0.0.1 修改為 0.0.0.0

然後重啟 Redis 服務即可:

systemctl restart redis_6379.service

此時外面遠端訪問還是訪問不到,因為我的防火牆沒有放開6379埠,開啟6379埠

firewall-cmd --zone=public --add-port=3306/tcp --permanent 
firewall-cmd --reload