Ubuntu14.04 Tomcat 安裝過程記錄java
檢查java的版本mysql
zhousp@ubuntu:~$ sudo java -version web
[sudo] password for zhousp: sql
java version "1.7.0_95" 數據庫
OpenJDK Runtime Environment (IcedTea 2.6.4) (7u95-2.6.4-0ubuntu0.14.04.2) apache
OpenJDK 64-Bit Server VM (build 24.95-b01, mixed mode) 編程
zhousp@ubuntu:~$ bootstrap
查找java目錄ubuntu
zhousp@ubuntu:~$ whereis java vim
java: /usr/bin/java /etc/java /usr/lib/java /usr/bin/X11/java /usr/share/java /usr/share/man/man1/java.1.gz
zhousp@ubuntu:~$ which java
/usr/bin/java
設置環境變量
zhousp@ubuntu:~$ echo $JAVA_HOME
空行-表示沒有設定該環境變量
zhousp@ubuntu:~$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
zhousp@ubuntu:~$ JAVA_HOME=/usr/bin/java;export JAVA_HOME
zhousp@ubuntu:~$ echo $JAVA_HOME
/usr/bin/java
zhousp@ubuntu:~$
安裝Tomcat並設置環境變量
zhousp@ubuntu:~/Downloads$ sudo cp -r apache-tomcat-8.0.33 /home/tomcat
zhousp@ubuntu:~/Downloads$ cd /home/
zhousp@ubuntu:/home$ ls
tomcat zhousp
zhousp@ubuntu:/home$ cd tomcat
zhousp@ubuntu:/home/tomcat$
zhousp@ubuntu:/home/tomcat$ ls
bin conf lib LICENSE logs NOTICE RELEASE-NOTES RUNNING.txt temp webapps work
zhousp@ubuntu:/home/tomcat$ cd ~
zhousp@ubuntu:~$ CATALINA_HOME=/home/tomcat;export CATALINA_HOME
zhousp@ubuntu:~$ echo $CATALINA_HOME
/home/tomcat
zhousp@ubuntu:~$
解決conf文件夾訪問權限不夠的問題
zhousp@ubuntu:/home$ sudo chmod -R 755 tomcat
zhousp@ubuntu:/home$ ll
total 16
drwxr-xr-x 4 root root 4096 4月 22 12:03 ./
drwxr-xr-x 23 root root 4096 4月 23 11:32 ../
drwxr-xr-x 9 root root 4096 4月 22 12:03 tomcat/
drwxr-xr-x 31 zhousp zhousp 4096 4月 23 21:30 zhousp/
zhousp@ubuntu:/home$ cd ./tomcat
zhousp@ubuntu:/home/tomcat$ ls
bin lib logs RELEASE-NOTES temp work
conf LICENSE NOTICE RUNNING.txt webapps
zhousp@ubuntu:/home/tomcat$ ll
total 120
drwxr-xr-x 9 root root 4096 4月 22 12:03 ./
drwxr-xr-x 4 root root 4096 4月 22 12:03 ../
drwxr-xr-x 2 root root 4096 4月 23 11:48 bin/
drwxr-xr-x 3 root root 4096 4月 22 12:14 conf/
drwxr-xr-x 2 root root 4096 4月 22 12:03 lib/
-rwxr-xr-x 1 root root 57011 4月 22 12:03 LICENSE*
drwxr-xr-x 2 root root 4096 4月 23 10:39 logs/
-rwxr-xr-x 1 root root 1444 4月 22 12:03 NOTICE*
-rwxr-xr-x 1 root root 6739 4月 22 12:03 RELEASE-NOTES*
-rwxr-xr-x 1 root root 16195 4月 22 12:03 RUNNING.txt*
drwxr-xr-x 2 root root 4096 4月 22 12:03 temp/
drwxr-xr-x 7 root root 4096 4月 22 12:03 webapps/
drwxr-xr-x 3 root root 4096 4月 22 12:14 work/
zhousp@ubuntu:/home/tomcat$
啓動Tomcat
(使用eclipse 搭建java web編程環境時,不須要啓動Tomcat,eclipse運行程序時,會本身啓動Tomcat。因此,做爲系統服務啓動Tomcat是爲了講系統做爲web服務器,對外提供web服務,而不是啓動以後,eclipse纔可以連接到服務器。這一點和程序連接mysql服務器的概念大相徑庭。)
zhousp@ubuntu:/home/tomcat/bin$ sudo su
root@ubuntu:/home/tomcat/bin# sh startup.sh
Using CATALINA_BASE: /home/tomcat
Using CATALINA_HOME: /home/tomcat
Using CATALINA_TMPDIR: /home/tomcat/temp
Using JRE_HOME: /usr
Using CLASSPATH: /home/tomcat/bin/bootstrap.jar:/home/tomcat/bin/tomcat-juli.jar
Tomcat started.
root@ubuntu:/home/tomcat/bin#
ubuntu下設置Tomcat服務自動啓動
root@ubuntu:/home/tomcat/bin# cp catalina.sh /etc/init.d/
root@ubuntu:/home/tomcat/bin# cd /etc/init.d/
root@ubuntu:/etc/init.d# mv catalina.sh tomcat
rroot@ubuntu:/etc/init.d# ls tomcat
tomcat
root@ubuntu:/etc/init.d# vim tomcat
添加環境變量:
JAVA_HOME=/home/tomcat
CATALINA_HOME=/usr/bin/java
root@ubuntu:/etc/init.d# service tomcat start
Using CATALINA_BASE: /home/tomcat
Using CATALINA_HOME: /home/tomcat
Using CATALINA_TMPDIR: /home/tomcat/temp
Using JRE_HOME: /usr/bin/java
Using CLASSPATH: /home/tomcat/bin/bootstrap.jar:/home/tomcat/bin/tomcat-juli.jar
Tomcat started.
自動啓動命令:
root@ubuntu:/# chmod 755 /etc/init.d/tomcat
root@ubuntu:/# update-rc.d -f tomcat defaults
update-rc.d: warning: /etc/init.d/tomcat missing LSB information
update-rc.d: see <http://wiki.debian.org/LSBInitScripts>
Adding system startup for /etc/init.d/tomcat ...
/etc/rc0.d/K20tomcat -> ../init.d/tomcat
/etc/rc1.d/K20tomcat -> ../init.d/tomcat
/etc/rc6.d/K20tomcat -> ../init.d/tomcat
/etc/rc2.d/S20tomcat -> ../init.d/tomcat
/etc/rc3.d/S20tomcat -> ../init.d/tomcat
/etc/rc4.d/S20tomcat -> ../init.d/tomcat
/etc/rc5.d/S20tomcat -> ../init.d/tomcat
root@ubuntu:/#
(刪除自動啓動)
zhousp@ubuntu:~$ update-rc.d -f tomcat remove
Removing any system startup links for /etc/init.d/tomcat ...
/etc/rc0.d/K20tomcat
update-rc.d: unlink: Permission denied
zhousp@ubuntu:~$ sudo update-rc.d -f tomcat remove
[sudo] password for zhousp:
Removing any system startup links for /etc/init.d/tomcat ...
/etc/rc0.d/K20tomcat
/etc/rc1.d/K20tomcat
/etc/rc2.d/S20tomcat
/etc/rc3.d/S20tomcat
/etc/rc4.d/S20tomcat
/etc/rc5.d/S20tomcat
/etc/rc6.d/K20tomcat
zhousp@ubuntu:~$
安裝MySQL
終端輸入命令: .$ sudo apt-get install mysql-server
這種方法安裝完mysql須要修改root密碼,否則會出現這麼一種狀況.'Access denied for user 'root'@'localhost' (using password: YES)'或者其餘導致沒法登陸mysql的狀況。能夠按以下步驟解決:
1.打開/etc/mysql/debian.cnf文件,裏面存儲了相關的密碼
sudo gedit /etc/mysql/debian.cnf
在[client]段有user=以及password=這兩行,此即咱們須要的東西
2.輸入命令:mysql -udebian-sys-maint -p
debian-sys-maint即debian.cnf中user=後面的內容
回車後會提示輸入密碼,此時把password=後面的內容複製粘貼後回車便可進行mysql控制檯(通常不要照打,容易出錯,複製便可)
3.進入控制檯後.按如下步驟進行:
use mysql;
update user set password=PASSWORD('新密碼') where user='root';
FLUSH PRIVILEGES;
此時能夠輸入quit;退出後用root賬號登陸,也能夠繼續其餘操做。
MySQL編碼設置
啓動和中止服務器:.$ /etc/init.d/mysql start(stop)
主要配置文件所在位置:/etc/mysql/my.cnf
放置數據庫表文件夾,至關於windows下mysql的date文件夾:/var/lib/mysql/
登陸mysql後執行:>show variables like 'character%';
修改/etc/mysql/my.cnf文件:
在[client]下面添加:
default-character-set=utf8
在[mysqld]下慢添加:
default-character-set=utf8
init_connect='SET NAMES utf8'
修改好後,重啓mysql便可,查詢一下:>show variables like 'character%';
從新啓動mysql服務:.$ /etc/init.d/mysql start(stop)