服务器之家:专注于服务器技术及软件下载分享
分类导航

PHP教程|ASP.NET教程|JAVA教程|ASP教程|编程技术|正则表达式|C/C++|IOS|C#|Swift|Android|JavaScript|易语言|

服务器之家 - 编程语言 - JAVA教程 - 搭建JavaWeb服务器步骤详解

搭建JavaWeb服务器步骤详解

2021-04-05 13:46代码风云 JAVA教程

本篇文章主要给大家详细分享了搭建JavaWeb服务器的详细步骤以及用到的代码,对此有需要的朋友可以跟着学习下。

1、安装jdk7

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
//检查jdk是否已经安装
[root@iZwz9catu2mrq92b07d1d0Z ~]# yum list installed | grep java
java-1.7.0-openjdk.x86_64
java-1.7.0-openjdk-demo.x86_64
java-1.7.0-openjdk-devel.x86_64
java-1.7.0-openjdk-javadoc.noarch
java-1.7.0-openjdk-src.x86_64
tzdata-java.noarch   2017c-1.el6   @updates               
//卸载现有的jdk
[root@iZwz9catu2mrq92b07d1d0Z ~]# yum -y remove java-1.7.0*
//查看yum库中的Java安装包
[root@iZwz9catu2mrq92b07d1d0Z ~]# yum -C list java*
...
java-1.7.0-openjdk.x86_64                     1:1.7.0.151-2.6.11.0.el6_9              updates
java-1.7.0-openjdk-demo.x86_64                   1:1.7.0.151-2.6.11.0.el6_9              updates
java-1.7.0-openjdk-devel.x86_64                  1:1.7.0.151-2.6.11.0.el6_9              updates
java-1.7.0-openjdk-javadoc.noarch                 1:1.7.0.151-2.6.11.0.el6_9              updates
...
//安装jdk7
[root@iZwz9catu2mrq92b07d1d0Z ~]# yum -y install java-1.7.0*
//安装成功
[root@iZwz9catu2mrq92b07d1d0Z ~]# java -version
java version "1.7.0_151"
OpenJDK Runtime Environment (rhel-2.6.11.0.el6_9-x86_64 u151-b00)
OpenJDK 64-Bit Server VM (build 24.151-b00, mixed mode)

2、安装tomcat7

?
1
2
3
4
5
6
7
8
9
10
11
//从官网下载tomcat7
[cjh@iZwz9catu2mrq92b07d1d0Z ~]$ wget http://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-7/v7.0.82/bin/apache-tomcat-7.0.82.tar.gz
 
//检查压缩包文件
[cjh@iZwz9catu2mrq92b07d1d0Z ~]$ tar -ztvf apache-tomcat-7.0.82.tar.gz
 
//解压
[cjh@iZwz9catu2mrq92b07d1d0Z ~]$ tar -zxvf apache-tomcat-7.0.82.tar.gz
 
[cjh@iZwz9catu2mrq92b07d1d0Z ~]$ ls
apache-tomcat-7.0.82 apache-tomcat-7.0.82.tar.gz

注:当我们尝试启动tomcat时可能会遇到启动非常慢的情况,并且在启动日志中会看到类似以下的信息

?
1
2
<DATE> org.apache.catalina.util.SessionIdGenerator createSecureRandom
INFO: Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [5172] milliseconds.

关于本问题请参考官方文章末尾有说明 官方说明

问题说明:

Tomcat 7+ heavily relies on SecureRandom class to provide random values for its session ids and in other places. Depending on your JRE it can cause delays during startup if entropy source that is used to initialize SecureRandom is short of entropy

译:tomcat7+严重依赖SecureRandom类为会话ids和其它地方提供的随机值,这会导致启动过程出现延迟。

 

解决办法:

There is a way to configure JRE to use a non-blocking entropy source by setting the following system property: -Djava.security.egd=file:/dev/./urandom

译:添加jvm参数 -Djava.security.egd=file:/dev/./urandom

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
[cjh@iZwz9catu2mrq92b07d1d0Z bin]$ pwd
/home/cjh/apache-tomcat-7.0.82/bin
 
//在开头注释后面添加参数
[cjh@iZwz9catu2mrq92b07d1d0Z bin]$ vi catalina.sh
 
...
JAVA_OPTS="-Djava.security.egd=file:/dev/./urandom"
...
 
 
//查看jvm运行参数,参数已添加
[cjh@iZwz9catu2mrq92b07d1d0Z bin]$ jps -v
...
 
//重新运行tomcat,查看启动日志,启动耗时正常
...

3、安装反向代理nginx

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
//安装nginx
[root@iZwz9catu2mrq92b07d1d0Z ~]# yum -y install nginx
 
//安装完成后查看配置文件路径
[root@iZwz9catu2mrq92b07d1d0Z ~]# whereis nginx
 
//检查配置文件内容,可以发现包含了另一个路径下的配置文件组
[root@iZwz9catu2mrq92b07d1d0Z ~]# cat /etc/nginx/nginx.conf
 
...
include /etc/nginx/conf.d/*.conf;
...
 
//切换路径,检查文件组
[root@iZwz9catu2mrq92b07d1d0Z ~]# cd /etc/nginx/conf.d/
[root@iZwz9catu2mrq92b07d1d0Z conf.d]# ls -l | grep .conf
-rw-r--r-- 1 root root 408 Nov 22 17:59 default.conf
-rw-r--r-- 1 root root 686 Oct 31 2016 ssl.conf
-rw-r--r-- 1 root root 283 Oct 31 2016 virtual.conf
 
//修改default.conf
[root@iZwz9catu2mrq92b07d1d0Z conf.d]# vi default.conf
 
...
listen   端口号;
server_name 域名/ip;
...
 
//启动nginx
[root@iZwz9catu2mrq92b07d1d0Z conf.d]# chkconfig nginx on
[root@iZwz9catu2mrq92b07d1d0Z conf.d]# service nginx start
 
//在浏览器上访问域名或ip,显示nginx的欢迎页面即配置成功

4、安装MySQL

下载官方yum库

https://dev.mysql.com/downloads/repo/yum/

安装说明

https://dev.mysql.com/doc/mysql-yum-repo-quick-guide/en/

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
//下载MySQL Yum库
[root@iZwz9catu2mrq92b07d1d0Z ~]# wget https://repo.mysql.com//mysql57-community-release-el6-11.noarch.rpm
 
//安装yum库
[root@iZwz9catu2mrq92b07d1d0Z ~]# yum -y localinstall mysql57-community-release-el6-11.noarch.rpm
 
//检查库安装成功,默认已开启子库mysql57-community
[root@iZwz9catu2mrq92b07d1d0Z ~]# yum -C repolist enabled
 
//安装MySQL5.7
[root@iZwz9catu2mrq92b07d1d0Z ~]# yum -y install mysql-community-server
 
//启动服务
[root@iZwz9catu2mrq92b07d1d0Z yum.repos.d]# chkconfig mysqld on
[root@iZwz9catu2mrq92b07d1d0Z ~]# service mysqld start
Initializing MySQL database:                [ OK ]
Starting mysqld:                      [ OK ]

注:服务在初次启动时会进行初始化(仅5.7),超级用户会被创建,并且它的密码已被设置并存储在/var/log/mysqld.log,而非空

A superuser account 'root'@'localhost' is created. A password for the superuser is set and stored in the error log file. To reveal it, use the following command:

?
1
2
3
4
5
6
7
8
9
//x值为数据库用户root的密码
[root@iZwz9catu2mrq92b07d1d0Z ~]# cat /var/log/mysqld.log | grep password
2017-11-22T14:27:56.638229Z 1 [Note] A temporary password is generated for root@localhost: x
 
//进入成功
[root@iZwz9catu2mrq92b07d1d0Z ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
...

以上就是本次小编整理的关于搭建JavaWeb服务器的详细内容以及步骤,希望我们整理的内容对大家有所帮助,感谢大家对服务器之家的支持。

原文链接:http://www.cnblogs.com/cjh-notes/p/7868262.html

延伸 · 阅读

精彩推荐