Ubuntu12.04 install and deploy the environment, nginx, tomcat, and mysql. Start tunginxtomcat at startup
Note: jdk, tomcat, and mysql should not be installed in your home directory. in this case, the startup will fail and the system will prompt that the corresponding files are missing. it may be because the home directory was not mounted at that time.
1: install nginx
Download nginxhttp: // nginx.org/download/nginx-1.2.2.tar.gz
Extract
Java code
-
Tar-zxf nginx-1.2.2.tar.gz
Java code
-
./Configure -- prefix =/usr/local/nginx
Java code
-
Make & sudo make install
Configure may prompt an error: install two dependencies.
Java code
-
Sudo apt-get install libpcre3-dev
-
Sudo apt-get install libssl-dev
The default nginx generated contains debugging information. to remove debugging information, modify the auto/cc/gcc file in the nginx directory and find
Java code
-
# Debug
-
CFLAGS = "$ CFLAGS-g"
Comment it out, and then recompile it.
Set boot start:
Create a new file under/etc/init. d/, which is called nginx. the content is:
Java code
-
#! /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
-
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
-
}
-
# 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 code
-
Sudo chmod + x nginx
Java code
-
Sudo update-rc.d-f nginx defaults
2: install jdk
Go to the official website to download the jdk with the suffix .tar.gz. the solution is under/usr/local/java.
Set environment variables:
Vi/etc // environment
Change the file to the following format:
Java code
-
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
You can.
Execute:
Java code
-
Sudo source/etc/environment
3: install tomcat
Download tomcat directly to the/usr/local/tomcat directory.
Set tomcat as a system service:
Copy a copy of tomcat, the catalina. sh file under the bin directory to/etc/init. d, and change it to tomcat
Add the following lines before the file:
Java code
-
Modify catalina. sh and add the following to the header ::
-
JAVA_HOME =/usr/local/java
-
CATALINA_HOME +/usr/local/tomcat
-
CLASSPATH = $ JAVA_HOME/lib: $ CATALINA_HOME/lib
Java code
-
Update-rc.d-f tomcat defaults
So OK.
4. install mysql
Download the green version of mysql to/usr/local/mysql
You may need to install the dependent database:
Java code
-
Sudo apt-get install libaio1
Java code
-
Sudo groupadd mysql
-
Sudo useradd-r-g mysql
-
Sudo chown-R mysql: mysql/usr/local/mysql
-
Sudo scripts/mysql_install_db -- user = mysql
Java code
-
Cd/etc/init. d
-
Sudo ln-s/usr/local/mysql/support-files/mysql. server
-
Sudo update-rc.d mysql. server defaults
Create a user:
Create user 'AAA' @ '%' identified by 'AAA ';
Grant all on *. * TO 'AAA' @ '% ';