How do I compile Redis so that I can upload and run it on shared hosting?
In my opinion the safest bet would be to statically compile redis.
I just did something similar for a CentOS 5 server. To be 100% sure I created a minimal CentOS 5 VM on my workstation, then I followed these steps (everything has been done on the CentOS 5 VM)
download redis and tcl 8.5
wget http://download.redis.io/releases/redis-3.0.2.tar.gz
wget http://prdownloads.sourceforge.net/tcl/tcl8.5.18-src.tar.gzinstall tcl 8.5
tar xfz tcl8.5.18-src.tar.gz
cd tcl8.5.18/unix
./configure
make
make test
make installcompile redis
make CFLAGS="-static" EXEEXT="-static" LDFLAGS="-I/usr/local/include/"
test redis
cd src
./redis-server- copy the resulting binaries on the target server. The binaries can be found under the
src
folder.
Running a compiled C program on a shared hosting account?
Yes it would work in most cases, as long as you can match system libraries / link statically.
Anyway, you will get banned eventually :-)
PS. Try VPS, it's cheap and have no such embarassing restrictions.
Redis - Connect to Remote Server
First I'd check to verify it is listening on the IPs you expect it to be:
netstat -nlpt | grep 6379
Depending on how you start/stop you may not have actually restarted the instance when you thought you had. The netstat will tell you if it is listening where you think it is. If not, restart it and be sure it restarts.
If it restarts and still is not listening where you expect, check your config file just to be sure.
After establishing it is listening where you expect it to, from a remote node which should have access try:
redis-cli -h REMOTE.HOST ping
You could also try that from the local host but use the IP you expect it to be listening on instead of a hostname or localhost. You should see it PONG in response in both cases.
If not, your firewall(s) is/are blocking you. This would be either the local IPTables or possibly a firewall in between the nodes. You could add a logging statement to your IPtables configuration to log connections over 6379 to see what is happening. Also, trying he redis ping from local and non-local to the same IP should be illustrative. If it responds locally but not remotely, I'd lean toward an intervening firewall depending on the complexity of your on-node IP Tables rules.
Could not connect to Redis at 127.0.0.1:6379: Connection refused with homebrew
After installing redis
, type from terminal
:
redis-server
And Redis-Server will be started
Docker Redis - Seeding Data - Cannot execute redis-cli via Dockerfile or via shell script
RUN cat /test_dir/seed.txt | redis-cli -a <password> --pipe
will execute when you do docker build
, at that time ENTRYPOINT ["redis-server", "/test_dir/redis.conf"]
still not run as it's only be called when the container start. So, you will surely have error.
As a result, you could use next workaround to do it:
/test_dir/seed.txt:
/test_dir/init.sh:
while :
do
redis-cli -h redis-svr -p 6379 quit
if [ $? -eq 0 ]; then
cat /test_dir/seed.txt | redis-cli -h redis-svr -p 6379 --pipe
break
else
echo "server not ready, wait then retry..."
sleep 3
fi
done
docker-compose.yaml:
version: '3'
services:
redis-svr:
image: redis
redis-cli:
image: redis
volumes:
- /test_dir:/test_dir
entrypoint: sh -c /test_dir/init.sh
Execution:
$ docker-compose up
WARNING: Found orphan containers (20210910_redis_1) for this project. If you removed or renamed this service in your compose file, you can run this command with the --remove-orphans flag to clean it up.
Starting 20210910_redis-svr_1 ... done
Starting 20210910_redis-cli_1 ... done
Attaching to 20210910_redis-cli_1, 20210910_redis-svr_1
redis-cli_1 | Could not connect to Redis at redis-svr:6379: Connection refused
redis-cli_1 | server not ready, wait then retry...
redis-svr_1 | 1:C 11 Sep 2021 05:55:33.872 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
redis-svr_1 | 1:C 11 Sep 2021 05:55:33.872 # Redis version=6.2.5, bits=64, commit=00000000, modified=0, pid=1, just started
redis-svr_1 | 1:C 11 Sep 2021 05:55:33.872 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
redis-svr_1 | 1:M 11 Sep 2021 05:55:33.873 * monotonic clock: POSIX clock_gettime
redis-svr_1 | 1:M 11 Sep 2021 05:55:33.879 * Running mode=standalone, port=6379.
redis-svr_1 | 1:M 11 Sep 2021 05:55:33.879 # Server initialized
redis-svr_1 | 1:M 11 Sep 2021 05:55:33.890 * Loading RDB produced by version 6.2.5
redis-svr_1 | 1:M 11 Sep 2021 05:55:33.890 * RDB age 266 seconds
redis-svr_1 | 1:M 11 Sep 2021 05:55:33.890 * RDB memory usage when created 0.77 Mb
redis-svr_1 | 1:M 11 Sep 2021 05:55:33.890 * DB loaded from disk: 0.010 seconds
redis-svr_1 | 1:M 11 Sep 2021 05:55:33.890 * Ready to accept connections
redis-cli_1 | OK
redis-cli_1 | All data transferred. Waiting for the last reply...
redis-cli_1 | Last reply received from server.
redis-cli_1 | errors: 0, replies: 0
20210910_redis-cli_1 exited with code 0
Explain:
redis-svr
will start a server there in one container, redis-cli
will start another container, it will frist call init.sh
, the init.sh
will try to link to redis server to see if server really start or not with redis-cli -h redis-svr -p 6379 quit
. If not, it will wait sometime and retry, if server already start, then it could call the client command to import the initial data to server.
EDIT20210912 based on OP's comment to use one container:
Folder structure:
$ tree
.
├── docker-compose.yaml
├── Dockerfile
├── init.sh
├── my-entrypoint.sh
└── seed.txt
docker-compose.yaml:
version: '3'
services:
redis-svr:
build: ./
Dockerfile:
FROM redis:6.2.5
COPY . /tmp
RUN chmod -R 777 /tmp
ENTRYPOINT ["/tmp/my-entrypoint.sh"]
CMD ["redis-server"]
init.sh:
while :
do
redis-cli quit
if [ $? -eq 0 ]; then
echo "Server ready now, start to import data ..."
cat ./seed.txt | redis-cli --pipe
break
else
echo "Server not ready, wait then retry..."
sleep 3
fi
done
my-entrypoint.sh:
#!/bin/sh
/tmp/init.sh &
docker-entrypoint.sh $1
Execution:
$ docker-compose up
Recreating test_dir_redis-svr_1 ... done
Attaching to test_dir_redis-svr_1
redis-svr_1 | Could not connect to Redis at 127.0.0.1:6379: Connection refused
redis-svr_1 | Server not ready, wait then retry...
redis-svr_1 | 7:C 12 Sep 2021 08:36:05.512 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
redis-svr_1 | 7:C 12 Sep 2021 08:36:05.512 # Redis version=6.2.5, bits=64, commit=00000000, modified=0, pid=7, just started
redis-svr_1 | 7:C 12 Sep 2021 08:36:05.512 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
redis-svr_1 | 7:M 12 Sep 2021 08:36:05.513 * monotonic clock: POSIX clock_gettime
redis-svr_1 | 7:M 12 Sep 2021 08:36:05.515 * Running mode=standalone, port=6379.
redis-svr_1 | 7:M 12 Sep 2021 08:36:05.515 # Server initialized
redis-svr_1 | 7:M 12 Sep 2021 08:36:05.515 * Ready to accept connections
redis-svr_1 | OK
redis-svr_1 | Server ready now, start to import data ...
redis-svr_1 | All data transferred. Waiting for the last reply...
redis-svr_1 | Last reply received from server.
redis-svr_1 | errors: 0, replies: 0
This define customized entrypoint to let init.sh
have chance to be executed before redis server run.
Related Topics
How Event Packet Header Is Getiing in Hci_Send_Req API Implementation
Starting Multiple Firefox Profiles with Batch File in Linux
Building Robert Nelson's Linux Kernel into Yocto(Daisy) for Beaglebone Black
Understanding The Netstat Output
Touch Command Create Multiple Files (Different Names) Under One Directory
How to Generic .Htaccess to Prevent Hotlink
Releasing All Keys After Disabling The Keyboard in X11/Linux Using Xinput
Linux Usb Driver Probe Not Called If Device Already Plugged
Polling a Loop Device Through a Kernel Module
Partitioning Images Based on Their White Space
Count Number of Column in a Pipe Delimited File
Kate Text Editor Cannot Handle Lines Longer Than 1024
How to Type "Cargo Run" Without Needing to Set The Ld_Library_Path Shell Variable
Shared Library Symbol Conflicts and Static Linking (On Linux)
Finding Directories with Find in Bash Using a Exclude List