Vagrant搭建(Tomcat8+JDK7+MySQL5+dubbo)java
JDKmysql
tar -xzvf jdk-7u79-linux-x64.tar.gz
vim /home/vagrant/.bashrc
這裏由於我用的vagrant因此提示: linux
The program 'vim' can be found in the following packages: * vim * vim-gnome * vim-tiny * vim-athena * vim-gtk
* vim-nox Try: sudo apt-get install <selected package>
因此要先下載vim:web
sudo apt-get install vim
若是繼續報錯,或者根據URL鏈接不上: sql
sudo apt-get update
sudo apt-get install vim
最後再次嘗試:apache
vim /home/vagrant/.bashrc
進入vim編輯頁面,control或ctrl + d向下翻頁,至文件底部,鍵盤輸入i進入編輯模式,將如下添加上:
bootstrap
JAVA_HOME=/home/vagrant/soft/jdk1.8.0_25
PATH=$PATH:$JAVA_HOME/bin:$CATALINA_HOME/bin
export JAVA_HOME
export PATH
刷新配置文件,從新載入vim
source ~/.bashrc
驗證是否安裝成功瀏覽器
vagrant@precise64:~/soft/jdk1.7.0_79$ java -version
java version "1.7.0_79"
Java(TM) SE Runtime Environment (build 1.7.0_79-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode)
Tomcattomcat
tar -xzvf apache-tomcat-8.0.15.tar.gz
vim /home/vagrant/.bashrc
在文件尾部追加
CATALINA_HOME=/home/vagrant/soft/apache-tomcat-8.0.15
export CATALINA_HOME
保存文件,重載配置文件
source ~/.bashrc
驗證是否安裝成功
vagrant@precise64:~/soft/Tomcat8.0.28$ sh ./bin/startup.sh
Using CATALINA_BASE: /home/vagrant/soft/Tomcat8.0.28
Using CATALINA_HOME: /home/vagrant/soft/Tomcat8.0.28
Using CATALINA_TMPDIR: /home/vagrant/soft/Tomcat8.0.28/temp
Using JRE_HOME: /home/vagrant/soft/jdk1.7.0_79
Using CLASSPATH: /home/vagrant/soft/Tomcat8.0.28/bin/bootstrap.jar:/home/vagrant/soft/Tomcat8.0.28/bin/tomcat-juli.jar
Tomcat started.
補充幾個Tomcat經常使用命令:
1.直接啓動
./startup.sh
2.做爲服務啓動
nohup ./startup.sh &
3.控制檯動態輸出方式啓動,就是window下啓動彈出的DOS窗口
./catalina.sh run Ctrl/control+c
三種啓動方式的比較:
1-3 啓動有弊端。當客服端鏈接斷開的時候,tomcat服務也會當即中止,經過方式二能夠做爲Linux服務一直運行
1-2 啓動時,其日誌會寫到相應的日誌文件中,而不能動態地查看tomcat控制檯的輸出信息與錯誤狀況,經過方式三能夠以控制檯模式啓動tomcat服務並查看控制檯輸出信息
Tomcat運行是jvm內存分配:
有時候會遇到內存溢出的問題
⑴開發環境下在myeclipse中配置
-Xms256m -Xmx512m -XX:NewSize=64m -XX:MaxNewSize=128m -XX:PermSize=512m -XX:MaxPermSize=512m
⑵線上環境(直接經過catalina或startup命令行的方式啓動)
①Linux下:catalina.sh
# OS specific support. $var _must_ be set to either true or false.在該註釋以後加下面一行
JAVA_OPTS="-server -Xms256m -Xmx512m -XX:NewSize=64m -XX:MaxNewSize=128m -XX:PermSize=512m -XX:MaxPermSize=512m"
②Windows下:cattalina.bat
rem Guess CATALINA_HOME if not defined 在該註釋以後加下面一行
set JAVA_OPTS=-Xms256m -Xmx512m -XX:NewSize=64m -XX:MaxNewSize=128m -XX:PermSize=512m -XX:MaxPermSize=512m
4.打開瀏覽器
若是是在主機上,沒問題,如今已經能打開了,但若是用vagrant搭建的虛擬機,那麼還須要如下操做:
編輯Vagrantfile文件:
# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine. In the example below,
# accessing "localhost:8080" will access port 80 on the guest machine.
config.vm.network "forwarded_port", guest: 80, host: 8080
# Create a private network, which allows host-only access to the machine
# using a specific IP.
config.vm.network "private_network", ip: "192.168.33.10"
其中「forwarded_port」表示將虛擬機的80端口映射至主機的8080端口,也就是說,若是虛擬機的Tomcat端口默認爲8080,那麼在主機瀏覽器訪問虛擬機IP(「private_network」設置):8080便可訪問到Tomcat webapp
設置後,重啓虛擬機:
vagrant reload
MySQL
sudo apt-get install mysql-server
開始下載。。
mysql -u root -p
遇到的問題:
1.vim輸入中文亂碼:
1)修改vim配置文件:
vim ~/.vimrc
2)添加如下內容:
set fileencodings=utf-8,ucs-bom,gb18030,gbk,gb2312,cp936
set termencoding=utf-8
set encoding=utf-8
2.啓動Tomcat時,提示:
-bash: ./startup.sh: Permission denied
解決:
1.cd ./bin
2.chmod u+x *.sh