歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> 安裝Redis報錯:undefined reference to `__sync_add_and_fetch_4

安裝Redis報錯:undefined reference to `__sync_add_and_fetch_4

日期:2017/2/28 14:31:48   编辑:Linux教程

在VMware的Linux系統上安裝Redis

具體過程如下:

下載,解壓和編譯:

$ wget http://redis.googlecode.com/files/redis-2.6.14.tar.gz
$ tar xzf redis-2.6.14.tar.gz
$ cd redis-2.6.14
$ make

在執行make的時候報錯,具體報錯信息如下:

zmalloc.o: In function `zmalloc_used_memory':
/usr/local/redis-2.6.14/src/zmalloc.c:223: undefined reference to `__sync_add_and_fetch_4'
collect2: ld returned 1 exit status
make[1]: *** [redis-server] Error 1
make[1]: Leaving directory `/usr/local/redis-2.6.14/src'
make: *** [all] Error 2

網上查了下資料,主要是因為我的linux是32位的,所以會報這個錯,解決方案如下:

在make操作的時候加一個執行參數:make CFLAGS="-march=i686"

然後就不報錯了。

附:啟動並運行Redis

編譯的可執行文件在src目錄中,使用以下命令運行Redis:

[root@localhost redis-2.6.14]# src/redis-server

啟動成功後控制台打印如下信息:

[2918] 03 Jul 09:05:01.011 # Warning: no config file specified, using the default config. In order to specify a config file use src/redis-server /path/to/redis.conf
[2918] 03 Jul 09:05:01.017 * Max number of open files set to 10032
[2918] 03 Jul 09:05:01.024 # Warning: 32 bit instance detected but no memory limit set. Setting 3 GB maxmemory limit with 'noeviction' policy now.
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 2.6.14 (00000000/0) 32 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in stand alone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 2918
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'

[2918] 03 Jul 09:05:01.029 # Server started, Redis version 2.6.14
[2918] 03 Jul 09:05:01.030 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
[2918] 03 Jul 09:05:01.030 * The server is now ready to accept connections on port 6379

附2:把Redis作為Linux服務開機啟動

這裡只提供一種最簡單的方式,最好的是通過編寫開機啟動腳本來做。

如果要開機啟動redis,我們需要把redis設置為daemon後台啟動(如果不設置為後台啟動,則linux啟動後圖形界面會卡在一個空白的頁面),而redis只有1個啟動參數,就是redis的配置文件路徑。redis的默認配置文件redis.conf位於redis的安裝目錄下。我們可以把該文件copy到/etc目錄下

[root@localhost redis-2.6.14]# cp redis.conf /etc/

redis的默認配置文件中daemonize參數的值為no,代表為非後台啟動,所以我們需要把該參數的值修改為yes。至於其它的參數在這裡就不詳細說了,具體可以參見:http://www.linuxidc.com/Linux/2013-11/92524.htm

修改完daemonize參數之後,redis就能夠通過daemon方式啟動了,那麼下一步就是把redis加入到linux開機啟動服務配置中了,具體步驟如下:

使用VI編輯器打開Linux開機啟動服務配置文件/etc/rc.local,並在其中加入下面的一行代碼:

/usr/local/redis-2.6.14/src/redis-server /etc/redis.conf

編輯完後保存,然後重啟系統就OK了。

停止Redis服務:

src/redis-cli shutdown

Ubuntu 14.04下Redis安裝及簡單測試 http://www.linuxidc.com/Linux/2014-05/101544.htm

Redis集群明細文檔 http://www.linuxidc.com/Linux/2013-09/90118.htm

Ubuntu 12.10下安裝Redis(圖文詳解)+ Jedis連接Redis http://www.linuxidc.com/Linux/2013-06/85816.htm

Redis系列-安裝部署維護篇 http://www.linuxidc.com/Linux/2012-12/75627.htm

CentOS 6.3安裝Redis http://www.linuxidc.com/Linux/2012-12/75314.htm

Redis配置文件redis.conf 詳解 http://www.linuxidc.com/Linux/2013-11/92524.htm

Redis 的詳細介紹:請點這裡
Redis 的下載地址:請點這裡

Copyright © Linux教程網 All Rights Reserved