文章目录
小知识:
1.访问控制
allow some.ip.addr; # 一个 IP/主机/域名/网段
deny all;
deny some.ip.addr;
allow all;
2. Nginx 自身状态监控
sub_status
location /status/{
sub...;
}
接收、处理、读、写
zabbix
3. 升级
- 版本升级
- 功能升级
升级方式:
1. 停 Nginx 服务后,进行升级
2. 不停服务升级 - 平滑升级
共有的步骤:
1. 下载对应软件包
- 主程序源码包
- 模块的源码包
2. 配置:
首先安装相关的依赖环境包
./configure
把原来配置完全复制一下(nginx -V)+需要增加的新功能所有的配置参数
使用第三方的模块时候,使用:
--add-modlue=/usr/local/nginx/modleu_name_dir
3. 编译
make
目标文件:编译的主目录下的 objs/nginx
4.1 停服务升级
- 停服务
- 备份原来的主程序(/usr/local/nginx/sbin/nginx)
- 拷贝编译好的主程序到安装的目录下
cp objs/nginx /usr/local/nginx/sbin/
- 测试
/usr/local/nginx/sbin/nginx -V
- 启动服务
/usr/local/nginx/sbin/nginx
4.2 不停服务
- 备份原来的主程序(/usr/local/nginx/sbin/nginx)
mv /usr/local/nginx/sbin/nginx{
,.bak} #nginx.bak
- 拷贝编译好的主程序到安装的目录下
cp objs/nginx /usr/local/nginx/sbin/
- 执行升级操作
- 手动(自己写命令发信号)
- kill -USR2 `cat /var/run/nginx.pid`
# 由原来的主进程产生一个新的主进程,
之后由这个新的主进程产生自己的新的工作进程
由新的工作进程接收新的 web 请求
- kill -WINCH `cat /var/run/nginx.pid.old`
# 给老的主进程发送信号,让其控制自己的原来的工作进程
优雅退出
此时,老的工作进程就会有序退出
- kill -QUIT `cat /var/run/nginx.pid.old`
# 给老的主进程发送信号,让其退出。
- 自动
在自己编译的主目录下执行如下命令即可:
make upgrade
条件是:之前的 Nginx启动方式需要是使用绝对路径
5. 淘宝团队开发的主动的后端服务健康检查模块
upstream 配置块中使用
http1.0
HEAD 请求方法
nginx 性能优化
当我需要进行性能优化时,说明我们服务器无法满足日益增长的业务,需要从以下几个方面进行探讨
1、当前系统结构瓶颈
首先需要了解的是当前系统瓶颈,用的是什么,跑的是什么业务。里面的服务是什么样子,每个服务最大支持多少并发。
可以通过查看当前cpu负荷,内存使用率,来做简单判断。还可以通过操作系统的一些工具来判断当前系统性能瓶颈,如分析对应的日志,查看请求数量。也可以通过nginx http_stub_status_module模块来查看对应的连接数,总握手次数,总请求数。
2、了解业务模式
虽然我们是在做性能优化,但还是要熟悉业务,最终目的都是为业务服务的。我们要了解每一个接口业务类型是什么样的业务,比如电子商务抢购模式,这种情况平时流量会很小,但是到了抢购时间,流量一下子就会猛涨。也要了解系统层级结构,每一层在中间层做的是代理还是动静分离,还是后台进行直接服务。
3、性能与安全
性能与安全也是一个需要考虑的因素,往往大家注重性能忽略安全或注重安全又忽略性能。比如说我们在设计防火墙时,如果规则过于全面肯定会对性能方面有影响。如果对性能过于注重在安全方面肯定会留下很大隐患。所以大家要评估好两者的关系,把握好两者的孰重孰轻,以及整体的相关性。权衡好对应的点。
4、系统与nginx性能优化
对相关的系统瓶颈及现状有了一定的了解之后,就可以根据影响性能方面做一个全体的评估和优化。
- 网络(网络流量、是否有丢包,网络的稳定性都会影响用户请求)
- 系统(系统负载、内存使用率、系统的稳定性、硬件磁盘是否有损坏)
- 服务(连接优化、内核性能优化、http服务请求优化都可以在nginx中根据业务来进行设置)
- 程序(接口性能、处理请求速度、每个程序的执行效率)
- 数据库、底层服务
上面列举出来每一级都会有关联,也会影响整体性能,这里主要关注的是nginx服务这一层。
1、文件句柄
在linux/unix操作系统中一切皆文件,我们的设备是文件,文件是文件,文件夹也是文件。当我们用户每发起一次请求,就会产生一个文件句柄。文件句柄可以简单的理解为
文件句柄就是一个索引
。文件句柄就会随着请求量的增多,进程调用频繁增加,那么产生的文件句柄也就会越多。
系统默认对文件句柄是有限制的,不可能会让一个进程无限制的调用句柄。因为系统资源是有限的,所以我们需要限制每一个服务能够使用多大的文件句柄。操作系统默认使用的文件句柄是1024个句柄。
2、设置方式
- 系统全局性修改
- 用户局部性修改
- 进程局部性修改
3、系统全局性修该和用户局部性修改
[root@nginx-server ~]# vim /etc/security/limits.conf
#* soft core 0
#* hard rss 10000
#@student hard nproc 20
#@faculty soft nproc 20
#@faculty hard nproc 50
#ftp hard nproc 0
#@student - maxlogins 4
#root只是针对root这个用户来限制,soft只是发提醒,操作系统不会强制限制,一般的站点设置为一万左右就ok了
root soft nofile 65535
root hard nofile 65535
# *代表通配符 所有的用户
* soft nofile 25535
* hard nofile 25535 #hard硬控制,到达设定值后,操作系统会采取机制对当前进程进行限制,这个时候请求就会受到影响
可以看到root
和*
,root代表是root用户,*代表的是所有用户,后面的数字就是文件句柄大小。大家可以根据个人业务来进行设置。
4、进程局部性修改
[root@nginx-server ~]# vim /etc/nginx/nginx.conf
user nginx; #运行nginx的用户。可以修改
worker_processes auto;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
worker_rlimit_nofile 65535; #进程限制
events {
worker_connections 1024; #一个worker进程的并发
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$http_user_agent' '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for" '
'"$args" "$request_uri"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
worker_rlimit_nofile
是在进程上面进行限制。
5、cpu的亲和配置
cpu的亲和能够使nginx对于不同的work工作进程绑定到不同的cpu上面去。就能够减少在work间不断切换cpu,来减少性能损耗。nginx 亲和配置[点击链接]
查看物理cpu
[root@nginx-server ~]# cat /proc/cpuinfo | grep "physical id" | sort|uniq | wc -l
查看cpu核心数
[root@nginx-server ~]# cat /proc/cpuinfo|grep "cpu cores"|uniq
查看cpu使用率
[root@nginx-server ~]#top #回车后按 1
6、配置worker_processes
[root@nginx-server ~]# vim /etc/nginx/nginx.conf
将刚才查看到自己cpu * cpu核心就是worker_processes
worker_processes 2; #根据自己cpu核心数配置/这里也可以设置为auto
7、cpu
通过下面命令查看nginx进程配置在哪个核上
[root@nginx-server ~]# ps -eo pid,args,psr |grep [n]ginx
在nginx 1.9版本之后,就帮我们自动绑定了cpu;
worker_processes auto;
worker_cpu_affinity auto;
5、nginx通用配置优化
[root@localhost ~]# cat /etc/nginx/nginx.conf
#将nginx进程设置为普通用户,为了安全考虑
user nginx;
#当前启动的worker进程,官方建议是与系统核心数一致
worker_processes auto;
#方式一,就是自动分配绑定
worker_cpu_affinity auto;
#日志配置成warn
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
#针对 nginx 句柄的文件限制
worker_rlimit_nofile 65535;
#事件模型
events {
#使用epoll内核模型
use epoll;
#每一个进程可以处理多少个连接,如果是多核可以将连接数调高 worker_processes * 1024
worker_connections 10240;
}
http {
server_tokens off; #隐藏nginx的版本号
# include /etc/nginx/mime.types;
# default_type application/octet-stream;
# charset utf-8; #设置字符集,服务端返回给客户端报文的时候,Nginx强行将报文转码为utf-8
#设置日志输出格式,根据自己的情况设置
log_format main '$http_user_agent' '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for" '
'"$args" "$request_uri"';
access_log /var/log/nginx/access.log main;
sendfile on; #对静态资源的处理比较有效
#tcp_nopush on; #如果做静态资源服务器可以打开
keepalive_timeout 65 30;
#65 表示服务端主动断开链接
#30 表示客户端主动断开链接
include /etc/nginx/conf.d/*.conf;
########
#Gzip module
gzip on; #文件压缩默认可以打开.告诉nginx采用gzip压缩的形式发送数据。这将会减少发送的数据量。
gzip_disable "MSIE [1-6]\."; #对于有些浏览器不能识别压缩,需要过滤如ie6
gzip_http_version 1.1; #设置识别 http 协议版本,默认是 1.1
server{
listen 80;
location / {
root /html;
index index.html;
}
}
}
6、扩展 ulimit
命令
# -a 显示目前资源限制的设定。
• -c <core文件上限> 设定core文件的最大值,单位为区块。
• -d <数据节区大小> 程序数据节区的最大值,单位为KB。
• -f <文件大小> shell所能建立的最大文件,单位为区块。
• -H 设定资源的硬性限制,也就是管理员所设下的限制。
• -m <内存大小> 指定可使用内存的上限,单位为KB。
# -n <文件数目> 指定同一时间最多可开启的文件数。
• -p <缓冲区大小> 指定管道缓冲区的大小,单位512字节。
• -s <堆叠大小> 指定堆叠的上限,单位为KB。
• -S 设定资源的弹性限制。
• -t <CPU时间> 指定CPU使用时间的上限,单位为秒。
• -u <程序数目> 用户最多可开启的程序数目。
• -v <虚拟内存大小> 指定可使用的虚拟内存上限,单位为KB
1 ulimit -a 显示系统资源的设置
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 63154
max locked memory (kbytes, -l) 64
max memory size (kbytes, -m) unlimited
open files (-n) 1024
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 8192
cpu time (seconds, -t) unlimited
max user processes (-u) 63154
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
2、ulimit -n 65535 #修改打开句柄数 —临时
7、ab接口压力测试工具
ab是Apache超文本传输协议(HTTP)的性能测试工具。其设计意图是描绘当前所安装的Apache的执行性能,主要是显示你安装的Apache每秒可以处理多少个请求。
[root@nginx-server ~]# yum -y install httpd-tools
[root@nginx-server ~]# ab -n 2000 -c 2 http://127.0.0.1/
-n 总的请求数
-c 并发数
-k 是否开启长连接
-X:指定使用的端口号,例如:"126.10.10.3:88"
1 参数选项
-n:即requests,用于指定压力测试总共的执行次数
-c:即concurrency,用于指定的并发数
-t:即timelimit,等待响应的最大时间(单位:秒)
-b:即windowsize,TCP发送/接收的缓冲大小(单位:字节)
-p:即postfile,发送POST请求时需要上传的文件,此外还必须设置-T参数
-u:即putfile,发送PUT请求时需要上传的文件,此外还必须设置-T参数
-T:即content-type,用于设置Content-Type请求头信息,例如:application/x-www-form-urlencoded,默认值为text/plain
-v:即verbosity,指定打印帮助信息的冗余级别
-w:以HTML表格形式打印结果
-i:使用HEAD请求代替GET请求
-x:插入字符串作为table标签的属性
-y:插入字符串作为tr标签的属性
-z:插入字符串作为td标签的属性
-C:添加cookie信息,例如:"Apache=1234"(可以重复该参数选项以添加多个)
-H:添加任意的请求头,例如:"Accept-Encoding: gzip",请求头将会添加在现有的多个请求头之后(可以重复该参数选项以添加多个)
-A:添加一个基本的网络认证信息,用户名和密码之间用英文冒号隔开
-P:添加一个基本的代理认证信息,用户名和密码之间用英文冒号隔开
-X:指定使用的和端口号,例如:"126.10.10.3:88"
-V:打印版本号并退出
-k:使用HTTP的KeepAlive特性
-d:不显示百分比
-S:不显示预估和警告信息
-g:输出结果信息到gnuplot格式的文件中
-e:输出结果信息到CSV格式的文件中
-r:指定接收到错误信息时不退出程序
-H:显示用法信息,其实就是ab -help
2 内容解释
Server Software: nginx/1.10.2 (服务器软件名称及版本信息)
Server Hostname: 192.168.1.106(服务器主机名)
Server Port: 80 (服务器端口)
Document Path: /index1.html. (供测试的URL路径)
Document Length: 3721 bytes (供测试的URL返回的文档大小)
Concurrency Level: 1000 (并发数)
Time taken for tests: 2.327 seconds (压力测试消耗的总时间)
Complete requests: 5000 (的总次数)
Failed requests: 688 (失败的请求数)
Write errors: 0 (网络连接写入错误数)
Total transferred: 17402975 bytes (传输的总数据量)
HTML transferred: 16275725 bytes (HTML文档的总数据量)
Requests per second: 2148.98 [#/sec] (mean) (平均每秒的请求数) 这个是非常重要的参数数值,服务器的吞吐量 #计算公式:总请求数 / 处理这些请求的总完成时间
Time per request: 465.338 [ms] (mean) (所有并发用户(这里是1000)都请求一次的平均时间)
Time request: 0.247 [ms] (mean, across all concurrent requests) (单个用户请求一次的平均时间)
Transfer rate: 7304.41 [Kbytes/sec] received 每秒获取的数据长度 (传输速率,单位:KB/s)
...
Percentage of the requests served within a certain time (ms)
50% 347 ## 50%的请求在347ms内返回
66% 401 ## 60%的请求在401ms内返回
75% 431
80% 516
90% 600
95% 846
98% 1571
99% 1593
100% 1619 (longest request)
3 示例演示
注意事项
● 测试机与被测试机要分开
● 不要对线上的服务器做压力测试
● 观察测试工具ab所在机器,以及被测试的机器的CPU、内存、网络等都不超过最高限度的75%
[root@nginx-server ~]# ab -n 200000 -c 2000 http://127.0.0.1/
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 127.0.0.1 (be patient).....done
Server Software: nginx
Server Hostname: 127.0.0.1
Server Port: 80
Document Path: /
Document Length: 146 bytes
Concurrency Level: 2000
Time taken for tests: 21.074 seconds
Complete requests: 200000
Failed requests: 0
Write errors: 0
Non-2xx responses: 200000
Total transferred: 57800000 bytes
HTML transferred: 29200000 bytes
Requests per second: 9490.46 [#/sec] (mean)
Time per request: 210.738 [ms] (mean)
Time per request: 0.105 [ms] (mean, across all concurrent requests)
Transfer rate: 2678.46 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 174 651.8 3 15039
Processing: 4 16 61.0 10 2644
Waiting: 0 13 60.9 8 2644
Total: 9 190 662.9 14 15241
Percentage of the requests served within a certain time (ms)
50% 14
66% 16
75% 18
80% 20
90% 1016
95% 1027
98% 1829
99% 3026
100% 15241 (longest request)
Tomcat 运维
一、系统环境说明
[root@localhost ~]# getenforce
Disabled
[root@localhost ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
Active: inactive (dead)
Docs: man:firewalld(1)
二、安装JDK
从官网下载 https://www.oracle.com/java/technologies/javase-jdk15-downloads.html
[root@localhost ~]# tar xf jdk-8u151-linux-x64.gz -C /usr/local/
[root@localhost ~]# cd /usr/local/
[root@localhost local]# mv jdk1.8.0_151/ java
[root@localhost local]# vim /etc/profile
export JAVA_HOME=/usr/local/java #指定java安装目录
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH #用于指定java系统查找命令的路径
export CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$JAVA_HOME/lib/tools.jar #类的路径,在编译运行java程序时,如果有调用到其他类的时候,在classpath中寻找需要的类。
[root@localhost local]# source /etc/profile
[root@localhost ~]# java -version
java version "1.8.0_181"
Java(TM) SE Runtime Environment (build 1.8.0_181-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.181-b13, mixed mode)
三、安装Tomcat
[root@localhost ~]# wget https://mirrors.bfsu.edu.cn/apache/tomcat/tomcat-8/v8.5.61/bin/apache-tomcat-8.5.61.tar.gz
[root@localhost ~]# tar -xf apache-tomcat-8.5.61.tar.gz
[root@localhost ~]# mv apache-tomcat-8.5.61/ /usr/local/tomcat
[root@localhost ~]# ls /usr/local/tomcat/
bin conf lib logs README.md RUNNING.txt webapps
BUILDING.txt CONTRIBUTING.md LICENSE NOTICE RELEASE-NOTES temp work
[root@localhost ~]# tomcatpath='export TOMCAT_HOME=/usr/local/tomcat/'
[root@localhost ~]# echo $tomcatpath > /etc/profile.d/tomcat.sh
[root@localhost ~]# source /etc/profile.d/tomcat.sh
四、查看tomcat是否安装成功:
[root@localhost tomcat]# /usr/local/tomcat/bin/version.sh
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr/local/java
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/var/local/tomcat/bin/tomcat-juli.jar
Using CATALINA_OPTS:
NOTE: Picked up JDK_JAVA_OPTIONS: --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED
Server version: Apache Tomcat/8.5.61
Server built: Dec 3 2020 14:03:28 UTC
Server number: 8.5.61.0
OS Name: Linux
OS Version: 3.10.0-1127.19.1.el7.x86_64
Architecture: amd64
JVM Version: 15.0.1+9-18
JVM Vendor: Oracle Corporation
五、Tomcat目录介绍
1、tomcat主目录介绍
[root@localhost ~]# cd /usr/local/tomcat
[root@localhost tomcat]# /yum install -y tree
[root@localhost tomcat]# /tree
.
├── bin #存放tomcat的管理脚本
├── BUILDING.txt
├── conf #tomcat的配置文件
├── CONTRIBUTING.md
├── lib #web应用调用的jar包存放路径
├── LICENSE
├── logs #tomcat日志存放目录,catalin.out日志为只要输出日志
├── NOTICE
├── README.md
├── RELEASE-NOTES
├── RUNNING.txt
├── temp #存放临时文件
├── webapps #默认网站发布目录
└── work #存放编译生产的.java与.class文件
7 directories, 7 files
2、webapps目录介绍
[root@localhost tomcat]# cd webapps/
[root@localhost webapps]# tree
.
├── docs #tomcat的帮助文档
├── examples #web应用实例
├── host-manager #主机管理
├── manager #管理
└── ROOT #默认站点根目录
5 directories, 0 files
3、Tomcat配置文件目录介绍(conf)
[root@localhost webapps]# cd ../conf/
[root@localhost conf]# tree
.
├── Catalina
├── catalina.policy
├── catalina.properties
├── context.xml
├── logging.properties
├── logs
├── server.xml # tomcat 主配置文件
├── server.xml.bak
├── server.xml.bak2
├── tomcat-users.xml # tomcat 管理用户配置文件
├── tomcat-users.xsd
└── web.xml
2 directories, 10 files
4、Tomcat的管理
启动程序
/usr/local/tomcat/bin/startup.sh #启动
关闭程序
/usr/local/tomcat/bin/shutdown.sh #关闭
启动
[root@localhost /]# cd /usr/local/tomcat/
[root@localhost tomcat]# ./bin/startup.sh
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr/local/java
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/var/local/tomcat/bin/tomcat-juli.jar
Using CATALINA_OPTS:
Tomcat started.
检查tomcat是否启动正常
[root@localhost bin]# yum -y install netstat
[root@localhost bin]# netstat -lntp |grep java
tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN 15246/java
tcp 0 0 127.0.0.1:8005 0.0.0.0:* LISTEN 15246/java
浏览器可以访问
http://192.168.116.155:8080/
端口
8005
:这个端口负责监听关闭Tomcat的请求
shutdown
:向 8005 端口发送的关闭服务器的命令字符串。
8080
: 建立http也就是客户端访问连接用。可以修改
8009
: 与其他http服务通信接口。需要修改 conf/server.xml 文件中的如下配置
<Connector protocol="AJP/1.3"
address="::1"
port="8009"
redirectPort="8443" />
查看日志
[root@localhost bin]# tail -f /var//local/tomcat/logs/catalina.out
六、WEB站点部署
上线的代码有两种方式:
第一种方式是直接将程序目录放在webapps目录下面。
第二种方式是使用开发工具将程序打包成war包,然后上传到webapps目录下面。
一、使用war包部署web站点
[root@localhost ~]# pwd
/root
下载jenkins的war包
[root@localhost ~]# wget http://updates.jenkins-ci.org/download/war/2.129/jenkins.war
[root@localhost ~]# ls
jenkins.war
[root@localhost ~]# cd /usr/local/tomcat/
[root@localhost tomcat]# cp -r webapps/ /opt/
[root@localhost tomcat]# cd webapps/
[root@localhost webapps]# ls
docs examples host-manager manager ROOT
[root@localhost webapps]# rm -rf *
[root@localhost webapps]# cp /root/jenkins.war .
[root@localhost webapps]# ../bin/startup.sh
Using CATALINA_BASE: /usr/local/tomcat/
Using CATALINA_HOME: /usr/local/tomcat/
Using CATALINA_TMPDIR:/usr/local/tomcat/temp
Using JRE_HOME: /usr/local/java
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/var/local/tomcat/bin/tomcat-juli.jar
Using CATALINA_OPTS:
Tomcat started.
[root@localhost webapps]# ls
jenkins jenkins.war
二、手动解压,完成安装
[root@localhost webapps]# ../bin/shutdown.sh #关闭tomcat
[root@java-tomcat1 ~]# cd /usr/local/tomcat/webapps/
[root@localhost webapps]# rm -rf *
[root@localhost webapps]# mkdir ROOT #创建一个ROOT目录存放war包
[root@localhost webapps]# ls
ROOT
[root@localhost webapps]# cd ROOT/
[root@localhost ROOT]# cp /root/jenkins.war .
[root@localhost ROOT]# unzip jenkins.war
[root@localhost ROOT]# ls
bootstrap jenkins.war MainDialog$1.class
ColorFormatter.class JNLPMain.class MainDialog.class
css jsbundles Main$FileAndDescription.class
dc-license.txt LogFileOutputStream$1.class META-INF
executable LogFileOutputStream$2.class robots.txt
favicon.ico LogFileOutputStream.class scripts
help Main.class WEB-INF
images MainDialog$1$1.class winstone.jar
[root@localhost ROOT]# cd /var/local/tomcat/webapps/
[root@localhost webapps]# ../bin/startup.sh
Using CATALINA_BASE: /var/local/tomcat
Using CATALINA_HOME: /var/local/tomcat
Using CATALINA_TMPDIR: /var/local/tomcat/temp
Using JRE_HOME: /usr/local/java
Using CLASSPATH: /var/local/tomcat/bin/bootstrap.jar:/var/local/tomcat/bin/tomcat-juli.jar
Using CATALINA_OPTS:
Tomcat started.
[root@localhost webapps]# cat /root/.jenkins/secrets/initialAdminPassword
f77d2da6c4b04eb5a6eacd14e420ee01
#如果输入密码404 就直接输入 http://192.168.116.155:8080/
三、部署开源站点(jspgou商城)
安装配置数据库
[root@localhost ~]# wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
[root@localhost ~]# rpm -ivh mysql80-community-release-el7-3.noarch.rpm
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# vim mysql-community.repo
# Enable to use MySQL 5.7
[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[mysql80-community]
name=MySQL 8.0 Community Server
baseurl=http://repo.mysql.com/yum/mysql-8.0-community/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[root@localhost yum.repos.d]# yum -y install mysql-server mysql
[root@localhost yum.repos.d]# cd
[root@localhost ~]# systemctl start mysqld
[root@localhost ~]# systemctl enable mysqld
查找密码并修改密码
[root@localhost ~]# grep pass /var/log/mysqld.log #过滤查找密码
2020-12-22T09:54:04.255280Z 1 [Note] A temporary password is generated for root@localhost: 50Ra_Tb=?JkO
[root@localhost ~]# mysqladmin -u root -p'50Ra_Tb=?JkO' password 'Neko@123' #修改密码
配置数据库
[root@localhost ~]# mysql -u root -p'Neko@123'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.32 MySQL Community Server (GPL)
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> create database jspgou default charset=utf8; #创建数据库设置字符集
Query OK, 1 row affected (0.00 sec)
mysql> \q
Bye
四、jspgou商城上线
上传jspgou商城的代码
[root@localhost ~]# unzip jspgouV6-ROOT.zip
[root@localhost ~]# cp -r ROOT/ /usr/local/tomcat/webapps/
[root@localhost ~]# cd /usr/local/tomcat/webapps/
[root@localhost webapps]# ls
jenkins jenkins.war ROOT
[root@localhost webapps]# vim ROOT/WEB-INF/config/jdbc.properties
#mysql\u914d\u7f6e
jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://127.0.0.1:3306/jspgou?characterEncoding=UTF-8
jdbc.username=root
jdbc.password=Neko@123
配置数据库连接----jdbc
将数据导入数据库:
[root@localhost ~]# cd DB/
[root@localhost DB]# ls
jspgou.sql
[root@localhost DB]# mysql -uroot -pNeko@123 -D jspgou < jspgou.sql
[root@localhost DB]# vim /etc/my.cnf #添加sql_mod
sql_mode=STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUB
explicit_defaults_for_timestamp=1
[root@localhost DB]# systemctl restart mysqld
[root@localhost DB]# mysql -uroot -p'Neko@123' -D jspgou < jspgou.sql
[root@localhost DB]# /usr/local/tomcat/bin/startup.sh
[root@localhost DB]# netstat -lntp