在LNMP的环境下其中一条很重要的优化就是安装Redis,而对于Memcache和Redis的选择的话,Memcache支持多核多线程,Redis单线程操作并且只使用单核,单核下存储数据较小的时候Redis要比Memcache性能更好,但当数据大于100K时,Memcache优秀之处便体现出来。
因为大象网是个很小的站点,所以我便选择了opcache+Redis,前者先不说,因为操作很简单直接修改PHP.INI就可以,所以这里就简单说下我的腾讯云服务器在LNMP下无法安装Redis的解决方法。
本来服务器的环境是LNMP1.5,正常情况下,我们直接进入LNMP1.5的的目录,执行一条命令就可以正常安装Redis,如果有其它要做的那就是需要等待就可以了。
但我执行命令后却报错了,我没有保存,但我找到了别人的错误显示结果,虽然版本不太一样,但是显示的错误信息却是一样的。
./addons.sh install redis
1
./addons.shinstallredis
Uncompress redis-4.0.2.tgz...
tar (child): redis-4.0.2.tgz: Cannot open: No such file or directory
tar (child): Error is not recoverable: exiting now
tar: Child returned status 2
tar: Error is not recoverable: exiting now
cd redis-4.0.2...
include/main.sh: line 425: cd: redis-4.0.2: No such file or directory
Cannot find config.m4.
Make sure that you run '/usr/local/php/bin/phpize' in the top level source direc tory of the module
include/redis.sh: line 62: ./configure: No such file or directory
make: *** No targets specified and no makefile found. Stop.
make: *** No targets specified and no makefile found. Stop.
make: *** No rule to make target `install'. Stop.
Add to auto startup...
Add redis service at system startup...
Restarting php-fpm......
Gracefully shutting down php-fpm . done
Starting php-fpm [06-Apr-2019 15:40:23] NOTICE: PHP message: PHP Warning: PHP S tartup: Unable to load dynamic library '/usr/local/php/lib/php/extensions/no-deb ug-non-zts-20131226/redis.so' - /usr/local/php/lib/php/extensions/no-debug-non-z ts-20131226/redis.so: cannot open shared object file: No such file or directory in Unknown on line 0
done
Starting Redis server.../etc/init.d/redis: line 33: /usr/local/redis/bin/redis-s erver: No such file or directory
done
Redis install failed!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
Uncompressredis-4.0.2.tgz...
tar(child):redis-4.0.2.tgz:Cannotopen:Nosuchfileordirectory
tar(child):Errorisnotrecoverable:exitingnow
tar:Childreturnedstatus2
tar:Errorisnotrecoverable:exitingnow
cdredis-4.0.2...
include/main.sh:line425:cd:redis-4.0.2:Nosuchfileordirectory
Cannotfindconfig.m4.
Makesurethatyourun'/usr/local/php/bin/phpize'inthetoplevelsourcedirectoryofthemodule
include/redis.sh:line62:./configure:Nosuchfileordirectory
make:***Notargetsspecifiedandnomakefilefound.Stop.
make:***Notargetsspecifiedandnomakefilefound.Stop.
make:***Noruletomaketarget`install'. Stop.
Add to auto startup...
Add redis service at system startup...
Restarting php-fpm......
Gracefully shutting down php-fpm . done
Starting php-fpm [06-Apr-2019 15:40:23] NOTICE: PHP message: PHP Warning: PHP S tartup: Unable to load dynamic library '/usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/redis.so'-/usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/redis.so:cannotopensharedobjectfile:NosuchfileordirectoryinUnknownonline0
done
StartingRedisserver.../etc/init.d/redis:line33:/usr/local/redis/bin/redis-server:Nosuchfileordirectory
done
Redisinstallfailed!
如果你也遇到这个问题,那么你是很幸运的,因为解决起来很简单。这个问题是因为无法下载Redis所以引起的错误,我们修改一下该服务器的DNS就好了,将第一个DNS服务器地址修改为114.114.114.114,第二个DNS服务器地址是否修改并不影响。
vi /etc/resolv.conf
nameserver 114.114.114.114
nameserver 8.8.8.8
1
2
3
vi/etc/resolv.conf
nameserver114.114.114.114
nameserver8.8.8.8
修改完成后,我们再执行安装Redis命令的话,一般就不会出现问题了,祝你好运哈。
我在整个过程中还是遇到了很多坑,在报错之后我认为是脚本的问题,其实安装Redis并且在下载的它的时候会出现一个Redis的URL链接,我还特意把这个链接复制到本地PC上下载测试却是正常,这就能证明并不是被墙的原因。
由于我对Linux的了解并不多,所以几番尝试之后没有搞定,就重装了,但坑并没有结束,比如如下报错。
--2020-05-05 02:31:02-- (try: 9) http://175.6.32.4:88/soft/lib/openssl/openssl-1.1.1d.tar.gz
Connecting to 175.6.32.4:88... failed: Connection timed out.
Retrying.
1
2
3
--2020-05-0502:31:02--(try:9)http://175.6.32.4:88/soft/lib/openssl/openssl-1.1.1d.tar.gz
Connectingto175.6.32.4:88...failed:Connectiontimedout.
Retrying.
skying查找资料更换下载地址可以解决,但是还是302跳转到上面那个IP上,最后便安装了LNMP1.6的完整版,当时看了看时间,好像去年还是前年就是在五一前后出的问题,好吧,具体命令如下。
wget https://upyun.vpser.net/lnmp/lnmp1.6-full.tar.gz-cO lnmp1.6-full.tar.gz && tar zxf lnmp1.6-full.tar.gz && cd lnmp1.6-full && ./install.sh lnmp
1
wgethttps://upyun.vpser.net/lnmp/lnmp1.6-full.tar.gz-cO lnmp1.6-full.tar.gz && tar zxf lnmp1.6-full.tar.gz && cd lnmp1.6-full && ./install.sh lnmp