In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "how to install Redis and run with non-root users under CentOS7". In the daily operation, I believe that many people have doubts about how to install Redis and run it with non-root users under CentOS7. Xiaobian consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the questions of "how to install Redis and run with non-root users under CentOS7". Next, please follow the editor to study!
1. Basic environment information 1.1, environment information serial number ID version 1 operating system CentOS72redis5.0.12
1.2. download address of redis
Download address of redis:
What we use here is 5.0.12.
2. Install 2.1and create a new redis ordinary user
1. Log in to our system using root
2), new group: groupadd redisgroup
3). New user: useradd-g redisgroup redis
4) set the password: passwd redis can enter the password itself.
Groupadd redisgroupuseradd-g redisgroup redispasswd redis
2.2. Upload the installation package and decompress it
1) use root users to create a new directory: mkdir-p / usr/local/src/redis
2) decompress the package: tar-zxvf redis-5.0.12.tar.gz
As follows:
Mkdir-p / usr/local/src/redistar-zxvf redis-5.0.12.tar.gz
2.3. Create a new directory
Switch to the redis user and create a new folder under the user directory: redis
Mkdir rediscd redismkdir datamkdir etc2.4, compile and install
Use root user actions
1), compile: cd redis-5.0.12
Make
2), install:
Make install PREFIX=/home/redis/redis
3. Configure 3.1. copy the configuration file to the redis user.
1) copy the redis.conf file under / usr/local/src/redis/redis-5.0.12 to the / home/redis/redis/etc directory
2), if it cannot be copied, use root to grant permission, chmod 777 redis.conf
3) after copying, change the group and user to which the file belongs
Chown redis redis.confchgrp redisgroup redis.conf3.2, configuration file for configuring Redis
To modify the configuration file, we mainly modify three areas:
1), modify it to run in the background
2), modify and support other machine connections
The following three keys can be modified directly in the configuration file
# yes- background mode runs, no- foreground mode runs. The default daemonize yes# is commented out here. By default, the value below # bind 127.0.0.is changed to no, default is yesprotected-mode no4, write startup script, start 4.1and write management script.
1) Log in with the redis user, and we create a new directory bin under the user directory
2) create a new redctl script under the bin directory and grant executable permissions, chmod aquix redisctl
3) add the ~ / bin directory to the user's environment variable
Modify the. bash_profile file in the user directory and add it on the penultimate line
PATH=$PATH:~/bin
The complete content is as follows:
# .bash _ profile# Get the aliases and functionsif [- f ~ / .bashrc]; then. ~ / .bashrcfi # User specific environment and startup programsPATH=$PATH:$HOME/.local/bin:$HOME/binPATH=$PATH:~/binexport PATH
Write a redctl script that supports redis start, stop, restart and status check. The details are as follows:
Redctl
#! / bin/bash#check paramif [$#-lt 1]; thenecho "USAGE: redctl start | stop | restart | status" exit 8fipid=0ACTION=$1REDIS_HOME=$HOME/redis# Here define some functiongetpid () {pid= `ps-ef | grep redis-server | grep-v grep | awk'{print $2}'} start () {getpidif [!-n "$pid"]; thencd $REDIS_HOME/bin. / redis-server.. / etc/redis.conf getpidif [!-n "$pid"] Thenecho "redis-server start failed, please check your commond" elseecho "redis-server start success, PID: $pid" fielseecho "redis-server is running PID: $pid" fi} stop () {getpidif [!-n "$pid"]; thenecho "redis-server is not running" elsekill-9$ pidecho "redis-server has been stopped" fi} restart () {stopsleep 1s start} status () {getpidif [!-n "$pid"]; thenecho "redis-server is not running" elseecho "redis-server is running PID: $pid" fi} case $ACTION instart) start ; stop) stop;;restart) restart;;status) status;;*) echo "require start | stop | restart | status";; esac4.2, start the service and verify
Execute, start, check status, restart, stop, and the commands are as follows:
Redctl start
Redctl status
Redctl restart
Redctl stop
Let's execute the start command again to start the redis service
Using the redis-cli connection, try to set some values and view the values you set, as follows:
Indicates success
5. Problems that may be encountered 5.1. No gcc gaming + package installed
If you do not have the gcc gaming + package installed, please install it yourself.
At this point, the study on "how to install and run Redis with non-root users under CentOS7" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.