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 bzip2cd /usr/local/src && tar -zxf gcc-11.2.0.tar.gz > /dev/nullcd gcc-11.2.0 && ./contrib/download_prerequisites && mkdir -p build && cd build && ../configure -enable-checking=release -enable-languages=c,c++ -disable-multilibmake && make installgcc -vThe 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/nullcd redis-6.2.6 && make && make install PREFIX=/usr/local/redismkdir -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_configsed -ri '/^bind/s/127.0.0.1/0.0.0.0/' $redis_configsed -ri '/^dir/s/\.\//\/usr\/\/local\/redis\/data/' $redis_configsed -ri '/^protected-mode/s/yes/no/' $redis_configsed -ri '/^logfile/s/""/"\/usr\/\/local\/redis\/log\/redis.log"/' $redis_configIt 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 <<EOF[Unit]After=network.target[Service]ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/bin/redis.conf --supervised systemdExecStop=/bin/kill -s QUIT $MAINPIDType=notifyUser=redisGroup=redisRuntimeDirectory=redisRuntimeDirectoryMode=0755[Install]WantedBy=multi-user.targetEOFFinally, it reloads the systemd daemon, starts the Redis service, and invokes the two installation functions:
systemctl daemon-reloadsystemctl start redis.servicegcc_installredis_installSigned-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
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.
