ubuntu 12.04安裝部署環境nginx,tomcat,mysql以及開機啟動備忘
注意:jdk,tomcat,mysql請不要裝在你的home目錄,這樣開機啟動會失敗,會提示相應的文件找不多,可能是應為那時候home目錄沒有掛載
www.2cto.com
1:安裝nginx
下載nginx http://nginx.org/download/nginx-1.2.2.tar.gz
解壓
Java代碼
tar -zxf nginx-1.2.2.tar.gz
編譯,
Java代碼
./configure --prefix=/usr/local/nginx
Java代碼
make && sudo make install
configure可能會提示出錯:安裝一下兩個依賴就可以了
Java代碼 www.2cto.com
sudo apt-get install libpcre3-dev
sudo apt-get install libssl-dev
默認生成的nginx是帶調試信息的,如果要去掉調試信息,則要修改 nginx目錄下的auto/cc/gcc文件,找到
Java代碼
# debug
CFLAGS="$CFLAGS -g"
注釋掉就可以了,然後再重新編譯就可以了
設置開機啟動:
在/etc/init.d/下新建一個文件,就叫 nginx,內容為:
Java代碼
#!/bin/bash
# nginx Startup script for the Nginx HTTP Server
# it is v.0.0.2 version.
# chkconfig: - 85 15
# description: Nginx is a high-performance web and proxy server.
# It has a lot of features, but it's not for everyone.
# processname: nginx
# pidfile: /var/run/nginx.pid
# config: /usr/local/nginx/conf/nginx.conf
nginxd=/usr/local/nginx/sbin/nginx
nginx_config=/usr/local/nginx/conf/nginx.conf
nginx_pid=/var/run/nginx.pid
RETVAL=0 www.2cto.com
prog="nginx"
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
[ -x $nginxd ] || exit 0
# Start nginx daemons functions.
start() {
if [ -e $nginx_pid ];then
echo "nginx already running...."
exit 1
fi
echo -n $"Starting $prog: "
$nginxd -c ${nginx_config}
RETVAL=$?
echo
[ $RETVAL = 0 ]
return $RETVAL
}
# Stop nginx daemons functions.
stop() {
echo -n $"Stopping $prog: "
$nginxd -s stop
RETVAL=$?
echo
[ $RETVAL = 0 ]
}
# reload nginx service functions.
reload() {
echo -n $"Reloading $prog: "
#kill -HUP `cat ${nginx_pid}`
killproc $nginxd -HUP
RETVAL=$?
echo
} www.2cto.com
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
stop
start
;;
status)
status $prog
RETVAL=$?
;;
*)
echo $"Usage: $prog {start|stop}"
exit 1
esac
exit $RETVAL
給他加上執行權限:
Java代碼
sudo chmod +x nginx
再執行 :
Java代碼
sudo update-rc.d -f nginx defaults
www.2cto.com
2:安裝jdk
去官網下載jdk,後綴為 .tar.gz的,解藥到 /usr/local/java下面
設置環境變量:
vi /etc//environment
將此文件改成如下樣子:
Java代碼
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/java/bin"
export JAVA_HOME=/usr/local/java
就可以了
使之生效:執行:
Java代碼
sudo source /etc/environment
3:安裝 tomcat
直接下載tomcat,解藥到 /usr/local/tomcat目錄下
設置tomcat為系統服務:
復制一份tomcat,bin目錄下的catalina.sh文件到/etc/init.d,並改名為 tomcat
在此文件前面加上如下幾行:
Java代碼
修改 catalina.sh,頭上加入如下::
JAVA_HOME=/usr/local/java
CATALINA_HOME+/usr/local/tomcat
CLASSPATH=$JAVA_HOME/lib:$CATALINA_HOME/lib
www.2cto.com
然後執行:
Java代碼
update-rc.d -f tomcat defaults
這樣就OK了
4.安裝mysql
下載綠色版的mysql,解藥到/usr/local/mysql下
可能要安裝一下依賴庫:
Java代碼
sudo apt-get install libaio1
www.2cto.com
執行:
Java代碼
sudo groupadd mysql
sudo useradd -r -g mysql mysql
sudo chown -R mysql:mysql /usr/local/mysql
sudo scripts/mysql_install_db --user=mysql
設置開機啟動:
Java代碼
cd /etc/init.d
sudo ln -s /usr/local/mysql/support-files/mysql.server
sudo update-rc.d mysql.server defaults
創建用戶:
CREATE USER 'aaa'@'%' IDENTIFIED BY 'aaa';
GRANT ALL ON *.* TO 'aaa'@'%';
作者 cmzx3444