Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

CentOS 7 Single-Node Deployment: Nginx, MySQL, Nacos, Kafka, Redis, MinIO, kkFileView, and EMQX

Tech 2

Environment Preparation

This guide covers deploying a complete service stack on CentOS 7. The /data/ directory serves as the mounted storage location, with installation packages stored in /data/install-page.

1. Setting Up Local YUM Repository

Creating Mount Point

mkdir -p /mnt/centos

Mounting ISO Image

Upload the CentOS 7 ISO file to /data/install-page, then mount it:

mount -o loop /data/install-page/CentOS-7-x86_64-DVD-2009.iso /mnt/centos

Backing Up Existing YUM Configurasion

cd /etc/yum.repos.d/
mkdir backup
mv *.repo backup/

Creating Local Repository Configuration

vi /etc/yum.repos.d/local.repo
[centos-local]
name=CentOS-7 - Local
baseurl=file:///mnt/centos
gpgcheck=0
enabled=1

Rebuilding YUM Cache

yum clean all
yum makecache

Configuring HTTP Access to YUM Repository

vi /data/nginx/conf.d/yumserver.conf
location /centos {
    alias /mnt/centos/;
    index index.html;
    autoindex on;
}

2. Installing JDK

Creating Installation Directory

mkdir -p /data/install-page
cd /data/install-page

Downloading and Extracting JDK

wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" https://download.oracle.com/java/17/latest/jdk-17_linux-x64_bin.tar.gz
tar zxf jdk-17_linux-x64_bin.tar.gz -C /data/
mv /data/jdk-17.0.2 /data/jdk

Configuring Environment Variables

vi /etc/profile.d/jdk.sh
#!/bin/bash
export JAVA_HOME=/data/jdk
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
source /etc/profile
java -version

3. Installing Nginx

Creating Required Directories

mkdir -p /data/nginx/{logs,temp,web,run,conf.d}
cd /data/install-page

Installing Dependencies

yum -y install pcre pcre-devel openssl openssl-devel zlib-devel gcc gcc-c++ autoconf automake

Creating Nginx User

useradd -r nginx

Downloading and Compiling Nginx

wget http://nginx.org/download/nginx-1.26.1.tar.gz
tar zxf nginx-1.26.1.tar.gz
cd nginx-1.26.1

./configure \
  --prefix=/data/nginx \
  --error-log-path=/data/nginx/logs/error.log \
  --http-log-path=/data/nginx/logs/access.log \
  --pid-path=/data/nginx/run/nginx.pid \
  --lock-path=/data/nginx/run/nginx.lock \
  --http-client-body-temp-path=/data/nginx/temp/client_temp \
  --http-proxy-temp-path=/data/nginx/temp/proxy_temp \
  --http-fastcgi-temp-path=/data/nginx/temp/fastcgi_temp \
  --http-uwsgi-temp-path=/data/nginx/temp/uwsgi_temp \
  --http-scgi-temp-path=/data/nginx/temp/scgi_temp \
  --user=nginx \
  --group=nginx \
  --with-http_ssl_module \
  --with-http_v2_module \
  --with-http_realip_module \
  --with-stream

make && make install

Creating Systemd Service

vi /lib/systemd/system/nginx.service
[Unit]
Description=The nginx HTTP Server
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
ExecStart=/data/nginx/sbin/nginx
ExecReload=/data/nginx/sbin/nginx -s reload
ExecStop=/data/nginx/sbin/nginx -s stop

[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl enable --now nginx

Configuring Nginx

vi /data/nginx/conf/nginx.conf
user nginx;
worker_processes auto;
error_log /data/nginx/logs/error.log warn;
pid /data/nginx/run/nginx.pid;

events {
    worker_connections 2048;
}

http {
    include /data/nginx/conf/mime.types;
    default_type application/octet-stream;
    
    log_format main '$remote_addr - $remote_user [$time_local] "$request" '
                     '$status $body_bytes_sent "$http_referer" '
                     '"$http_user_agent" "$http_x_forwarded_for"';
    
    access_log /data/nginx/logs/access.log main;
    
    sendfile on;
    tcp_nodelay on;
    keepalive_timeout 65;
    client_max_body_size 500m;
    
    gzip on;
    gzip_min_length 1k;
    gzip_comp_level 6;
    gzip_types text/plain text/css text/xml application/json application/javascript application/xml;
    
    include /data/nginx/conf.d/*.conf;
}

4. Installing Nacos

Extracting Nacos

cd /data/install-page
tar zxf nacos-server-2.3.2.tar.gz -C /data
mv /data/nacos/nacos /data/nacos-server
cd /data/nacos-server

Configuring Database Connection

vi /data/nacos-server/conf/application.properties
spring.datasource.platform=mysql
db.num=1
db.url.0=jdbc:mysql://localhost:3306/nacos_config?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true
db.user=root
db.password=MySecurePass123!

Initializing Database

mysql -uroot -pMySecurePass123! <<EOF
CREATE DATABASE nacos_config;
EOF

mysql -uroot -pMySecurePass123! nacos_config < /data/nacos-server/conf/nacos-mysql.sql

Creating Systemd Service

vi /lib/systemd/system/nacos.service
[Unit]
Description=Nacos Server
After=network.target mysql.service

[Service]
Type=forking
ExecStart=/data/nacos-server/bin/startup.sh -m standalone
ExecStop=/data/nacos-server/bin/shutdown.sh
Restart=on-failure

[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl enable --now nacos

5. Installing Kafka and Zookeeper

Setting Up Kafka

cd /data/install-page
tar zxf kafka_2.13-3.7.0.tgz -C /data
mv /data/kafka_2.13-3.7.0 /data/kafka

Configuring Kafka

vi /data/kafka/config/server.properties
broker.id=0
listeners=PLAINTEXT://0.0.0.0:9092
advertised.listeners=PLAINTEXT://192.168.100.10:9092
log.dirs=/data/kafka/logs
zookeeper.connect=localhost:2181

Creating Kafka Service

vi /lib/systemd/system/kafka.service
[Unit]
Description=Apache Kafka
After=zookeeper.service

[Service]
Type=simple
Environment="JAVA_HOME=/data/jdk"
ExecStart=/data/kafka/bin/kafka-server-start.sh /data/kafka/config/server.properties
ExecStop=/data/kafka/bin/kafka-server-stop.sh
Restart=on-failure

[Install]
WantedBy=multi-user.target

Settting Up Zookeeper

vi /data/kafka/config/zookeeper.properties
dataDir=/data/zookeeper
dataLogDir=/data/zookeeper/logs
clientPort=2181
mkdir -p /data/zookeeper/{data,logs}
echo 0 > /data/zookeeper/data/myid

Creating Zookeeper Service

vi /lib/systemd/system/zookeeper.service
[Unit]
Description=ZooKeeper
After=network.target

[Service]
Type=simple
Environment="JAVA_HOME=/data/jdk"
ExecStart=/data/kafka/bin/zookeeper-server-start.sh /data/kafka/config/zookeeper.properties
ExecStop=/data/kafka/bin/zookeeper-server-stop.sh
Restart=on-failure

[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl enable --now zookeeper kafka

6. Installing Redis

Extracting and Building Redis

cd /data/install-page
tar zxf redis-7.4.1.tar.gz -C /data
mv /data/redis-7.4.1 /data/redis
cd /data/redis
make -j$(nproc)

Creating Directories

mkdir -p /data/redis/{data,run,logs}

Configuring Redis

vi /data/redis/redis.conf
bind 0.0.0.0
protected-mode no
port 6380
daemonize yes
pidfile /data/redis/run/redis.pid
logfile "/data/redis/logs/redis.log"
dir /data/redis/data
requirepass RedisSecure#456!
appendonly yes
maxmemory 2gb
maxmemory-policy allkeys-lru

Creating Service

vi /lib/systemd/system/redis.service
[Unit]
Description=Redis In-Memory Data Store
After=network.target

[Service]
ExecStart=/data/redis/src/redis-server /data/redis/redis.conf
ExecStop=/data/redis/src/redis-cli -a RedisSecure#456! shutdown
Restart=always

[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl enable --now redis

7. Installing MySQL

Creating MySQL User and Directories

useradd -r -s /sbin/nologin mysql
mkdir -p /data/mysql/{data,logs,run,binlog}
chown -R mysql:mysql /data/mysql

Extracting MySQL

cd /data/install-page
tar zxf mysql-8.0.38-el7-x86_64.tar.gz -C /data
mv /data/mysql-8.0.38-el7-x86_64 /data/mysql

Installing Dependencies

yum -y install libaio numactl

Configuring MySQL

vi /etc/mysql.conf
[mysql]
default-character-set=utf8mb4

[client]
port=3307
socket=/tmp/mysql.sock

[mysqld]
port=3307
user=mysql
socket=/tmp/mysql.sock
basedir=/data/mysql
datadir=/data/mysql/data
log-bin=/data/mysql/binlog/mysql-bin
innodb_data_home_dir=/data/mysql/data
innodb_log_group_home_dir=/data/mysql/data
log-error=/data/mysql/logs/error.log
pid-file=/data/mysql/run/mysqld.pid
character-set-server=utf8mb4
lower_case_table_names=1
autocommit=1
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ENGINE_SUBSTITUTION
default-time-zone=+08:00

key_buffer_size=256M
max_allowed_packet=32M
table_open_cache=2048
sort_buffer_size=4M
read_buffer_size=2M
read_rnd_buffer_size=8M
myisam_sort_buffer_size=64M
thread_cache_size=64
tmp_table_size=256M
max_connections=3000

default_storage_engine=InnoDB
innodb_buffer_pool_size=2G
innodb_log_file_size=512M
innodb_flush_log_at_trx_commit=1
innodb_lock_wait_timeout=50

Initializing MySQL

cd /data/mysql/bin
./mysqld --initialize-insecure --user=mysql --basedir=/data/mysql --datadir=/data/mysql/data

Creating Service

vi /lib/systemd/system/mysql.service
[Unit]
Description=MySQL Database Server
After=network.target

[Service]
Type=notify
User=mysql
Group=mysql
ExecStart=/data/mysql/bin/mysqld --defaults-file=/etc/mysql.conf
LimitNOFILE=10000
Restart=on-failure
RestartSec=10

[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl enable --now mysql

Configuring Root Access

mysql -uroot <<EOF
ALTER USER 'root'@'localhost' IDENTIFIED BY 'RootPass#789!';
CREATE USER 'root'@'%' IDENTIFIED BY 'RootPass#789!';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;
EOF

8. Installing kkFileView

Preparing LibreOffice

cd /data/install-page
tar zxf LibreOffice_24.2.8_Linux_x86-64_rpm.tar.gz -C /tmp
cd /tmp/LibreOffice_24.2.8.2_Linux_x86_64_rpm/RPMS
rpm -ivh *.rpm

Installing kkFileView

cd /data/install-page
tar zxf kkFileView-4.1.0.tar.gz -C /data
mv /data/kkFileView-4.1.0 /data/kkfileview

Configuring kkFileView

vi /data/kkfileview/config/application.properties
server.port=8012
spring.servlet.multipart.max-file-size=100MB
spring.servlet.multipart.max-request-size=100MB
file.home=/data/kkfileview/fileDir
office.home=/opt/libreoffice24.2

Configuring Startup Script

vi /data/kkfileview/bin/startup.sh
#!/bin/bash
export JAVA_HOME=/data/jdk
export JRE_HOME=${JAVA_HOME}/jre
export PATH=${JAVA_HOME}/bin:$PATH

cd $(dirname $0)/..
sh bin/startup.sh

Creating Service

vi /lib/systemd/system/kkfileview.service
[Unit]
Description=kkFileView Document Viewer
After=network.target

[Service]
Type=forking
ExecStart=/data/kkfileview/bin/startup.sh
ExecStop=/data/kkfileview/bin/shutdown.sh
Restart=on-failure

[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl enable --now kkfileview

9. Installing MinIO

Extracting MinIO

cd /data/install-page
unzip minio.zip -d /data/
mkdir -p /data/minio/{data,logs}
chmod +x /data/minio/bin/*

Creating Startup Script

vi /data/minio/bin/start.sh
#!/bin/bash
export MINIO_ROOT_USER=minioadmin
export MINIO_ROOT_PASSWORD=minioadmin123
nohup /data/minio/bin/minio server \
  --address ":9000" \
  --console-address ":9001" \
  /data/minio/data > /data/minio/logs/minio.log 2>&1 &

Creating Service

vi /lib/systemd/system/minio.service
[Unit]
Description=MinIO Object Storage
After=network.target

[Service]
Type=forking
ExecStart=/data/minio/bin/start.sh
ExecStop="pkill -9 minio"
Restart=on-failure
RestartSec=10

[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl enable --now minio

10. Installing EMQX

Extracting EMQX

cd /data/install-page
tar zxf emqx-5.8.1-el8-amd64.tar.gz -C /data
mv /data/emqx-5.8.1-el8-amd64 /data/emqx

Configuring EMQX

vi /data/emqx/etc/emqx.conf
node.name = emqx@127.0.0.1
node.cookie = emqx_secret_cookie_2024
listeners.tcp.default = 1883
listeners.ssl.default = 8883
listeners.http.default = 8081
listeners.https.default = 8082

Creating Service

vi /lib/systemd/system/emqx.service
[Unit]
Description=EMQX MQTT Broker
After=network.target

[Service]
Type=exec
User=root
Group=root
ExecStart=/data/emqx/bin/emqx start
ExecStop=/data/emqx/bin/emqx stop
WorkingDirectory=/data/emqx
Restart=on-failure
RestartSec=10

[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl enable --now emqx

Verifying Installation

/data/emqx/bin/emqx ctl status

Service Ports Summary

Service Port Console/Management Port
Nginx 80 -
MySQL 3307 -
Redis 6380 -
Nacos 8848 9848
Kafka 9092 -
Zookeeper 2181 -
MinIO 9000 9001
kkFileView 8012 -
EMQX 1883 18083

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.