Linux完整应用部署(JDK+MySQL+Redis+Nginx)配置

一、Linux硬盘分区

主要分区:

\boot1G,实际需求
\tmp实际需求
\swap内存大小
\home实际需求
\剩余所有

二、JDK安装

以1.8为,创建usr/lib/java文件夹,下载jdk压缩包,解压到当前路径。

cd /usr/lib/java
wget https://repo.huaweicloud.com/java/jdk/8u192-b12/jdk-8u192-linux-x64.tar.gz
tar -zxvf jdk-8u192-linux-x64.tar.gz

配置环境变量,同时配置SPRING_PROFILES_ACTIVE为uat

vi /etc/profile

JAVA_HOME=/usr/lib/java/jdk1.8.0_192
CLASSPATH=$JAVA_HOME/lib/
PATH=$PATH:$JAVA_HOME/bin
export PATH JAVA_HOME CLASSPATH

export SPRING_PROFILES_ACTIVE=uat

source /etc/profile

输入 java -version 测试是否配置成功

三、Redis安装

进入/usr/local文件夹,下载redis压缩包,解压,进入redis-6.2.6文件夹

cd /usr/local/
wget https://download.redis.io/releases/redis-6.2.6.tar.gz
tar -zxvf redis-6.2.6.tar.gz
cd redis-6.2.6
make
make PREFIX=/usr/local/redis install

配置redis

vi /usr/local/redis/redis.conf

daemonize yes
bind 127.0.0.1
requirepass 你的密码

# 如需远程工具访问连接redis,还需配置
# bind 127.0.0.1 -::1
# protected-mode yes
protected-mode no

配置redis启动脚本

vi /etc/init.d/redisd
#!/bin/sh
# chkconfig:   2345 90 10
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.
 
#redis服务器监听的端口
REDISPORT=6379
 
#服务端所处位置
EXEC=/usr/local/redis/bin/redis-server
 
#客户端位置
CLIEXEC=/usr/local/redis/bin/redis-cli
 
#redis的PID文件位置,conf文件中有
PIDFILE=/var/run/redis_6379.pid
 
#redis的配置文件位置
CONF="/usr/local/redis/redis.conf"

#password
AUTH="password"
 
case "$1" in
    start)
        if [ -f $PIDFILE ]
        then
                echo "$PIDFILE exists, process is already running or crashed"
        else
                echo "Starting Redis server..."
                $EXEC $CONF
        fi
        ;;
    stop)
        if [ ! -f $PIDFILE ]
        then
                echo "$PIDFILE does not exist, process is not running"
        else
                PID=$(cat $PIDFILE)
                echo "Stopping ..."
                $CLIEXEC -p $REDISPORT -a $AUTH shutdown
                while [ -x /proc/${PID} ]
                do
                    echo "Waiting for Redis to shutdown ..."
                    sleep 1
                done
                echo "Redis stopped"
        fi
        ;;
    *)
        echo "Please use start or stop as first argument"
        ;;
esac
chmod 777 /etc/init.d/redisd
#设置为开机自启动服务器
chkconfig redisd on
#打开服务
service redisd start
#关闭服务
service redisd stop

测试redis服务

四、Nginx配置

先安装基础依赖

yum install gcc-c++
yum install openssl openssl-devel
yum install pcre pcre-devel
yum install zlib zlib-devel
cd /usr/local/nginx/
wget http://nginx.org/download/nginx-1.20.2.tar.gz
tar -zxvf nginx-1.20.2.tar.gz
cd nginx-1.20.2
./configure
make
make install

查看nginx

whereis nginx

 启动nginx服务

# 启动nginx 
/usr/local/nginx/sbin/nginx                      
# 停止 Nginx
/usr/local/nginx/sbin/nginx -s stop
# 检查配置文件nginx.conf的正确性命令
/usr/local/nginx/sbin/nginx -t         

五、MySQL配置

下载mysql压缩包

cd /download
wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.36-linux-glibc2.12-x86_64.tar.gz
tar -zxvf mysql-5.7.36-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.7.36-linux-glibc2.12-x86_64.tar.gz /usr/local/mysql

创建mysql用户及数据目录

# 创建组
groupadd mysql
# 创建用户
useradd -r -g mysql mysql
# 创建目录
mkdir -p /data/mysql
# 权限
chown mysql:mysql -R /data/mysql

配置mysql配置文件

vi /etc/my.cnf
[mysqld]
# datadir=/var/lib/mysql
# socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
# symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd

bind-address=0.0.0.0
port=3306
user=mysql
basedir=/usr/local/mysql
datadir=/data/mysql
socket=/tmp/mysql.sock
log-error=/data/mysql/mysql.err
pid-file=/data/mysql/mysql.pid
#character config
character_set_server=utf8mb4
symbolic-links=0
explicit_defaults_for_timestamp=true

lower_case_table_names=1
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

[mysqld_safe]
# log-error=/var/log/mariadb/mariadb.log
# pid-file=/var/run/mariadb/mariadb.pid

#
# include all files from the config directory
#
!includedir /etc/my.cnf.d

配置数据库

cd /usr/local/mysql/bin
./mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql/ --datadir=/data/mysql/ --user=mysql --initialize

# 查看密码
cat /data/mysql/mysql.err

# 配置启动脚本
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql 

ln -s  /usr/local/mysql/bin/mysql    /usr/bin

# 启动mysql
service mysql start

# 登录Mysql
mysql -u root -p

# 输入刚才的密码

# 修改密码
set password = password('新密码');

# 设置密码不过期
ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;

# 生效
FLUSH PRIVILEGES; 

# 配置远程连接
update user set host = '%' where user = 'root';

六、防火墙配置

# 查看防火墙是否开启
systemctl status firewalld

# 手动开启端口命令,80为例
firewall-cmd --zone=public --add-port=80/tcp --permanent

# 若开启8080/8085端口段
firewall-cmd --zone=public --add-port=8080-8085/tcp --permanent

# 移除端口,8080为例
firewall-cmd --permanent --remove-port=8080/tcp

# 开启后需要重启防火墙才生效
systemctl restart firewalld.service

# 查看防火墙是否开启了80端口的访问
firewall-cmd --list-all

# 查看80端口被谁占用
netstat -tunlp | grep 80

# 或者
lsof -i:80

# 或者
netstat -aptn

七、Springboot 启动脚本

以api.jar为例,

启动脚本

#!/bin/bash
nohup java -jar -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=128m -Xms1024m -Xmx1024m -Xmn256m -Xss256k -XX:SurvivorRatio=8 -XX:+UseConcMarkSweepGC ./api.jar --spring.profiles.active=test > /dev/null 2>&1 &

停止脚本

#!/bin/bash
keyWord="api.jar"
findPid=`ps -ef|grep java|grep "$keyWord"|grep -v grep|awk '{print $2}'`

if [ "$findPid" != "" ];then
  kill -9 "$findPid"
  if [ $? -eq 0 ]; then
         echo "Close the api successfully."
  else
        echo "Close the api failed."
  fi
else
  echo "api is not running."
fi

  • 2
    点赞
  • 62
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值