Bash Script for Installing GCC 11.2.0 and Redis 6.2.6 with a Systemd Service
This Bash script automates the installation of GCC 11.2.0 and Redis 6.2.6 on a Linux system, configures Redis settings, creates a systemd service unit, and starts the Redis service, providing a reproducible setup procedure for developers and system administrators.
This script automates the installation of GCC 11.2.0 and Redis 6.2.6 on a Linux host.
It first defines the Redis configuration file location:
redis_config=/usr/local/redis/bin/redis.conf
The gcc_install() function installs required dependencies, extracts the GCC source, configures it for C and C++ languages, builds and installs it, and finally checks the installed version:
yum -y install bzip2
cd /usr/local/src && tar -zxf gcc-11.2.0.tar.gz > /dev/null
cd gcc-11.2.0 && ./contrib/download_prerequisites && mkdir -p build && cd build && ../configure -enable-checking=release -enable-languages=c,c++ -disable-multilib
make && make install
gcc -v
The redis_install() function extracts the Redis source, builds and installs it under /usr/local/redis , creates necessary directories, copies the default configuration and server binary, and adjusts the configuration using sed to disable daemonization, bind to all interfaces, set the data directory, disable protected mode, and specify the log file:
cd /usr/local/src && tar -zxf redis-6.2.6.tar.gz > /dev/null
cd redis-6.2.6 && make && make install PREFIX=/usr/local/redis
mkdir -p /usr/local/redis/{bin,run,log,data}
yes| cp -r /usr/local/src/redis-6.2.6/redis.conf /usr/local/redis/bin/
yes| cp -r /usr/local/src/redis-6.2.6/redis-server /usr/local/redis/bin/
sed -ri '/^daemonize/s/yes/no/' $redis_config
sed -ri '/^bind/s/127.0.0.1/0.0.0.0/' $redis_config
sed -ri '/^dir/s/\.\//\/usr\/\/local\/redis\/data/' $redis_config
sed -ri '/^protected-mode/s/yes/no/' $redis_config
sed -ri '/^logfile/s/""/"\/usr\/\/local\/redis\/log\/redis.log"/' $redis_config
It then creates a systemd unit file /lib/systemd/system/redis.service with the necessary Unit, Service, and Install sections:
cat > /lib/systemd/system/redis.service <
[Unit]
After=network.target
[Service]
ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/bin/redis.conf --supervised systemd
ExecStop=/bin/kill -s QUIT $MAINPID
Type=notify
User=redis
Group=redis
RuntimeDirectory=redis
RuntimeDirectoryMode=0755
[Install]
WantedBy=multi-user.target
EOF
Finally, it reloads the systemd daemon, starts the Redis service, and invokes the two installation functions:
systemctl daemon-reload
systemctl start redis.service
gcc_install
redis_install
Practical DevOps Architecture
Hands‑on DevOps operations using Docker, K8s, Jenkins, and Ansible—empowering ops professionals to grow together through sharing, discussion, knowledge consolidation, and continuous improvement.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.