查看Tomcat是否运行:
ps -ef|grep tomcat
查看nginx是否运行:
ps -ef|grep nginx
重启nginx
./nginx -s reload
安装JDK
上传java文件夹到根目录 //从qq群里下载java.rar压缩包在本地解压后通过上传工具上传(xftp)
cd /java //进入java目录
chmod -R 777 bin //对java目录中的bin目录指定可执行、读写等权限
vi /etc/profile //编辑profile文件,在末尾增加
export JAVA_HOME=/java
export PATH=$JAVA_HOME/bin:$PATH
按ESC键,在切换到大写状态,按两次ZZ键保存并退出
source /etc/profile //让profile配置文件立即生效
java -version //打印java版本信息,如果显示信息,则JDK安装完成
安装Tomcat
在同一台服务器上每一个站点独立运行tomcat服务,使用nginx进行代理,每一个tomcat的端口号要保证不同
配置server.xml //从qq群里下载tomcat.rar压缩包在本地解压后进入tomcat/conf目录
需要修改端口号的位置
<Server port="9001" shutdown="SHUTDOWN">
<Connector port="8001" protocol="HTTP/1.1" connectionTimeout="20000" maxPostSize="-1" redirectPort="8443" />
<Connector port="9501" protocol="AJP/1.3" redirectPort="8443" />
以上port的值需要修改,不同的tomcat必须不同,每多增加一站点端口号递增;建议命名规则:以9001、9002|8001、8002|9501、9502数字1、2、3...n类推
修改成保存
注意如果需要大文件上传:默认2M,增加maxPostSize="-1" 不限制(单位为字节);
上传tomcat目录到/data目录下 //通过xftp上传,上传前建议更改tomcat文件夹名称(也可以在上传后更改),如:sys8001,sys表示后台,8001表示所使用的端口号;如:www8002,www表示PC,8002表示所使用的端口号
cd /data/sys8001 //进入目录
chmod -R 777 bin //指定bin目录权限
cd bin //进入目录
./startup.sh //启动tomcat
./shutdown.sh stop -force //彻底强制关闭tomcat,当需要重启或停止tomcat时
安装nginx
yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel pcre pcre-devel libunwind gperftools
下载nginx最新版本 http://nginx.org/en/download.html //可下载到本地解压后的文件夹上传到服务器(建议使用),也可以直接在服务器上下载(服务器端解压),
上传解压文件夹/nginx-1.15.8 //下载时为最新版本,解压后的文件夹
cd /nginx-1.15.i //进入目录
chmod -R 777 configure //给权限
./configure --prefix=/nginx --with-http_stub_status_module --with-http_ssl_module --with-file-aio --with-http_realip_module --with-google_perftools_module --with-http_gzip_static_module //安装参数,指定的安装位置为/nginx
make install //安装
配置nginx
#user nobody;
worker_processes 2;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr $remote_user [$time_local] "$request" $request_body '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
log_format access '$remote_addr $remote_user [$time_local] "$request" $status "$http_referer" ';
access_log logs/access.log main;
#limit_req_zone $binary_remote_addr zone=allips:10m rate=2r/s;
#请求缓冲设置
server_names_hash_bucket_size 128; #服务器名字的hash表大小
large_client_header_buffers 8 32k; #设定请求缓
client_header_buffer_size 128k; #上传文件大小限制
client_max_body_size 8m; #设定请求缓
client_body_buffer_size 256k;
types_hash_bucket_size 128;
open_file_cache max=10000 inactive=20s;
open_file_cache_valid 30s;
open_file_cache_min_uses 1;
#set_real_ip_from 101.201.174.142;
#real_ip_header X-Forwarded-For;
#real_ip_header http_x_forwarded_for;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
gzip on; #开启gzip压缩输出
gzip_disable "MSIE [1-6]\.(?!.*SV1)";
gzip_min_length 1k; #最小压缩文件大小
gzip_buffers 4 16k; #压缩缓冲区
gzip_http_version 1.0; #压缩版本(默认1.1,前端如果是squid2.5请使用1.0)
gzip_comp_level 2; #压缩等级
#压缩类型,默认就已经包含text/html,所以下面就不用再写了,写上去也不会有问题,但是会有一个warn。
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;
#服务集合引入
include serverlist.conf;
}
配置serverlist.conf文件 //自定义服务器及域名站点配置文件,非nginx自带,创建文本文件保存为此名称与后缀
#80WEB服务器配置
server {
listen 80; #正常80端口
server_name sysv2.rss.ry1.itemjia.com; #域名
root html;
location / {
index index.html index.htm;
proxy_pass http://127.0.0.1:8001; #tomcat服务器地址,此处为与nginx安装在同一台服务器上
proxy_next_upstream http_500 http_502 http_503 error timeout invalid_header;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_body_buffer_size 1024k;
client_max_body_size 200m;
proxy_connect_timeout 1800;
proxy_send_timeout 600;
proxy_read_timeout 1800;
proxy_buffer_size 128k;
proxy_buffers 8 128k;
proxy_busy_buffers_size 128k;
proxy_temp_file_write_size 128k;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
#SSL配置 443 如需要时增加
参考文档 https://www.cnblogs.com/zhanghaoh/p/5293158.html
server {
listen 443 ssl;
server_name ssl.rss.ry1.itemjia.com;
ssl_certificate /nginx/cert/ssl.rss.ry1.itemjia.com.crt; //证书存放位置,以域名作为命名方式,以区分有多个站点
ssl_certificate_key /nginx/cert/ssl.rss.ry1.itemjia.com.key; //证书密钥存放位置
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
root html;
location / {
index index.html index.htm;
proxy_pass http://127.0.0.1:8004; #对应的tomcat服务器
proxy_next_upstream http_500 http_502 http_503 error timeout invalid_header;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
client_body_buffer_size 1024k;
client_max_body_size 200m;
proxy_connect_timeout 1800;
proxy_send_timeout 600;
proxy_read_timeout 1800;
proxy_buffer_size 128k;
proxy_buffers 8 128k;
proxy_busy_buffers_size 128k;
proxy_temp_file_write_size 128k;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
#tomcat server.xml ssl配置,以下只需要更改实际的端口号即可
<Server port="9004" shutdown="SHUTDOWN">
<Listener className="org.apache.catalina.startup.VersionLoggerListener" />
<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
<Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />
<GlobalNamingResources>
<Resource name="UserDatabase" auth="Container"
type="org.apache.catalina.UserDatabase"
description="User database that can be updated and saved"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
pathname="conf/tomcat-users.xml" />
</GlobalNamingResources>
<Service name="Catalina">
<Connector port="8004" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />
<Connector port="9204" protocol="AJP/1.3" redirectPort="8443" />
<Engine name="Catalina" defaultHost="localhost">
<Realm className="org.apache.catalina.realm.LockOutRealm">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/>
</Realm>
<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true">
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log" suffix=".txt" pattern="%h %l %u %t "%r" %s %b" remoteIpHeader="x-forwarded-for" remoteIpProxiesHeader="x-forwarded-by" protocolHeader="x-forwarded-proto" />
<Context path="" docBase="ROOT" reloadable="true" crossContext="true" />
</Host>
</Engine>
</Service>
</Server>
上传nginx.conf与serverlist.conf到/nginx/conf目录 //文件
cd /nginx/sbin
./nginx //启动nginx
自动启动
- 编辑:/etc/rc.d/rc.local //rc.local 需要增加可执行权限
- 加入内容:
/nginx/sbin/nginx
export JAVA_HOME=/java
export PATH=$JAVA_HOME/bin:$PATH
sh /data/tomcat/8001sys/bin/startup.sh
sh /data/tomcat/8002www/bin/startup.sh
sh /data/tomcat/8003uf/bin/startup.sh
如需要使用FTP进行文件上传发布,请参考FTP服务器安装与部署及相关的配置