JavaWeb服务简单部署

JavaWeb服务简单部署

服务器1 安装nginx-1.20.2
服务器2 安装jdk-1.8.0_241 redis-6.2.7
服务器3 安装mysql-8.0.24

1 安装环境

操作系统:CentOS7.9
硬件要求:8G以上
JDK版本:1.8 242版本
Nginx版本:1.20.2
MySQL版本:8.0.24
Redis版本:6.2.7

2 中间件安装

上产(tar/tar.gz)离线安装包到指定服务器的指定目录

2.0 临时环境变量

#误删$PATH导致ll等命令不能使用补救方法-设置临时变量
[root@newxiaoguan-test /u01]$ export PATH=/usr/bin:/usr/sbin:/bin:/sbin:/usr/X11R6/bin

2.1 JDK安装

2.1.1 上传jdk
#jdk-8u241-linux-x64.tar.gz

#卸载openjdk
[root@newxiaoguan-test /test]$ cd /u01
[root@newxiaoguan-test /u01]$ java -version
[root@newxiaoguan-test /u01]$ rpm -qa | grep java | xargs rpm -e --nodeps

#解压oraclejdk
[root@newxiaoguan-test /u01]$ mkdir java
[root@newxiaoguan-test /u01]$ cd /u01/soft
[root@newxiaoguan-test /soft]$ tar -zxvf jdk-8u241-linux-x64.tar.gz -C /u01/java
[root@newxiaoguan-test /soft]$ cd /u01/java
[root@newxiaoguan-test /java]$ mv ./jdk1.8.0_241/* /u01/java/
2.1.2 配置环境变量
[root@newxiaoguan-test /java]$ vim /etc/profile
i
#java environment
export JAVA_HOME=/u01/java
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
#CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/lib/dt.jar
export PATH=$PATH:$JAVA_HOME/bin
#系统自带openjdk,卸载openjdk
esc :wq!
[root@newxiaoguan-test /java]$ source /etc/profile
[root@newxiaoguan-test /java]$ java -version

2.2 Nginx安装

2.2.1 上传Nginx
#nginx-1.20.2.tar.gz

#安装所需插件
[root@newxiaoguan-test /test]$ cd /u01
[root@newxiaoguan-test /u01]$ gcc -v
[root@newxiaoguan-test /u01]$ yum install -y gcc
[root@newxiaoguan-test /u01]$ yum install -y pcre pcre-devel zlib zlib-devel openssl openssl-devel

#解压nginx
[root@newxiaoguan-test /u01]$ mkdir nginx
[root@newxiaoguan-test /soft]$ cd /u01/soft
[root@newxiaoguan-test /soft]$ tar -zxvf nginx-1.20.2.tar.gz -C /u01/nginx

#编译并安装nginx
[root@newxiaoguan-test /soft]$ cd /u01/nginx/nginx-1.20.2
[root@newxiaoguan-test /nginx-1.20.2]$ ./configure --prefix=/u01/nginx
[root@newxiaoguan-test /nginx-1.20.2]$ make && make install

#编辑配置文件nginx.conf
[root@newxiaoguan-test /nginx]$ cd /u01/nginx
[root@newxiaoguan-test /conf]$ cd /u01/nginx/conf
[root@newxiaoguan-test /conf]$ cp nginx.conf nginx.conf.bak
[root@newxiaoguan-test /conf]$ vim nginx.conf
i
    server {
        listen       80;
        server_name  localhost;
        }
esc :wq!

#启动nginx
[root@newxiaoguan-test /conf]$ cd /u01/nginx
[root@newxiaoguan-test /nginx]$ ./sbin/nginx
[root@newxiaoguan-test /nginx]$ ps -ef | grep nginx
[root@newxiaoguan-test /nginx]$ kill -9 ......
[root@newxiaoguan-test /nginx]$ ./sbin/nginx -s stop
[root@newxiaoguan-test /nginx]$ ./sbin/nginx -s reload

2.2.2 配置环境变量
[root@newxiaoguan-test /nginx]$ vim /etc/profile
i
#nginx
export NGINX_HOME=/u01/nginx
export PATH=$PATH:${NGINX_HOME}/sbin
esc :wq!
[root@newxiaoguan-test /nginx]$ source /etc/profile
[root@newxiaoguan-test /nginx]$ nginx -v
[root@newxiaoguan-test /nginx]$ nginx -s reload
2.2.3 开放端口80
#sudo systemctl start firewalld
#sudo systemctl stop firewalld
#sudo systemctl disable firewalld
[root@newxiaoguan-test /nginx]$ sudo firewall-cmd --zone=public --add-port=80/tcp --permanent
[root@newxiaoguan-test /nginx]$ sudo firewall-cmd --reload

2.3 MySQL安装

2.3.1 上传MySQL
#mysql-8.0.24-linux-glibc2.12-x86_64.tar

#卸载冲突插件
[root@newxiaoguan-test /test]$ cd /u01
[root@newxiaoguan-test /u01]$ rpm -qa | grep -i mysql
#--没有查到忽略--
[root@newxiaoguan-test /u01]$ rpm -e --nodeps mysql-libs-5.1.73-5.el6_6.x86_64
[root@newxiaoguan-test /u01]$ rm -rf /usr/lib/mysql
[root@newxiaoguan-test /u01]$ rm -rf /usr/include/mysql
[root@newxiaoguan-test /u01]$ rm -rf /etc/my.cnf
[root@newxiaoguan-test /u01]$ rm -rf /var/lib/mysql
#--没有查到忽略--
[root@newxiaoguan-test /u01]$ rpm -qa | grep mariadb
#--没有查到忽略--
[root@newxiaoguan-test /u01]$ rpm -e --nodeps mariadb-libs-5.5.60-1.el7_5.x86_64
#--没有查到忽略--
[root@newxiaoguan-test /u01]$ rpm -qa | grep libaio
#--没有查到安装--
[root@newxiaoguan-test /u01]$ yum install -y libaio
#--没有查到安装--


#解压mysql
[root@newxiaoguan-test /u01]$ mkdir mysql
[root@newxiaoguan-test /u01]$ cd /u01/soft
[root@newxiaoguan-test /soft]$ tar -xvf mysql-8.0.24-linux-glibc2.12-x86_64.tar -C /u01/mysql
[root@newxiaoguan-test /soft]$ cd /u01/mysql
[root@newxiaoguan-test /mysql]$ mv ./mysql-8.0.24-linux-glibc2.12-x86_64/* /u01/mysql

#创建用户组mysql
[root@newxiaoguan-test /soft]$ cd /u01/mysql
[root@newxiaoguan-test /mysql]$ groupadd mysql
[root@newxiaoguan-test /mysql]$ useradd -r -g mysql mysql

#创建文件夹并设置用户组
[root@newxiaoguan-test /mysql]$ mkdir -p /u01/mysql/data
[root@newxiaoguan-test /mysql]$ chown -R mysql:mysql /u01/mysql/data
[root@newxiaoguan-test /mysql]$ mkdir -p /var/lib/mysql
[root@newxiaoguan-test /mysql]$ chown -R mysql:mysql /var/lib/mysql/

#编辑配置文件my.cnf
[root@newxiaoguan-test /mysql]$ cd /u01/mysql
[root@newxiaoguan-test /mysql]$ vim /etc/my.cnf
i
[mysql]
socket=/var/lib/mysql/mysql.sock 
default-character-set=utf8 # 设置mysql客户端默认字符集 

[mysqld]
#skip-grant-tables
lower_case_table_names=1 # 设置表名不区分大小写
port=3306 # 设置端口号
socket=/var/lib/mysql/mysql.sock  
basedir=/u01/mysql # 设置mysql的安装目录   
datadir=/u01/mysql/data # 设置mysql数据库的数据的存放目录
max_connections=200 # 允许最大连接数 
character-set-server=utf8 # 服务端使用的字符集修改为UTF-8,默认为8比特编码的latin1字符集
default-storage-engine=INNODB # 创建新表时默认使用的存储引擎
# 开启bin-log日志
expire_logs_days=15
log-bin=/u01/mysql/data/mysql-bin
binlog-format=ROW
server_id=1
esc :wq!

#安装服务mysqld
[root@newxiaoguan-test /mysql]$ cp /u01/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@newxiaoguan-test /mysql]$ vim /etc/init.d/mysqld
i
basedir=/u01/mysql
datadir=/u01/mysql/data
mysqld_pid_file_path=/u01/mysql/data/mysqld.pid
conf=/etc/my.cnf
esc :wq!
[root@newxiaoguan-test /mysql]$ chmod +x /etc/rc.d/init.d/mysqld
[root@newxiaoguan-test /mysql]$ chkconfig --add mysqld
[root@newxiaoguan-test /mysql]$ chkconfig --list mysqld

#初始化mysql
[root@newxiaoguan-test /mysql]$ cd /u01/mysql
[root@newxiaoguan-test /mysql]$ sudo bin/mysqld --initialize --user=mysql --lower-case-table-names=1  --basedir=/u01/mysql --datadir=/u01/mysql/data
#sudo bin/mysqld --initialize --user=mysql --basedir=/u01/mysql --datadir=/u01/mysql/data
#[Note] [MY-010454] [Server] A temporary password is generated for root@localhost: dPV##sh5rEst
[root@newxiaoguan-test /mysql]$ ps -ef|grep mysqld
[root@newxiaoguan-test /mysql]$ kill -9 ......

#启动mysql
[root@newxiaoguan-test /mysql]$ chmod -R 777 /u01/mysql
#sudo service mysqld start
#sudo service mysqld restart
#sudo service mysqld stop
[root@newxiaoguan-test /mysql]$ sudo service mysqld start

#修改密码并创建新用户
[root@newxiaoguan-test /mysql]$ bin/mysql -uroot -pdPV##sh5rEst
-> use mysql;
-> select 1;
-> set password='root@123';
-> flush privileges;
-> exit
[root@newxiaoguan-test /mysql]$ bin/mysql -uroot -proot@123
-> use mysql;
-> select 1;
-> update user set host='%' where user='root';
-> create database gxdb;
-> create user 'gxuser'@'%' identified by 'gxuser';
-> grant all privileges on gxdb.* to 'gxuser'@'%';
-> flush privileges;
-> exit
2.3.2 配置环境变量
[root@newxiaoguan-test /mysql]$ vim /etc/profile
i
#mysql
export MYSQL_HOME=/u01/mysql
export PATH=$PATH:$MYSQL_HOME/bin
esc :wq!
[root@newxiaoguan-test /mysql]$ source /etc/profile
[root@newxiaoguan-test /mysql]$ cd /u01
[root@newxiaoguan-test /u01]$ mysql -ugxuser -pgxuser
-> use gxdb;
-> select 1;
-> exit
2.3.3 开放端口3306
#sudo systemctl start firewalld
#sudo systemctl stop firewalld
#sudo systemctl disable firewalld
[root@newxiaoguan-test /u01]$ sudo firewall-cmd --zone=public --add-port=3306/tcp --permanent
[root@newxiaoguan-test /u01]$ sudo firewall-cmd --reload

2.4 Redis安装

2.4.1 上传Redis
#redis-6.2.7.tar.gz
#wget http://download.redis.io/releases/redis-6.2.7.tar.gz

#安装所需插件
[root@newxiaoguan-test /test]$ cd /u01
[root@newxiaoguan-test /u01]$ yum install -y gcc-c++


#解压redis
[root@newxiaoguan-test /u01]$ mkdir redis
[root@newxiaoguan-test /u01]$ cd /u01/soft
[root@newxiaoguan-test /soft]$ tar -zxvf redis-6.2.7.tar.gz -C /u01/redis

#编译并安装redis
[root@newxiaoguan-test /soft]$ cd /u01/redis/redis-6.2.7
[root@newxiaoguan-test /redis-6.2.7]$ make MALLOC=libc && make PREFIX=/u01/redis install

#编辑配置文件redis.conf
[root@newxiaoguan-test /redis-6.2.7]$ cp ./redis.conf /u01/redis/bin/redis.conf
[root@newxiaoguan-test /redis-6.2.7]$ cd /u01/redis/bin/
[root@newxiaoguan-test /bin]$ cp redis.conf redis.conf.bak
[root@newxiaoguan-test /bin]$ vim redis.conf
i
daemonize no  -->  daemonize yes
protected-mode yes  -->  protected-mode no
bind 127.0.0.1  -->  bind 0.0.0.0
#bind 127.0.0.1 -::1
esc :wq!

#启动redis
[root@newxiaoguan-test /bin]$ cd /u01/redis
#./bin/redis-server
[root@newxiaoguan-test /redis]$ ./bin/redis-server ./bin/redis.conf
[root@newxiaoguan-test /redis]$ ps -ef | grep redis
[root@newxiaoguan-test /redis]$ kill -9 ......
[root@newxiaoguan-test /redis]$ ./bin/redis-cli
-> get 1;
-> quit
2.4.2 配置环境变量
[root@newxiaoguan-test /mysql]$ vim /etc/profile
i
#redis
export REDIS_HOME=/u01/redis
export PATH=$PATH:$REDIS_HOME/bin
esc :wq!
[root@newxiaoguan-test /mysql]$ source /etc/profile
[root@newxiaoguan-test /mysql]$ cd /u01
[root@newxiaoguan-test /u01]$ redis-cli
-> get 1;
-> quit
2.4.3 开放端口6379
#sudo systemctl start firewalld
#sudo systemctl stop firewalld
#sudo systemctl disable firewalld
[root@newxiaoguan-test /u01]$ sudo firewall-cmd --zone=public --add-port=6379/tcp --permanent
[root@newxiaoguan-test /u01]$ sudo firewall-cmd --reload

3 应用程序部署

3.1 前端部署

3.1.1 上传web包
#admin.tar.gz

[root@newxiaoguan-test /test]$ cd /u01/
[root@newxiaoguan-test /u01]$ cd tar -zxvf admin.tar.gz -C /u01/nginx/html
[root@newxiaoguan-test /u01]$ cd /u01/nginx

#编辑配置文件nginx.conf
[root@newxiaoguan-test /nginx]$ cd /u01/nginx/conf
[root@newxiaoguan-test /conf]$ vim nginx.conf
i
        listen       80;
        server_name  localhost;
        location ^~ /api/ {
            proxy_set_header Host $host;
            proxy_set_header Connection close;
            proxy_pass http://xx.1.10.xxx:8080;
            index  index.html index.htm;
        }
        location ^~ /admin{
            alias html/admin;
            index index.html; 
            try_files $uri $uri/ /admin/index.html;
        }
esc :wq!

#重启nginx
[root@newxiaoguan-test /conf]$ nginx -s reload

#访问地址
#http://xx.1.10.xxx/admin/user/login

3.2 后端部署

3.2.1 上传jar包
#new-cms.jar
#shutdown.sh startup.sh

[root@newxiaoguan-test /test]$ cd /u01/
[root@newxiaoguan-test /u01]$ cd /u01/app

#启动jar
#nohup java -jar new-cms.jar --server.port=8080 >/u01/app/new-cms.log 2>&1 &
[root@newxiaoguan-test /conf]$ sh startup.sh

#访问地址
#http://xx.1.10.xxx:8080
3.2.2 开放端口8080
[root@newxiaoguan-test /conf]$ sudo firewall-cmd --zone=public --add-port=8080/tcp --permanent
[root@newxiaoguan-test /conf]$ sudo firewall-cmd --reload
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值