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/
2.2、使用xftp上传文件
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
再执行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)
二、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
2.2、解压安装包
[root@chenstudy src]# tar -zxvf pcre-8.35.tar.gz
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
2.5、查看pcre版本
[root@chenstudy pcre-8.35]# pcre-config --version
8.35
第三步:安装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
3.2、解压安装包
[root@chenstudy src]# tar -zxvf nginx-1.22.0.tar.gz
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
第二步:配置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
第三步:启动 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
访问站点:
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