標籤:des style http color java 使用 os strong
最近需要做jsp項目,部署在ubuntu 下,周末抽時間配置了nginx + php + mysql + phpmyadmin + tomcat 環境,從windows 的C# 轉過來, 多少有些不適應, 估計要走全棧的方向了. 順便整理了一下入門的配置方法, 完全在控制台下完成.1.1 Common
Ctrl+Alt+T
sudo –sH
linux命令ps aux|grep xxx
ln -s 源地址 目的地址
比如把linux檔案系統rootfs_dir軟連結到/home/jyg/目錄下
ln -s /opt/linux/rootfs_dir /home/jyg/rootfs_dir就可以了
find / -name [filename]
apt-get
1.2 Install Java
sudo apt-get install openjdk-6-jdk
sudo apt-get install openjdk-7-jdk
sudo update-alternatives --config java
sudo update-alternatives --config javac
sudo update-alternatives --config javaws
sudo vi /etc/environment
#Add following
JAVA_HOME=”/usr/lib/jvm/java-1.6.0-openjdk-i386”
Test:
source /etc/environment
echo $JAVA_HOME
uninstall
sudo apt-get remove openjdk-6-jdk
The easy way to install the last JKD1.7
-- sudo apt-get install python-software-properties
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java7-installer
uninstall
sudo apt-get remove oracle-java7-installer
- Oralce JDK 1.7.0_03 (由於公司要求,live環境指定了JDK 版本)
Download JDK
http://download.oracle.com/otn-pub/java/jdk/7u3-b04/jdk-7u3-linux-x64.tar.gz
(you get the permission by access the page: http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1637583.html )
cd ~/Downloads
tar –zxcf jdk-7u3-linux-x64.tar.gz
#you will see the folder jdk1.7.0_03, for the same which live ,change the folder name to jdk 1.7.0
mv jdk1.7.0_03 jdk1.7.0
sudo mkdir –p –m ug+rw /usr/lib/jvm/jdk1.7.0
sodu mv jdk1.7.0 /usr/lib/jvm/
sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1. 1.7.0/bin/java" 1
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk1. 1.7.0/bin/javac" 1
sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/lib/jvm/jdk1.7.0/bin/javaws" 1
sudo update-alternatives --config java
sudo update-alternatives --config javac //
sudo update-alternatives --config javaws
sudo vi /etc/environment
#Add following
JAVA_HOME=”/usr/lib/jvm/jdk1.7.0”
Test:
source /etc/environment
echo $JAVA_HOME
Notice: If you want to install other version JDK, Please see Install Other JDK
1.3 Install Nginx
sudo apt-get install nginx
Useful Command about Nginx.
Start Nginx:sudo /etc/init.d/nginx start; // sudo service nginx start
Test: Browser the location:http://localhost ; if browser show "Welcome to nginx!", you have installed Nginx successfully;
Shutdown Nginx:sudo /etc/init.d/nginx stop;
Restart nginx:sudo /etc/init.d/nginx restart;
**You can run the following command to reveal your virtual server’s IP address.
ifconfig eth0 | grep inet | awk ‘{ print $2 }‘
When you visit your IP address page in your browser, you will see the words, “Welcome to nginx”
You can see a screenshot of the utilitarian nginx welcome page here
To ensure that nginx will be up after reboots, it’s best to add it to the startup. Type this command into terminal:
update-rc.d nginx defaults
1.4 Install PHP
sudo apt-get install php5-cli php5-cgi php5-fpm php5-mcrypt php5-mysql
php5-fpm:與nginx配合方式之一,另外個是:spawn-fcgi;
php5-mysql:訪問mysql;
sudo vi/etc/nginx/sites-available/default
將index的一行修改為:“index index.html index.htm index.php;”
去掉下面的注釋用於支援php指令碼:
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
}
Nginx 預設網站目錄: cd /usr/share/nginx/www
echo "<?php phpinfo();?>" > test.php
啟動nginx:
sudo /etc/init.d/nginx start
訪問:http://localhost/test.php
出現php詳細資料,配置成功。
關閉nginx
sudo /etc/init.d/nginx stop
1.5 Install Mysql
sudo apt-get install mysql-server
安裝過程中要求輸入使用者名稱秘密. [mysqlUser] /[mysqlPW]
mysql –u [mysqlUser]–p
進入到mysql 控制台.
1.6 Install phpmyAdmin
- 下載phpMyAdmin-4.2.7-all-languages.tar.gz (這個需要手工下載,使用Debian 直接安裝的話,和 nginx 整合會比較麻煩)
網站直接下載: http://www.phpmyadmin.net/home_page/downloads.php
Terminal 下載
wget http://prdownloads.sourceforge.net/phpmyadmin/phpMyAdmin-4.2.7-all-languages.tar.gz
儲存檔案到 /var/lib: sudo mv phpMyAdmin-4.2.7-all-languages.tar.gz /var/lib/phpMyAdmin
cd /var/lib/phpMyAdmin
sudo tar zxvf phpMyAdmin-4.2.7-all-languages.tar.gz
ln –s /var/lib/phpMyAdmin/ phpMyAdmin-4.2.7-all-languages /usr/share/nginx/www/phpmyadmin
訪問:http://localhost/phpmyadmin
出現登陸頁面, 用mysql 的使用者名稱密度登陸即可.
1.7 Install tomcat 7
sudo apt-get install tomcat7 tomcat7-docs tomcat7-examples tomcat7-admin
Choose username and password to manage tomcat and add to /etc/tomcat7/tomcat-users.xml file in the below format.
<role rolename="manager-gui"/>
<role rolename="admin-gui"/>
<user username="[tomactAdmin]" password="[tomcatPW]" roles="manager-gui,admin-gui"/>
This code must be within this < tomcat-users > …. < / tomcat-users > Tags
Now restart the service.
sudo /etc/init.d/tomcat7 restart
- 與nginx整合
- Must make sure stop tomcat7 and nginx first: (如果沒有stop tomcat 7 , 會出現很多很奇怪的問題)
sudo /etc/init.d/tomcat7 stop
sudo /etc/init.d/nginx stop
sudo vi /etc/tomcat7/server.xml
將<Host name="localhost" appBase="webapps" ...>修改為<Host name="localhost" appBase="/usr/share/nginx/www" ...>
sudo vi /etc/nginx/proxy_params
添加:
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
sudo vi /etc/nginx/sites-available/default
修改index行為:“index index.html index.htm index.php index.jsp;”
在"location ~ \.php${...}"php配置節添加:
location ~ \.jsp$ {
index index.jsp;
proxy_pass http://localhost:8080;
include proxy_params;
}
建立目錄:sudo mkdir /usr/share/nginx/www/test
建立JSP檔案:sudo vi /usr/share/nginx/www /test/test.jsp
輸入:
<HTML>
<BODY>
<%
out.println("IP:");
out.println(request.getHeader("x-forwarded-for"));
%>
</BODY>
</HTML>
啟動 tomcat: sudo /etc/init.d/tomcat7 start
啟動nginx:sudo /etc/init.d/nginx start
訪問:http://localhost/test/test.jsp
如有問題 查看tomcat log:
cat /var/log/tomcat7catalina.out |more
出現"IP:192.168.11.22"配置成功。
說明下,因為此處用了nginx代理的功能,所以要用request.getHeader("x-forwarded-for")獲得IP;request.getRemoteHost()獲得的將是代理的IP,即:127.0.0.1。
1.8 Install eclipse
sudo apt-get install eclipse-platform
sudo apt-get install eclipse-jdk
--need reconfig java vm
sudo update-alternatives --config java
sudo update-alternatives --config javac
sudo update-alternatives --config javaws
主要參考:
http://wenku.baidu.com/view/f1b8592a192e45361066f5ad.html