CentOS上安装JDK和Nginx

简介: 我们再练习项目时都是在本地进行跑,那如何把项目放到服务器上呢,要让项目在服务器上运行起来,我们需要在服务器上安装环境,本文将为大家带来JDK和Nginx的安装与下载,为我们部署项目做准备。Nginx是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,在BSD-like 协议下发行。其特点是占有内存少,并发能力强,事实上nginx的并发能力确实在同类型的网页服务器中表现较好;

Linux上安装LDK、Nginx

一、安装JDK

第一步:检测系统中是否存在JDK

[root@chenstudy ~]# java --version

显示:

-bash: java: command not found

说明系统中未安装JDK

第二步:安装新的JDK

2.1、下载JDK

JDK的下载链接https://www.oracle.com/cn/java/technologies/downloads/

image-20221008093059883

2.2、使用xftp上传文件

image-20221008093623993

image-20221008093806726

2.3、进入到目录,解压刚上传的文件

[root@chenstudy local]# cd jdk1.8/
[root@chenstudy jdk1.8]# ll
total 144692
-rw-r--r-- 1 root root 148162542 Oct  8 09:37 jdk-8u341-linux-x64.tar.gz
[root@chenstudy jdk1.8]# tar -zxvf jdk-8u341-linux-x64.tar.gz 
[root@chenstudy jdk1.8]# ll
total 144696
drwxr-xr-x 8 root root      4096 Oct  8 09:39 jdk1.8.0_341
-rw-r--r-- 1 root root 148162542 Oct  8 09:37 jdk-8u341-linux-x64.tar.gz
[root@chenstudy jdk1.8]# mv jdk1.8.0_341 jdk1.8 # 重命名
[root@chenstudy jdk1.8]# ll
total 144696
drwxr-xr-x 8 root root      4096 Oct  8 09:39 jdk1.8
-rw-r--r-- 1 root root 148162542 Oct  8 09:37 jdk-8u341-linux-x64.tar.gz
[root@chenstudy jdk1.8]# 

得到Jdk目录路径/usr/local/jdk1.8/jdk1.8

2.4、给所有的用户配置java环境

编辑 /etc/profile文件

按下i键,然后移动到最后一行,添加

#configuration java development enviroument
export JAVA_HOME=/usr/local/jdk1.8/jdk1.8
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar

然后按下esc键,输入:wq

image-20221008094733815

再执行source /etc/profile之后输入 java -version如果能看到对应版本信息,则说明java环境变量配置成功。

[root@chenstudy jdk1.8]# source /etc/profile
[root@chenstudy jdk1.8]# java -version
java version "1.8.0_341"
Java(TM) SE Runtime Environment (build 1.8.0_341-b10)
Java HotSpot(TM) 64-Bit Server VM (build 25.341-b10, mixed mode)

image-20221008095114264

二、Nginx 安装

第一步:安装编译工具及库文件

[root@chenstudy src]# yum -y install make zlib zlib-devel gcc-c++ libtool  openssl openssl-devel

第二步、首先要安装 PCRE

PCRE 作用是让 Nginx 支持 Rewrite 功能。

2.1、下载 PCRE 安装包,

PCRE下载地址: http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz

[root@chenstudy src]# cd /usr/local/src
[root@chenstudy src]# wget http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz

image-20221008100357281

2.2、解压安装包

[root@chenstudy src]# tar -zxvf pcre-8.35.tar.gz

image-20221008100650114

2.3、进入安装包目录

[root@chenstudy src]# cd pcre-8.35

2.4、编译安装

[root@chenstudy pcre-8.35]# ./configure
[root@chenstudy pcre-8.35]# make && make install

image-20221008101022851

2.5、查看pcre版本

[root@chenstudy pcre-8.35]# pcre-config --version
8.35

image-20221008101142325

第三步:安装nginx

3.1、下载nginx

下载地址:https://nginx.org/en/download.html

[root@chenstudy pcre-8.35]# cd /usr/local/src/
[root@chenstudy src]# wget wget http://nginx.org/download/nginx-1.22.0.tar.gz

image-20221008101538710

3.2、解压安装包

[root@chenstudy src]# tar -zxvf nginx-1.22.0.tar.gz

image-20221008101704182

3.3、进入安装包目录

[root@chenstudy src]# cd nginx-1.22.0

3.4、编译安装

[root@chenstudy nginx-1.22.0]# ./configure --prefix=/usr/local/webserver/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/usr/local/src/pcre-8.35
[root@chenstudy nginx-1.22.0]# make && make install

到此,nginx安装完成

第三步:Nginx 配置

第一步:创建 Nginx 运行使用的用户 www:

[root@chenstudy nginx-1.22.0]# cd /usr/local/webserver/nginx/conf/nginx.conf
[root@chenstudy conf]# /usr/sbin/groupadd www
[root@chenstudy conf]# /usr/sbin/useradd -g www www

image-20221008102549221

第二步:配置nginx.conf

将/usr/local/webserver/nginx/conf/nginx.conf替换为以下内容:

[root@chenstudy conf]# cat nginx.conf

user  www www;
worker_processes  1;

error_log  /usr/local/webserver/nginx/logs/nginx_error.log crit; # 日志位置和日志级别
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

pid        /usr/local/webserver/nginx/nginx.pid;
#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 65535;

events {
    use epoll;
    worker_connections  65535;
}


http {
    include       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  logs/access.log  main;

    server_names_hash_bucket_size 128;
    client_header_buffer_size 32k;
    large_client_header_buffers 4 32k;
    client_max_body_size 8m;
     
    sendfile on;
    tcp_nopush on;
    keepalive_timeout 60;
    tcp_nodelay on;
    fastcgi_connect_timeout 300;
    fastcgi_send_timeout 300;
    fastcgi_read_timeout 300;
    fastcgi_buffer_size 64k;
    fastcgi_buffers 4 64k;
    fastcgi_busy_buffers_size 128k;
    fastcgi_temp_file_write_size 128k;
    gzip on; 
    gzip_min_length 1k;
    gzip_buffers 4 16k;
    gzip_http_version 1.0;
    gzip_comp_level 2;
    gzip_types text/plain application/x-javascript text/css application/xml;
    gzip_vary on;

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}

检查配置文件nginx.conf的正确性命令:

[root@chenstudy conf]# /usr/local/webserver/nginx/sbin/nginx -t

image-20221008104143473

第三步:启动 Nginx

Nginx 启动命令如下:

[root@chenstudy conf]# /usr/local/webserver/nginx/sbin/nginx
[root@chenstudy conf]# ps -ef | grep nginx
root      5820     1  0 10:45 ?        00:00:00 nginx: master process /usr/local/webserver/nginx/sbin/nginx
www       5821  5820  0 10:45 ?        00:00:00 nginx: worker process
root      5851 24210  0 10:46 pts/0    00:00:00 grep --color=auto nginx

image-20221008104623935

访问站点:

image-20221008104811247

Nginx 其他命令

以下包含了 Nginx 常用的几个命令:

/usr/local/webserver/nginx/sbin/nginx -s reload            # 重新载入配置文件
/usr/local/webserver/nginx/sbin/nginx -s reopen            # 重启 Nginx
/usr/local/webserver/nginx/sbin/nginx -s stop              # 停止 Nginx
目录
相关文章
|
1天前
|
Oracle Java 关系型数据库
2022 年超详细过程步骤讲解 CentOS 7 安装Maven。以及Mavne配置文件的修改
这篇文章提供了在CentOS 7上安装Maven的详细步骤,包括从官网下载Maven、创建文件夹、上传和解压Maven安装包、配置环境变量、设置Maven源为阿里云、指定jar包仓库位置、配置JDK版本,并验证安装是否成功。
2022 年超详细过程步骤讲解 CentOS 7 安装Maven。以及Mavne配置文件的修改
|
1天前
|
关系型数据库 MySQL Java
centos7安装mysql教程及Navicat平替软件
【8月更文挑战第17天】本教程详述CentOS 7上安装MySQL的过程。首先确保移除任何预装的MySQL组件,然后通过wget获取并安装MySQL的YUM源。可以选择安装特定版本如5.7或8.0。安装MySQL服务器后,启动服务并查找初始密码。登录MySQL后应立即更改密码,并可根据需要设置远程访问权限。此外,还推荐使用免费开源的DBeaver作为数据库管理工具,提供了安装步骤以方便管理和操作MySQL数据库。
|
1天前
|
Oracle Java 关系型数据库
2022 年超详细过程步骤讲解 CentOS 7 安装jdk1.8
这篇文章提供了在CentOS 7系统上安装JDK 1.8的详细步骤,包括卸载系统自带的JDK、下载Oracle官网的JDK安装包、上传至虚拟机、解压安装包、配置环境变量,并验证安装是否成功。
2022 年超详细过程步骤讲解 CentOS 7 安装jdk1.8
|
1天前
|
NoSQL 数据可视化 Linux
2022 年超详细步骤讲解 CentOS 7 安装Redis 。解决Redis Desktop Manager 图形化工具连接失败解决 ;connection failed处理。开机自启Redis
这篇文章提供了在CentOS 7上安装Redis的详细步骤,包括上传Redis安装包、解压安装、编译、安装、备份配置文件、修改配置以支持后台运行和设置密码、启动Redis服务、使用客户端连接Redis、关闭Redis服务、解决Redis Desktop Manager图形化工具连接失败的问题、设置Redis开机自启动,以及Redis服务的启动和停止命令。
2022 年超详细步骤讲解 CentOS 7 安装Redis 。解决Redis Desktop Manager 图形化工具连接失败解决 ;connection failed处理。开机自启Redis
|
1天前
|
应用服务中间件 Linux 网络安全
2022年超详细在CentOS 7上安装Nginx方法(源码安装)
这篇文章提供了在CentOS 7系统上通过源码安装Nginx的详细步骤,包括从官网下载Nginx源码包、上传至虚拟机、解压、删除压缩包、编译安装前的配置、安装PCRE库(因为Nginx使用PCRE库解析正则表达式)、安装zlib和OpenSSL库(用于支持HTTPS协议)、重新编译Nginx、安装后启动Nginx服务、关闭服务、修改默认端口、以及重启服务测试等步骤。文章还提供了相关命令和操作截图,帮助用户更好地理解和执行安装过程。
2022年超详细在CentOS 7上安装Nginx方法(源码安装)
|
20小时前
|
Linux Docker 容器
在CentOS上安装Docker的指南:
【8月更文挑战第19天】介绍在CentOS上安装Docker的过程:首先确认CentOS版本兼容,建议使用7或更高版本,并通过`yum update -y`更新系统。安装Docker时推荐使用官方仓库方法,需安装`yum-utils`等工具,设置Docker仓库简化安装流程。可选配置国内镜像源(如阿里云)提升下载速度。亦可通过RPM包离线安装。安装后启动Docker服务并通过`systemctl enable docker`设为开机启动。最后,运行`docker run hello-world`验证安装。如遇问题,使用`sudo journalctl -u docker`查看日志排错。
32 0
|
1天前
|
JavaScript Linux
2022年超详细在CentOS 7上安装Node.js方法(源码安装)
这篇文章介绍了在CentOS 7系统上通过源码安装Node.js的详细步骤,包括从官网下载Node.js源码包、将安装包上传至虚拟机、解压安装包、删除压缩文件、编译安装Node.js、检查Node.js和npm版本,以及切换npm源到淘宝镜像以加速下载。此外,还提供了一个获取Linux下Node.js离线安装包的微信公众号搜索方式。
|
应用服务中间件 nginx
nginx安装报错/configure: error: the HTTP gzip module requires the zlib library.
反向代理服务器的工作原理 反向代理服务器通常有两种模型,它可以作为内容服务器的替身,也可以作为内容服务器集群的负载均衡器。 1,作内容服务器的替身 如果您的内容服务器具有必须保持安全的敏感信息,如信用卡号数据库,可在防火墙外部设置一个代理服务器作为内容服务器的替身。
3803 0
|
应用服务中间件 PHP nginx