安裝配置JDK
1、下載安裝
上官網(wǎng)下載新版本的JDK,
jdk-7u45-linux-i586.tar.gz壓縮包,放到Linux下任意目錄,cd到該目錄,執(zhí)行以下命令:
[plain]
view plaincopymkdir –p /dev-tools/java
tar zxvfjdk-7u45-linux-i586.tar.gz -C /dev-tools/java
解壓成功過(guò)后,jdk便位于/dev-tools/java下的jdk1.7.0_45目錄了,如圖
2、配置環(huán)境
從第一步,我們知道了jdk的解壓目錄就位于/dev-tools/java/jdk1.7.0_45,接著配置環(huán)境變量,通過(guò)修改.bashrc文件實(shí)現(xiàn),執(zhí)行以下命令:
[plain]
view plaincopyVi .bashrc
在文件末尾加上
[plain]
view plaincopyexport JAVA_HOME=/dev-tools/java/jdk1.7.0_45
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
exportPATH=${JAVA_HOME}/bin:$PATH
保存后退出。
執(zhí)行
[plain]
view plaincopysource~/.bashrc
修改馬上生效
執(zhí)行java –version能看到版本呢信息,JDK就安裝配置成功了,如圖
安裝配置Tomcat
1、下載解壓
跟JDK一樣上官網(wǎng)
http://tomcat.apache.org/download-70.cgi下載tomcat壓縮包,如apache-tomcat-7.0.47.tar.gz,下載后放入任意目錄cd到改目錄執(zhí)行以下命令解壓:
[plain]
view plaincopymkdir –p /dev-tools/tomcat
tar zxvfapache-tomcat-7.0.47.tar.gz -C /dev-tools/tomcat
解壓成功過(guò)后如圖:
2、配置環(huán)境
1)打開(kāi)端口
解壓成功過(guò)后如果Linux有設(shè)置防火墻,就必須先在防火墻打開(kāi)指定端口,tomcat默認(rèn)http端口為8080,一下為打開(kāi)8080端口的例子:
修改/etc/sysconfig/iptables文件,執(zhí)行以下命令
[plain]
view plaincopyvi /etc/sysconfig/iptables
增加一行
[plain]
view plaincopy-A RH-Firewall-1-INPUT -m state--state NEW -m tcp -p tcp --dport 8080 -j ACCEPT
如圖,我把80端口也順便打開(kāi)了,以后要用到
保存退出,重啟防火墻,執(zhí)行命令
[plain]
view plaincopyservice iptablesrestart
2)設(shè)置開(kāi)機(jī)啟動(dòng)
通過(guò)以上的設(shè)置,tomcat其實(shí)已經(jīng)可以啟動(dòng)并正常訪(fǎng)問(wèn)了,只要執(zhí)行
[plain]
view plaincopy/dev-tools/tomcat/apache-tomcat-7.0.47/bin/startup.sh
就可以啟動(dòng)tomcat了(JDK已經(jīng)正確安裝)如圖:
但是你每次啟動(dòng)都要輸入一次未免太麻煩了,所以我們要設(shè)置開(kāi)機(jī)自動(dòng)啟動(dòng)tomcat。
a)把下面的代碼保存為tomcat(藍(lán)色字體為需要修改部分)文件,并讓它成為可執(zhí)行文件
[plain]
view plaincopychmod 755 tomcat
[plain]
view plaincopy#!/bin/bash
#
# kenny kenny.zhou@tom.com
# /etc/rc.d/init.d/tomcat
# init script for tomcat precesses
#
# processname: tomcat
# description: tomcat is a j2se server
# chkconfig: 2345 86 16
# description: Start up the Tomcat servlet engine.
if [ -f /etc/init.d/functions ]; then
. /etc/init.d/functions
elif [ -f /etc/rc.d/init.d/functions ]; then
. /etc/rc.d/init.d/functions
else
echo -e "/atomcat: unable to locate functions lib. Cannot continue."
exit -1
fi
RETVAL=$?
JAVA_HOME=/dev-tools/java/jdk1.7.0_45
export JAVA_HOME
PATH=$JAVA_HOME/bin:$PATH
export PATH
CATALINA_HOME="/dev-tools/tomcat/apache-tomcat-7.0.47"
case "$1" in
start)
if [ -f $CATALINA_HOME/bin/startup.sh ];
then
echo $"Starting Tomcat"
$CATALINA_HOME/bin/startup.sh
fi
;;
stop)
if [ -f $CATALINA_HOME/bin/shutdown.sh ];
then
echo $"Stopping Tomcat"
$CATALINA_HOME/bin/shutdown.sh
fi
;;
*)
echo $"Usage: $0 {start|stop}"
exit 1
;;
esac
exit $RETVAL
b)將tomcat文件拷貝到/etc/init.d/下,并運(yùn)行:
[plain]
view plaincopychkconfig --add tomcat
重啟,tomcat就能自動(dòng)啟動(dòng)了。
PS:
啟動(dòng)tomcat:
[plain]
view plaincopyservice tomcat start
停止tomcat:
[plain]
view plaincopyservice tomcat stop
安裝配置nginx
1、編譯安裝nginx
a) 建立安裝文件夾
[plain]
view plaincopymkdir -p /dev-tools/nginx
mkdir –p /dev-tools/pcre
cd /dev-tools
b) 安裝依賴(lài)
[plain]
view plaincopyyum install wget
yum install pcre
yum install openssl*
yum -y install gcc gcc-c++autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devellibxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-develkrb5 krb5-devel libidn libidn-devel openssl openssl-devel openldapopenldap-devel nss_ldap openldap-clients openldap-servers make
yum -y install gd gd2 gd-develgd2-devel
c) 建立用戶(hù)
[plain]
view plaincopy/usr/sbin/groupadd www
/usr/sbin/useradd -g www www
ulimit -SHn 65535
d) 編譯安裝pcre(藍(lán)色部分為安裝路徑)
wgetftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.32.tar.gztar zxvf pcre-8.32.tar.gzcd pcre-8.32./configure --prefix=/dev-tools/pcremake && make installcd ../
e) 編譯安裝nginx((藍(lán)色部分為安裝路徑))
wget http://nginx.org/download/nginx-1.5.2.tar.gztar zxvf nginx-1.5.2.tar.gzcd nginx-1.5.2./configure --user=www --group=www --prefix=/dev-tools/nginx --with-http_stub_status_module --with-http_ssl_module--with-pcre=/dev-tools/pcre-8.32--with-http_realip_module --with-http_image_filter_modulemakemake installcd ../一切順利了,安裝結(jié)束后,執(zhí)行
[plain]
view plaincopy/dev-tools/nginx/sbin/nginx
啟動(dòng)nginx,默認(rèn)監(jiān)聽(tīng)80端口,如何打開(kāi)80端口,看tomcat配置,如圖
2、配置nginx與tomcat協(xié)作
修改nginx的配置文件
[plain]
view plaincopyvi /dev-tools/nginx/conf/nginx.conf
如下
[plain]
view plaincopy#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent"$http_referer" '
# '"$http_user_agent""$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root /dev-tools/tomcat/apache-tomcat-7.0.47/webapps/ROOT;
index index.jsp index.html index.htm;
}
#error_page 404 /404.html;
# redirect servererror pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location =/50x.html {
root html;
}
# 代理tomcat
location ~ \.jsp${
root /dev-tools/tomcat/apache-tomcat-7.0.47/webapps/ROOT;
proxy_pass http://127.0.0.1:8080; #轉(zhuǎn)向tomcat處理
<span style="white-space:pre"> </span>}
}
}
保存配置,重新載入配置
[plain]
view plaincopy/dev-tools/nginx/sbin/nginx -s reload
直接訪(fǎng)問(wèn)80端口下的index.jsp,如圖:
Nginx已經(jīng)可以成功將請(qǐng)求交給tomcat了。
3、開(kāi)機(jī)自動(dòng)啟動(dòng)nginx
vi /etc/rc.d/init.d/nginx
鍵入以下文本(藍(lán)色字體按照實(shí)際修改)
#!/bin/bash
# chkconfig: - 85 15
# description: Nginx is a high-performance web and proxy server.
# It has alot of features, but it's not for everyone.
nginxd=/dev-tools/nginx/sbin/nginx
nginx_config=/dev-tools/nginx/conf/nginx.conf
nginx_pid=/var/run/nginx.pid
RETVAL=0
prog="nginx"
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
[ -x $nginxd ] || exit 0
# Start nginx daemons functions.
start() {
if [ -e $nginx_pid ];then
echo "nginxalready running...."
exit 1
fi
echo -n $"Starting$prog: "
daemon $nginxd -c${nginx_config}
RETVAL=$?
echo
[ $RETVAL = 0 ]&& touch /var/lock/subsys/nginx
return $RETVAL
}
# Stop nginx daemons functions.
stop() {
echo -n$"Stopping $prog: "
killproc $nginxd
RETVAL=$?
echo
[ $RETVAL = 0 ]&& rm -f /var/lock/subsys/nginx /var/run/nginx.pid
}
# 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|restart|reload|status|help}"
exit 1
esac
exit $RETVAL
保存后執(zhí)行一下命令
修改權(quán)限
chmod 777 /etc/rc.d/init.d/nginx
添加開(kāi)機(jī)啟動(dòng)
chkconfig --add nginx
chkconfig --level 2345 nginx on
PS:
啟動(dòng)mysql: service nginx start
停止mysql: service nginx stop
安裝配置MySQL
1、下載安裝MySql
執(zhí)行命令
cd /dev-tools/
wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.14-linux-glibc2.5-i686.tar.gz
tar zxvf mysql-5.6.14-linux-glibc2.5-i686.tar.gz
mv mysql-5.6.14-linux-glibc2.5-i686/ mysql
創(chuàng)建mysql賬戶(hù)與組
/usr/sbin/groupadd mysql
/usr/sbin/useradd -g mysql mysql
建立數(shù)據(jù)庫(kù)文件存放的目錄,安裝數(shù)據(jù)庫(kù),并安裝數(shù)據(jù)庫(kù)文件到新建的目錄
mkdir -p /home/data/mysql/data
/dev-tools/mysql/scripts/mysql_install_db --basedir=/dev-tools/mysql --datadir=/home/data/mysql/data --user=mysql
把啟動(dòng)腳本中的所有“/usr/local/mysql”路徑替換為我們安裝目錄路徑“/dev-tools/mysql”
sed -i"s#/usr/local/mysql#/dev-tools/mysql#g"/dev-tools/mysql/bin/mysqld_safe
2、配置MySql
a) 修改/etc/my.cnf如下(藍(lán)色字體為需要修改或者需要添加的)
[mysqld]
datadir=/home/data/mysql/data
socket=/tmp/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assortedsecurity risks
symbolic-links=0
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
basedir=/dev-tools/mysql
datadir=/home/data/mysql/data
b) 建立服務(wù),開(kāi)機(jī)自動(dòng)啟動(dòng)
vi /etc/init.d/mysqld
鍵入以下文本(藍(lán)色字體按照實(shí)際路徑填寫(xiě))
#!/bin/sh
# chkconfig: - 85 15
# description: mysql
mysql_username="root"
mysql_password=""
function_start_mysql()
{
printf "StartingMySQL...\n"
/bin/sh /dev-tools/mysql/bin/mysqld_safe 2>&1 >/dev/null &
}
function_stop_mysql()
{
printf "StopingMySQL...\n"
/dev-tools/mysql/bin/mysqladmin -u${mysql_username} -p${mysql_password} -S /tmp/mysql.sock shutdown
}
function_restart_mysql()
{
printf"Restarting MySQL...\n"
function_stop_mysql
sleep 5
function_start_mysql
}
if [ "$1" = "start" ]; then
function_start_mysql
elif [ "$1" = "stop" ]; then
function_stop_mysql
elif [ "$1" = "restart" ]; then
function_restart_mysql
else
printf "Usage:/home/data/mysql/data{start|stop|restart|kill}\n"
fi
設(shè)置權(quán)限
chmod 777 /etc/init.d/mysqld
添加服務(wù)并讓他開(kāi)機(jī)自動(dòng)啟動(dòng)
chkconfig --add mysqld
chkconfig --level 2345 mysqld on
PS:
啟動(dòng)mysql: service mysqld start
停止mysql: service mysqld stop