1,安装redis 5需要 先安装tcl yum install -y tcl tcl-devel
2, wget http://download.redis.io/releases/redis-5.0.7.tar.gz
3, tar -zxvf redis-5.0.7.tar.gz ;cd redis-5.0.7/ ;make;make test;make install PREFIX=/webdata/opt/local/redis
4,useradd redis -s /sbin/nologin -M
5,mkdir -p /webdata/opt/local/redis/{db,etc,log}
6,chown -R redis:redis /webdata/opt/local/redis
7,解决redis报警,增加
vm.overcommit_memory = 1
net.core.somaxconn = 2048
到/etc/sysctl.conf 然后sysctl -p
8,增加
root soft nofile 65535
root hard nofile 65535
* soft nofile 65535
* hard nofile 65535
/etc/security/limits.conf 中,解决 openfile 报警问题
9,执行下面命令解决大页报警问题
echo never > /sys/kernel/mm/transparent_hugepage/enabled
10,下载
redis.conf 文件放到 /webdata/opt/local/redis/etc 下面(可以根据具体情况修改配置文件)
redis-shutdown 文件放到 /webdata/opt/local/redis/bin 下面
redis.service 文件放到 /usr/lib/systemd/system 下面
11, systemctl enable redis.service ;systemctl start redis.service
注意,上面redis.service 启动脚本在redis 6.X中是启动不了的,一直hang在启动界面,使用如下方式编译,已经证明是正常的:
1,yum install -y systemd-devel jemalloc-devel
2,make USE_SYSTEMD=yes MALLOC=jemalloc ;make install PREFIX=/usr/local/redis
PS,再redis 6.X版本中此脚本启动一直hang在前台【原因是使用不能通知libsystem-dev, 去掉type=notify 可以启动】,打开另外一个shell进程,通过systemctl status redis.service 查看服务,显示服务已经起来,但是灰色的,正常应该是绿色的。
导致这个问题是因为,下面是一个问题链接:
I have followed this answer: https://serverfault.com/a/893075/210494. I have CentOS 7.8.
redis.service
[Service] Type=notify ExecStart=/opt/redis/bin/redis-server /opt/redis/conf/redis-master.conf TimeoutStartSec=60 TimeoutStopSec=60 TimeOutSec=90 RestartSec=5s Restart=on-success
redis-master.conf
daemonize no supervised systemd
When I run this service, the Redis process starts but the systemctl hangs and I have to press Ctrl-C to get back to shell.
This is in the logs:
69486:C 28 Aug 2020 17:31:14.545 # Redis version=6.0.6, bits=64, commit=00000000, modified=0, pid=69486, just started 69486:C 28 Aug 2020 17:31:14.545 # Configuration loaded 69486:C 28 Aug 2020 17:31:14.545 # WARNING supervised by systemd - you MUST set appropriate values for TimeoutStartSec and TimeoutStopSec in your service unit. 69486:M 28 Aug 2020 17:31:14.546 * Increased maximum number of open files to 4096 (it was originally set to 1024). 69486:M 28 Aug 2020 17:31:14.547 * Running mode=standalone, port=6380. 69486:M 28 Aug 2020 17:31:14.547 # Server initialized
If I comment out Type=notify, then systemctl finishes immediatelly but this is in the logs.
68629:C 28 Aug 2020 17:29:58.933 # Redis version=6.0.6, bits=64, commit=00000000, modified=0, pid=68629, just started 68629:C 28 Aug 2020 17:29:58.933 # Configuration loaded 68629:C 28 Aug 2020 17:29:58.933 # WARNING supervised by systemd - you MUST set appropriate values for TimeoutStartSec and TimeoutStopSec in your service unit. 68629:C 28 Aug 2020 17:29:58.933 # systemd supervision requested, but NOTIFY_SOCKET not found 68629:M 28 Aug 2020 17:29:58.933 * Increased maximum number of open files to 4096 (it was originally set to 1024). 68629:M 28 Aug 2020 17:29:58.934 * Running mode=standalone, port=6380. 68629:M 28 Aug 2020 17:29:58.934 # Server initialized
Where is the problem? I found DigitalOcean tutorial where they do not have Type=notify and I found Redis issues when they successfully recommended Type=notify.
Update
Job for redis.service failed because a timeout was exceeded. See "systemctl status redis.service" and "journalctl -xe" for details. [root@DB dev]# systemctl status redis ● redis.service - Redis Loaded: loaded (/etc/systemd/system/redis.service; enabled; vendor preset: disabled) Active: failed (Result: timeout) since Sun 2020-08-30 12:06:58 CEST; 46min ago Process: 11134 ExecStart=/opt/app/redis/default/bin/redis-server /opt/app/redis/default/conf/redis-master.conf (code=exited, status=0/SUCCESS) Main PID: 11134 (code=exited, status=0/SUCCESS) Aug 30 12:05:57 DB systemd[1]: Starting Redis... Aug 30 12:06:58 DB systemd[1]: redis.service start operation timed out. Terminating. Aug 30 12:06:58 DB systemd[1]: Failed to start Redis. Aug 30 12:06:58 DB systemd[1]: Unit redis.service entered failed state. Aug 30 12:06:58 DB systemd[1]: redis.service failed.
这是答案:
Ok, the problem was that systemd support is not compiled by default. You need to compile it explicitelly. I will write a PR to update README.md in sources because this is not explained.
This commit is responsible for this behaviour. I found it in this issue: https://github.com/redis/redis/issues/7217
yum install systemd-devel make BUILD_WITH_SYSTEMD=yes USE_SYSTEMD=yes
下面是有效答案:
Same problem here. Compiled redis, tcl, pkg-config and libsystemd-dev installed. Tests are fine, daemonize no, supervised systemd, no pid file specified. Redis starts, but systemctl doesn't recognize this.
Edit: Set BUILD_WITH_SYSTEMD=no to yes in src/Makefile. Nothing changed...
Edit2: Set export USE_SYSTEMD=yes before use make. Nothing changed. I will write a service which uses screen. I'm realy unhappy with this: Your documentation says "please compile by yourself to get the newest version". Okay, I do want you say... And then the quickstart guide suggest me to use init.d? Guys, which distribution uses init.d nowadays? Please update your documentation if you want, that peoples don't uses outdated redis versions through repos, or support a official PPA.
Edit3: For others googled this: make BUILD_WITH_SYSTEMD=yes USE_SYSTEMD=yes MALLOC=libc is the correct make command. Only use MALLOC=libc if make fails with an error.
hanks. redis-server works now systemd. I use this command
make USE_SYSTEMD=yes MALLOC=jemalloc V=1 PREFIX=/home/s BUILD_TLS=yes install
I am using redis 6.0.5.
This adds Makefile/build-system support for USE_SYSTEMD=(yes|no|*). This variable's value determines whether or not libsystemd will be linked at build-time. If USE_SYSTEMD is set to "yes", make will use PKG_CONFIG to check for libsystemd's presence, and fail the build early if it isn't installed/detected properly. If USE_SYSTEM is set to "no", libsystemd will *not* be linked, even if support for it is available on the system redis is being built on. For any other value that USE_SYSTEM might assume (e.g. "auto"), PKG_CONFIG will try to determine libsystemd's presence, and set up the build process to link against it, if it was indicated as being installed/available. This approach has a number of repercussions of its own, most importantly the following: If you build redis on a system that actually has systemd support, but no libsystemd-dev package(s) installed, you'll end up *without* support for systemd notification/status reporting support in redis-server. This changes established runtime behaviour. I'm not sure if the build system and/or the server binary should indicate this. I'm also wondering if not actually having systemd-notify-support, but requesting it via the server's config, should result in a fatal error now.
PS: memcache 安装和编译
1,下载memcached-1.6.1(目前最新)
wget http://www.memcached.org/files/memcached-1.6.1.tar.gz
2,tar -zxvf memcached-1.5.21.tar.gz ;cd memcached-1.5.21; ./configure --prefix=/webdata/opt/local/memcached --enable-64bit;make;make install
2.1 ,yum install libevent-devel
3,useradd memcached -s /sbin/nologin
4,vim /etc/sysconfig/memcached 加入
PORT="11211"
USER="memcached"
MAXCONN="1024"
CACHESIZE="512"
OPTIONS=""
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!