这篇文章将为大家详细讲解有关如何搭建JavaWeb服务器,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。
站在用户的角度思考问题,与客户深入沟通,找到轮台网站设计与轮台网站推广的解决方案,凭借多年的经验,让设计与互联网技术结合,创造个性化、用户体验好的作品,建站类型包括:网站设计、成都网站制作、企业官网、英文网站、手机端网站、网站推广、域名与空间、虚拟空间、企业邮箱。业务覆盖轮台地区。1、安装jdk7
//检查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
//从官网下载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时可能会遇到启动非常慢的情况,并且在启动日志中会看到类似以下的信息
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
[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
//安装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/
//下载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:
//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服务器”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。