nginx-1.15.12 + jdk1.8.0 + tomcat-8.5.42 + redis-5.0.5 + redisson + mysql5.7.26。
安装zlib-devel、pcre-devel等依赖包
yum -y install gcc gcc-c++ make libtool zlib zlib-devel pcre pcre-devel openssl openssl-devel
groupadd nginx
useradd nginx -g nginx -s /sbin/nologin -M
cd /usr/local/src
wget http://nginx.org/download/nginx-1.15.12.tar.gz
tar zxf nginx-1.15.12.tar.gz
cd nginx-1.15.12
./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module --with-http_realip_module --with-http_ssl_module --with-http_gzip_static_module --with-pcre --with-http_flv_module
make
make install
ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
nginx -t
(
#添加进service
vi /etc/init.d/nginx
chmod +x /etc/init.d/nginx
chkconfig --add nginx
chkconfig nginx on
systemctl daemon-reload
)
vi /usr/local/nginx/conf/nginx.conf
(
user nginx;
worker_processes 4;
#多核cpu的配置
worker_cpu_affinity 0001 0010 0100 1000;
error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#配置Nginx worker进程最大打开文件数
worker_rlimit_nofile 10240;
pid logs/nginx.pid;
events {
#使用epoll模型
use epoll;
#单个进程允许的客户端最大连接数
worker_connections 4096;
}
http {
#文件的数据类型
include mime.types;
default_type application/octet-stream;
#访问日志配置
log_format main '$remote_addr - r e m o t e u s e r [ remote_user [ remoteuser[time_local] “KaTeX parse error: Double superscript at position 34: … '̲status b o d y b y t e s s e n t " body_bytes_sent " bodybytessent"http_referer” ’
‘“ h t t p u s e r a g e n t " " http_user_agent" " httpuseragent""http_x_forwarded_for”’;
access_log logs/access.log main;
#隐藏版本号
server_tokens off;
sendfile on;
tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#Compression Settings
gzip on;
gzip_comp_level 6;
gzip_http_version 1.1;
gzip_proxied any;
gzip_min_length 1k;
gzip_buffers 16 8k;
gzip_types text/plain text/css text/javascript application/json application/javascript application/x-javascript application/xml;
gzip_vary on;
#end gzip
#http_proxy Settings
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 75;
proxy_send_timeout 75;
proxy_read_timeout 75;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
#load balance Settings
upstream backend_tomcat {
server 192.168.0.205:8080 weight=1 max_fails=2 fail_timeout=10s;
server 192.168.0.205:8081 weight=1 max_fails=2 fail_timeout=10s;
}
#virtual host Settings
server {
listen 8089;
#这里配置nginx需要代理的域名
server_name 192.168.0.205;
charset utf-8;
location / {
root html;
index index.jsp index.html index.htm;
}
location ~* .(jsp|do)$ {
#指定反向代理为上面配置的那个upstream节点
proxy_pass http://backend_tomcat;
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_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
}
location /nginx_status {
#stub_status on;
#access_log off;
#允许某个ip或者一个ip段访问
#allow 192.168.0.0/255;
#禁止某个ip或者一个ip段访问
#deny all;
}
}
}
)
firewall-cmd --permanent --add-port=8089/tcp (–permanent永久生效,没有此参数重启后失效)
firewall-cmd --reload
./nginx 启动 ./nginx -s stop 停止 (nginx -s reload重新加载)
ps -ef|grep nginx
#wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum install -y java-1.8.0-openjdk*
java -version # java -verbose 查看jdk安装位置
wget http://mirror.bit.edu.cn/apache/tomcat/tomcat-8/v8.5.42/bin/apache-tomcat-8.5.42.tar.gz
tar zxf apache-tomcat-8.5.42.tar.gz
mv apache-tomcat-8.5.42 /usr/local/tomcat-8080
cp -r tomcat-8080 tomcat-8081
vi /etc/profile
(
JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.212.b04-0.el7_6.x86_64
export JAVA_HOME
CATALINA_HOME=/usr/local/tomcat-8080
CATALINA_BASE=/usr/local/tomcat-8080
CATALINA_HOME1=/usr/local/tomcat-8081
CATALINA_BASE1=/usr/local/tomcat-8081
export CATALINA_HOME CATALINA_BASE CATALINA_HOME1 CATALINA_BASE1
PATH= P A T H : PATH: PATH:JAVA_HOME/bin
CLASSPATH=.: J A V A H O M E / l i b / d t . j a r : JAVA_HOME/lib/dt.jar: JAVAHOME/lib/dt.jar:JAVA_HOME/lib/tools.jar: C A T A L I N A H O M E / b i n : CATALINA_HOME/bin: CATALINAHOME/bin:CATALINA_HOME1/bin
export CLASSPATH PATH
)
source /etc/profile
/usr/local/tomcat-8080/bin/version.sh #查看tomcat版本
vi /usr/local/tomcat-8081/conf/server.xml #改三个端口避免冲突
vi catalina.sh
(
#OS specific support. var must be set to either true or false.
在上面代码的下面增加如下代码
第二个tomcat:
export CATALINA_BASE=$CATALINE_BASE1
export CATALINA_HOME=$TOMCAT_HOME1
)
firewall-cmd --permanent --add-port=8080/tcp #firewall-cmd --permanent --remove-port=8080/tcp
firewall-cmd --permanent --add-port=8081/tcp
firewall-cmd --reload
netstat -anpt | grep java #查看端口监听信息
vi /usr/local/tomcat-8080/conf/server.xml #找到对应位置 添加jvmRoute 和Context
vi /usr/local/tomcat-8081/conf/server.xml
mkdir -p /home/web/webapp1
mkdir -p /home/web/webapp2
cd /home/web/webapp1
cd /home/web/webapp2
vi index.jsp
http://192.168.0.205:8089/index.jsp #访问nginx 测试访问请求负载均衡
wget http://download.redis.io/releases/redis-5.0.5.tar.gz
tar zxf redis-5.0.5
cd redis-5.0.5
make && make install #默认安装到/usr/local,/usr/local/bin,/usr/local/share,/usr/local/include,/usr/local/lib,/usr/local/share/man目录下
cd utils
./install_server.sh #初始化 中间提示Please select the redis executable path [] 输入 /usr/local/bin/redis-server
#配置文件为/etc/redis/6379.conf ,日志文件为/var/log/redis_6379.log
#数据文件dump.rdb存放到/var/lib/redis/6379目录 ,启动脚本为/etc/init.d/redis_6379
vi /etc/systemd/system/redis_6379.service
(
[Unit]
Description=Redis on port 6379
[Service]
Type=forking
ExecStart=/etc/init.d/redis_6379 start
ExecStop=/etc/init.d/redis_6379 stop
[Install]
WantedBy=multi-user.target
)
#启动redis
systemctl daemon-reload
systemctl enable redis_6379.service
systemctl start redis_6379.service
systemctl status redis_6379.service
netstat -anpt | grep 6379
ln -s /usr/local/src/redis-5.0.5/src/redis-server /usr/bin/redis-server #创建全局命令(也可以在第一个安装目录里执行redis-server命令)
ln -s /usr/local/src/redis-5.0.5/src/redis-cli /usr/bin/redis-cli
redis-server -v #查看版本
vi /etc/redis/6379.conf #配置redis grep -Ev ‘#|$’ /etc/redis/6379.conf
(
bind 127.0.0.1 192.168.0.205
requirepass redis@123
appendonly no
)
systemctl restart redis_6379.service #systemctl stop redis_6379.service systemctl start redis_6379.service
redis-cli -h 192.168.0.205 -p 6379 -a redis@123
(
192.168.0.205:6379> keys *
(empty list or set)
192.168.0.205:6379> set name lisi
OK
192.168.0.205:6379> get name
“lisi”
192.168.0.205:6379> del name
(integer) 1
)
#将redisson-all-3.11.0.jar和redisson-tomcat-8-3.11.0.jar上传到tomcat的lib目录下
vi /usr/local/tomcat-8080/conf/context.xml vi /usr/local/tomcat-8081/conf/context.xml
vi /usr/local/tomcat-8080/redisson.conf (context.xml里配置的catalina.base 是tomcat的根目录)
{
“singleServerConfig”:{
“idleConnectionTimeout”:10000,
“pingTimeout”:1000,
“connectTimeout”:10000,
“timeout”:3000,
“retryAttempts”:3,
“retryInterval”:1500,
“password”:“redis@123”,
“subscriptionsPerConnection”:5,
“clientName”:null,
“address”: “redis://127.0.0.1:6379”,
“subscriptionConnectionMinimumIdleSize”:1,
“subscriptionConnectionPoolSize”:50,
“connectionMinimumIdleSize”:32,
“connectionPoolSize”:64,
“database”:0,
“dnsMonitoringInterval”:5000
},
“threads”:0,
“nettyThreads”:0,
“codec”:{
“class”:“org.redisson.codec.JsonJacksonCodec”
},
“transportMode”:“NIO”
}
#重启tomcat访问测试效果 http://192.168.0.205:8089/index.jsp
###如果遇到后来又装了一个redis导致覆盖无法正常启动的问题时,删除对应的pid文件和dump文件,重启即可
#执行systemctl status redis_6379.service 报错信息如下/var/run/redis_6379.pid exists, process is already running or crashed
#rm -rf /var/run/redis_6379.pid
#rm -rf /var/lib/redis/6379/dump.rdb
#systemctl restart redis_6379.service
tar -xvzf mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.7.26-linux-glibc2.12-x86_64 mysql
groupadd mysql
useradd -r -g mysql mysql
cd mysql
mkdir data
chown -R mysql:mysql ./
./bin/mysqld --initialize --user=mysql --basedir=/home/mysql --datadir=/home/mysql/data
#A temporary password is generated for root@localhost: 0
chown -R mysql data
mkdir tmp
chown -R mysql:mysql tmp
vi /etc/my.cnf
(
#本配置未做任何性能调优
[mysqld]
basedir=/home/mysql
datadir=/home/mysql/data
socket=/home/mysql/tmp/mysql.sock
port=3306
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
lower_case_table_names=1
[client]
socket=/home/mysql/tmp/mysql.sock
[mysqld_safe]
basedir=/home/mysql
datadir=/home/mysql/data
socket=/home/mysql/tmp/mysql.sock
port=3306
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
#include all files from the config directory
!includedir /etc/my.cnf.d
)
./bin/mysqld_safe&
#输入bg后台运行
ps -ef|grep mysql
./bin/mysql -uroot -p
#输入0
flush privileges;
use mysql;
update user set host = ‘%’ where user =‘root’; #开启远程访问
quit
#进入mysql安装根目录
./bin/mysqladmin -u root -p shutdown
#输入密码关闭,然后再启动
./bin/mysqld_safe&
#开防火墙端口
firewall-cmd --permanent --add-port=3306/tcp
firewall-cmd --reload
cp mysql-connector-java-5.1.47.jar /usr/local/tomcat-8080/lib/
cp mysql-connector-java-5.1.47.jar /usr/local/tomcat-8081/lib/
vi /usr/local/tomcat-8080/conf/context.xml vi /usr/local/tomcat-8081/conf/context.xml
(
username=“root” password=“mysql@123” driverClassName=“com.mysql.jdbc.Driver”
url=“jdbc:mysql://192.168.0.205:3306/javatest”/>
)
mkdir /home/web/webapp1/WEB-INF mkdir /home/web/webapp2/WEB-INF
vi /home/web/webapp1/WEB-INF/web.xml cp /home/web/webapp1/WEB-INF/web.xml /home/web/webapp2/WEB-INF
(
xsi:schemaLocation=“http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd”
version=“2.4”>
)
vi /home/web/webapp1/test.jsp cp /home/web/webapp1/test.jsp /home/web/webapp2/
(
<%@ page language=“java” import=“java.sql.*” pageEncoding=“GB2312”%>
connect MySQL
<%
String driverClass=“com.mysql.jdbc.Driver”;
String url=“jdbc:mysql://192.168.0.205:3306/javatest”;
String username = “root”;
String password = “mysql@123”;
Class.forName(driverClass);
Connection conn=DriverManager.getConnection(url, username, password);
Statement stmt=conn.createStatement();
ResultSet rs = stmt.executeQuery(“select * from testdata”);
while(rs.next()){
out.println(“
foo:”+rs.getString(2)+“bar:”+rs.getString(3));
}
rs.close();
stmt.close();
conn.close();
%>
)
#访问地址 http://192.168.0.8089/test.jsp