- Installing Java 8 =========
Checking available Java versions
yum search java | grep jdk
Select Java 8 from the available options.
Installing Java 8
yum install java-1.8.0-openjdk java-1.8.0-openjdk-devel
After installation, note the complete Java 8 version name displayed in the output, as it will be needed for environment variable configuration.
Locating Java 8 intsallation path
Java installed via this method is located in /usr/lib/jvm
Configure environment variables by editing /etc/profile
Add the following content to the end of the file (replace the JDK version with the one you noted earlier):
#set java environment
JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.252.b09-2.el7_8.x86_64
JRE_HOME=$JAVA_HOME/jre
CLASS_PATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib
PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
export JAVA_HOME JRE_HOME CLASS_PATH PATH
Apply the configuration changes
source /etc/profile
Verify Java installation
java -version
- Installing MySQL 5.7 =============
Part 1: Install YUM Repository
1. Since CentOS's yum repository doesn't include MySQL, we need to download the yum repo configuration file from MySQL's official website:
wget https://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
2. Install the repository:
rpm -ivh mysql57-community-release-el7-9.noarch.rpm
After execution, two repo files will be created in /etc/yum.repos.d/: mysql-community.repo and mysql-community-source.repo
Part 2: Installation using yum
Note: Ensure you are in the /etc/yum.repos.d/ directory before executing the following commands
1. Installation command:
yum install mysql-server
2. Start MySQL:
systemctl start mysqld # Start MySQL
Check MySQL status with:
systemctl status mysqld.service
3. Retrieve the temporary password generated during installation (required for first login):
MySQL is now running, but to log in as root, we need to find the temporary password in the log file:
grep "password" /var/log/mysqld.log
Part 3: Login and Initial Setup
mysql -uroot -p
You must change the password before performing any operations:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'new password';
Replace 'new password' with your desired password. Note: The password must include uppercase letters, lowercase letters, numbers, and special characters (e.g., ,/';:) to be accepted.
If you encounter the following error:
Part 6: Enable Remote Access
For security reasons, MySQL only allows local connections by default. To enable remote connections:
Method 1
1.1. Connect to the server: mysql -u root -p
1.2. List all databases: show databases;
1.3. Access the mysql database: use mysql;
1.4. Display all tables in the mysql database: show tables;
1.5. View user table data: select Host, User from user;
1.6. Modify the Host in the user table: update user set Host='%' where User='root';
Note: % represents any client, or you can specify a particular IP address.
1.7. Apply changes: flush privileges;
1.8. Remember to add ";" at the end of each SQL statement.
Method 2
1. Using the grant command
grant all privileges on database_name.table_name to 'username'@'%' identified by 'password';
Format: database_name.table_name Using . grants all databases flush privileges; # Apply changes
Example:
GRANT ALL PRIVILEGES ON . TO 'root'@'%' IDENTIFIED BY 'yourpassword' WITH GRANT OPTION;
The value after @ is the client IP address (or hostname) that can access MySQL. % represents any client. If you specify localhost, the user can only access locally.
Reload privileges: flush privileges;
If you still cannot connect, the configuration file may need modification:
1. Edit MySQL configuration file
vim /etc/my.cnf
2. Add the following line under [mysqld]
bind-address=0.0.0.0 // or your specific IP
3. Restart MySQL service
service mysqld restart
Default directories for MySQL installed via yum (RPM package) on CentOS:
| Directory | Contents |
|---|---|
| /usr/bin | Client programs and scripts |
| /usr/sbin | mysqld server |
| /var/lib/mysql | Log files, database files |
| /usr/share/mysql | Error messages and character set files |
| /etc/my.cnf | Configuration file |
- Installing Nginx =========
Prerequisites
Nginx is developed in C and is best run on Linux. This guide uses CentOS 7 as the installation environment.
1. Install gccNginx requires compiling source code downloaded from the official website, which depends on the gcc environment. If not installed, use:
yum install gcc-c++
2. Install PCRE pcre-develPCRE (Perl Compatible Regular Expressions) is a Perl library including perl-compatible regex libraries. Nginx's http module uses pcre to parse regular expressions, so pcre library must be installed on Linux. pcre-devel is a development library for pcre. Nginx also requires this library:
yum install -y pcre pcre-devel
3. Install zlibThe zlib library provides various compression and decompression methods. Nginx uses zlib to gzip http content, so zlib library must be installed on CentOS.
yum install -y zlib zlib-devel
4. Install OpenSSLOpenSSL is a robust SSL cryptographic library that includes major cryptographic algorithms, key and certificate management functions, and SSL protocol. Nginx supports not only http but also https (http over ssl), so OpenSSL library must be installed on CentOS.
yum install -y openssl openssl-devel
All dependencies can be instlaled at once with:
yum -y install make zlib-devel gcc-c++ pcre pcre-devel libtool openssl openssl-devel
Download from official website
- Download the .tar.gz package directly from: https://nginx.org/en/download.html
- Use wget to download (recommended). Ensure wget is installed with yum install wget if needed:
wget -c https://nginx.org/download/nginx-1.20.1.tar.gz
Extract
Use the following commands:
tar -zxvf nginx-1.20.1.tar.gz
cd nginx-1.20.1
Configure
In nginx versions 1.12.0 and later, default configuration is usually sufficient. However, you can customize the configuration directory if needed.
- Use default configuration
./configure
- Custom configuration (not recommended)
./configure \
--prefix=/usr/local/nginx \
--conf-path=/usr/local/nginx/conf/nginx.conf \
--pid-path=/usr/local/nginx/conf/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--with-http_gzip_static_module \
--http-client-body-temp-path=/var/temp/nginx/client \
--http-proxy-temp-path=/var/temp/nginx/proxy \
--http-fastcgi-temp-path=/var/temp/nginx/fastcgi \
--http-uwsgi-temp-path=/var/temp/nginx/uwsgi \
--http-scgi-temp-path=/var/temp/nginx/scgi
Note: If specifying /var/temp/nginx for temporary files, create the temp and nginx directories under /var
Compile and Install
make && make install
Find the installation path with:
Start, Stop, and Restart Nginx
cd /usr/local/nginx/sbin/
./nginx
./nginx -s stop
./nginx -s quit
./nginx -s reload
./nginx -s quit: This method stops Nginx after it has finished processing current requests. ./nginx -s stop: This is equivalent to finding the Nginx process ID and using kill to terminate it forcefully.
For SSL configuration, refer to: https://www.cnblogs.com/ambition26/p/14077773.html
Start on Boot
Add startup commands to rc.local:
vi /etc/rc.local
Add the line /usr/local/nginx/sbin/nginxSet execute permissions:
chmod 755 rc.local
Nginx installation is now complete. Start, stop, and restart operations are all working. You can also configure it as a system service if needed.
- Installing Redis =========
Part 1: Install gcc dependency
Redis is developed in C, so gcc must be installed first (check with gcc -v). If not installed, use:
yum install -y gcc
Part 2: Download and extract the package
wget http://download.redis.io/releases/redis-3.2.13.tar.gz
tar -zxvf redis-3.2.13.tar.gz
Part 3: Compile in the extracted directory
cd redis-3.2.13
make
Part 4: Install with custom directory
make install PREFIX=/usr/local/redis
Part 5: Start the service
5.1 Foreground start
cd /usr/local/redis/bin/
./redis-server
5.2 Background start
Copy redis.conf from the source directory to the installation directory
cp /root/redis-3.2.13/redis.conf /usr/local/redis/bin/
Modify redis.conf to allow external access and set password
Change daemonize no to daemonize yes
vi /usr/local/redis/bin/redis.conf
Find and modify these parameters:
- bind 127.0.0.1 (IP allowed to connect)
- daemonize no (daemon mode)
- protected-mode yes (protected mode on)
- #requirepass yourpassword (authentication password)
The first two parameters are particularly important. The fourth parameter sets a password for additional security.
Modify as follows:
- #bind 127.0.0.1
- daemonize yes
- protected-mode no
- requirepass yourpassword
daemonize:yes: Redis uses a single-process, multi-threaded model. When daemonize is set to yes in redis.conf, Redis runs in the background and writes the process ID to the file specified by pidfile. Redis will continue running until manually terminated. daemonize:no: When daemonize is set to no, the current interface enters Redis's command line interface. Exiting or closing the connection tool (putty, xshell, etc.) will cause the Redis process to exit.
Check if Redis is running: ps -ef|grep redis
Start Redis in background mode
./redis-server redis.conf
Part 6: Configure startup on boot
Add a startup service
vi /etc/systemd/system/redis.service
Copy and paste the following content:
[Unit]
Description=redis-server
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/bin/redis.conf
PrivateTmp=true
[Install]
WantedBy=multi-user.target
Note: Update ExecStart with your actual path
Enable startup on boot
systemctl daemon-reload
systemctl start redis.service
systemctl enable redis.service
Create a symbolic link for the redis command
ln -s /usr/local/redis/bin/redis-cli /usr/bin/redis
Service management commands
systemctl start redis.service # Start Redis service
systemctl stop redis.service # Stop Redis service
systemctl restart redis.service # Restart service
systemctl status redis.service # Check current service status
systemctl enable redis.service # Enable auto-start on boot
systemctl disable redis.service # Disable auto-start on boot
Reference: