這篇文章將為大家詳細講解有關(guān)如何搭建JavaWeb服務(wù)器,小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。
成都創(chuàng)新互聯(lián)專注為客戶提供全方位的互聯(lián)網(wǎng)綜合服務(wù),包含不限于網(wǎng)站設(shè)計制作、成都做網(wǎng)站、酉陽土家族苗族網(wǎng)絡(luò)推廣、微信小程序定制開發(fā)、酉陽土家族苗族網(wǎng)絡(luò)營銷、酉陽土家族苗族企業(yè)策劃、酉陽土家族苗族品牌公關(guān)、搜索引擎seo、人物專訪、企業(yè)宣傳片、企業(yè)代運營等,從售前售中售后,我們都將竭誠為您服務(wù),您的肯定,是我們最大的嘉獎;成都創(chuàng)新互聯(lián)為所有大學(xué)生創(chuàng)業(yè)者提供酉陽土家族苗族建站搭建服務(wù),24小時服務(wù)熱線:18980820575,官方網(wǎng)址:www.cdcxhl.com
1、安裝jdk7
//檢查jdk是否已經(jīng)安裝 [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 //卸載現(xiàn)有的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
//從官網(wǎng)下載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
注:當(dāng)我們嘗試啟動tomcat時可能會遇到啟動非常慢的情況,并且在啟動日志中會看到類似以下的信息
org.apache.catalina.util.SessionIdGenerator createSecureRandom INFO: Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [5172] milliseconds.
關(guān)于本問題請參考官方文章末尾有說明 官方說明
問題說明:
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+嚴(yán)重依賴SecureRandom類為會話ids和其它地方提供的隨機值,這會導(dǎo)致啟動過程出現(xiàn)延遲。
解決辦法:
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參數(shù) -Djava.security.egd=file:/dev/./urandom
[cjh@iZwz9catu2mrq92b07d1d0Z bin]$ pwd /home/cjh/apache-tomcat-7.0.82/bin //在開頭注釋后面添加參數(shù) [cjh@iZwz9catu2mrq92b07d1d0Z bin]$ vi catalina.sh ... JAVA_OPTS="-Djava.security.egd=file:/dev/./urandom" ... //查看jvm運行參數(shù),參數(shù)已添加 [cjh@iZwz9catu2mrq92b07d1d0Z bin]$ jps -v ... //重新運行tomcat,查看啟動日志,啟動耗時正常 ...
3、安裝反向代理nginx
//安裝nginx [root@iZwz9catu2mrq92b07d1d0Z ~]# yum -y install nginx //安裝完成后查看配置文件路徑 [root@iZwz9catu2mrq92b07d1d0Z ~]# whereis nginx //檢查配置文件內(nèi)容,可以發(fā)現(xiàn)包含了另一個路徑下的配置文件組 [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
下載官方y(tǒng)um庫
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 //檢查庫安裝成功,默認(rèn)已開啟子庫mysql57-community [root@iZwz9catu2mrq92b07d1d0Z ~]# yum -C repolist enabled //安裝MySQL5.7 [root@iZwz9catu2mrq92b07d1d0Z ~]# yum -y install mysql-community-server //啟動服務(wù) [root@iZwz9catu2mrq92b07d1d0Z yum.repos.d]# chkconfig mysqld on [root@iZwz9catu2mrq92b07d1d0Z ~]# service mysqld start Initializing MySQL database: [ OK ] Starting mysqld: [ OK ]
注:服務(wù)在初次啟動時會進行初始化(僅5.7),超級用戶會被創(chuàng)建,并且它的密碼已被設(shè)置并存儲在/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值為數(shù)據(jù)庫用戶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. ...
關(guān)于“如何搭建JavaWeb服務(wù)器”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,使各位可以學(xué)到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。