天天看點

CentOS6.5下安裝JDK1.7 MYSQL5.5 TOMCAT7 nginx1.7.5環境安裝文檔

----------------CentOS6.5下安裝JDK1.7 MYSQL5.5 TOMCAT7 nginx1.7.5環境安裝文檔-----------------------

【JDK1.7安裝】

1)登入Sun的JDK官方下載下傳網 址:http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html

2)下載下傳jdk-7u67-linux-x64.rpm檔案

》删除系統自帶OpenJDK

CentOs6.5 預設會安裝OpenOffice之類,需要JAVA支援,系統預設安裝了一個openjdk1.7版本

# java -version

java version "1.7.0"

OpenJDK Runtime Environment (build 1.7.0-b09)

OpenJDK Client VM (build 1.7.0-b09, mixed mode)

備注:

無須删除原有的openjdk;否則,與之相關的openoffice等軟體,也會自動随之删除;

如果直接"應用程式-添加/删除軟體--基本系統--java“删除其他相關軟體也會自動删除,是以删除前,最好安裝配置好新的JDK環境

1) 删除原有的JDK:

# rpm -qa|grep jdk

檢視安裝的JDK,會顯示多個java-1.7.0-openjdk-1.7.0相關的程式,在以下一一解除安裝。直到删完為止,如下:

# rpm -e --nodeps java-1.7.0-openjdk-1.7.0.65-2.5.1.2.el65.x8664

# rpm -e --nodeps java-1.7.0-openjdk-devel-1.7.0.65-2.5.1.2.el65.x8664

# rpm -e --nodeps java-1.7.0-openjdk-demo-1.7.0.65-2.5.1.2.el65.x8664

......

# rpm -qa|grep java

檢視安裝的JAVA關聯程式,在以下一一解除安裝。直到删完為止,如下:

# rpm -e --nodeps tzdata-java-2014h-1.el6.noarch

......

》配置新的JDK環境

1)把安裝檔案檔案儲存在/usr/java/tools下 ,并切換到root使用者

# mkdir /usr/java 建立/urs/java目錄

# cd /usr/java/

# rpm -ivh ./tools/jdk-7u67-linux-x64.rpm

》配置jdk1.6.0_22環境變量

# vi /etc/profile

JAVAHOME=/usr/java/jdk1.7.079

JREHOME=/usr/java/jdk1.7.079/jre

PATH=$PATH:$JAVAHOME/bin:$JREHOME/bin

CLASSPATH=:$JAVAHOME/lib/dt.jar:$JAVAHOME/lib/tools.jar:$JRE_HOME/lib

export JAVAHOME JREHOME PATH CLASSPATH

》使環境變量生效:

#source /etc/profile

》測試安裝

1)檢視版本号

# java -version

java version "1.7.0_67"

Java(TM) SE Runtime Environment (build 1.7.0_67-b01)

Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)

Java HotSpot(TM) Client VM (build 17.1-b03, mixed mode, sharing)

說明成功了。

【MYSQL5.5的安裝】

安裝方式分為rpm和源碼編譯安裝兩種,本文是采用mysql源碼編譯方式,編譯器使用Cmake。軟體需要mysql-5.5.40.tar.gz和cmake-2.8.10.2.tar.gz,請自行下載下傳。

》下載下傳位址:

http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.40.tar.gz

http://www.cmake.org/files/v2.8/cmake-2.8.10.2.tar.gz

其中mysql使用最新的穩定版本,即最新試用版的上一個版本,且非rc或者alpha的版本,Cmake直接用的最新版。

》上傳mysql-5.5.40.tar.gz和cmake-2.8.10.2.tar.gz到/usr/java/tools檔案夾下。

》CentOS安裝g 和ncurses-devel

# yum install gcc-c

# yum install ncurses-devel

》cmake的安裝

# mkdir -p /usr/java/make

# cd /usr/java/make

# mv ../tools/cmake-2.8.10.2.tar.gz ./

# tar -zxv -f cmake-2.8.10.2.tar.gz

# cd cmake-2.8.10.2

# ./configure

# make

# make install

》将cmake永久加入系統環境變量

》用vi在檔案/etc/profile檔案中增加變量,使其永久有效,

# vi /etc/profile

》在檔案PATH中加入MAKE_PATH環境變量:

JAVAHOME=/usr/java/jdk1.7.067

JREHOME=/usr/java/jdk1.7.067/jre

MAKE_PATH=/usr/java/cmake/cmake-2.8.10.2/bin

PATH=$MAKEPATH:$PATH:$JAVAHOME/bin:$JRE_HOME/bin

CLASSPATH=:$JAVAHOME/lib/dt.jar:$JAVAHOME/lib/tools.jar:$JRE_HOME/lib

export JAVAHOME JREHOME PATH CLASSPATH

》執行以下代碼使剛才的修改生效:

# source /etc/profile

》用 export 指令檢視PATH值

# echo $PATH

》建立mysql的安裝目錄及資料庫存放目錄

# mkdir -p /usr/java/mysql //安裝mysql

# mkdir -p /usr/java/mysql/data //存放資料庫

》建立mysql使用者及使用者組

# groupadd mysql

# useradd -r -g mysql mysql

》編譯安裝mysql

# cd /usr/java/mysql

# tar zxvf ../tools/mysql-5.5.40.tar.gz

# cd mysql-5.5.40/

# cmake -DCMAKEINSTALLPREFIX=/usr/java/mysql

-DMYSQLUNIXADDR=/usr/java/mysql/mysql.sock

-DDEFAULT_CHARSET=utf8

-DDEFAULTCOLLATION=utf8general_ci

-DWITHMYISAMSTORAGE_ENGINE=1

-DWITHINNOBASESTORAGE_ENGINE=1

-DWITHMEMORYSTORAGE_ENGINE=1

-DWITH_READLINE=1

-DENABLEDLOCALINFILE=1

-DMYSQL_DATADIR=/usr/java/mysql/data

-DMYSQL_USER=mysql

-DMYSQLTCPPORT=6666

# make

# make install

》檢驗是否安裝成功

# cd /usr/java/mysql

[[email protected] mysql]# ls

bin data include lib mysql-5.5.40 mysql-test scripts sql-bench

COPYING docs INSTALL-BINARY man mysql.sock README share support-files

有bin等以上檔案的話,恭喜你已經成功安裝了mysql。

》配置mysql

》設定mysql目錄權限

# cd /usr/java/mysql //把目前目錄中所有檔案的所有者設為root,所屬組為mysql

# chown -R root:mysql .

# chown -R mysql:mysql data

》将mysql的啟動服務添加到系統服務中

# cp support-files/my-medium.cnf /etc/my.cnf

cp:是否覆寫"/etc/my.cnf"? y

》建立系統資料庫的表

# cd /usr/java/mysql

# scripts/mysqlinstalldb --user=mysql

》設定環境變量

# vi /root/.bash_profile

在修改PATH=$PATH:$HOME/bin為:

PATH=$PATH:$HOME/bin:/usr/java/mysql/bin:/usr/java/mysql/lib

# source /root/.bash_profile //使剛才的修改生效

》手動啟動mysql

# ./bin/mysqld_safe --user=mysql & //啟動MySQL,但不能停止

mysqladmin -u root -p shutdown //此時root還沒密碼,是以為空值,提示輸入密碼時,直接回車即可。

》将mysql的啟動服務添加到系統服務中

# cp support-files/mysql.server /etc/init.d/mysql

》啟動mysql

# service mysql start

Starting MySQL... ERROR! The server quit without updating PID file (/usr/java/mysql/data/localhost.localdomain.pid).

》啟動失敗:

》我這裡是權限問題,先改變權限

# chown -R mysql:mysql /usr/java/mysql

》接着啟動伺服器

# /etc/init.d/mysql start

》修改MySQL的root使用者的密碼以及打開遠端連接配接

# mysql -u root mysql

mysql> use mysql;

mysql> desc user;

mysql> GRANT ALL PRIVILEGES ON . TO root@"%" IDENTIFIED BY "root"; //為root添加遠端連接配接的能力

mysql> update user set Password = password('x123456.') where User='root'; //設定root使用者密碼

mysql> select Host,User,Password from user where User='root';

mysql> flush privileges;

mysql> exit

》重新登入

# mysql -u root -p

enter password:x123456.000

》若還不能進行遠端連接配接,關閉防火牆

[[email protected]]# /etc/rc.d/init.d/iptables stop

用遠端工具連接配接上了表示成功了。

【TOMCAT7.0的安裝】

》先下載下傳apache-tomcat-7.0.56.tar.gz

》下載下傳地下:http://mirrors.hust.edu.cn/apache/tomcat/tomcat-7/v7.0.56/bin/apache-tomcat-7.0.56.tar.gz

# cd /usr/java

# tar -zxvf ./tools/apache-tomcat-7.0.56.tar.gz

# cd /etc/rc.d/init.d

# vi tomcat

#----------輸入以下資訊---------------------

#

# chkconfig: 345 80 15

# description: Tomcat is a Servlet JSP Engine.

# Enter the jdk installation directory

jdkFile=/usr/java/jdk1.7.067

# Enter the tomcat installation directory

tomcat_File=/usr/java/apache-tomcat-7.0.56

export JAVAHOME=$jdkFile

# Source function library.

. /etc/rc.d/init.d/functions

start(){

if [ -z $(/sbin/pidof java) ]; then

echo "Starting tomcat"

$tomcat_File/bin/startup.sh

touch /var/lock/subsys/tomcat

else

echo "tomcat allready running"

fi

}

stop(){

if [ ! -z $(/sbin/pidof java) ]; then

echo "Shutting down tomcat"

$tomcat_File/bin/shutdown.sh

until [ -z $(/sbin/pidof java) ]; do :; done

rm -f /var/lock/subsys/tomcat

else

echo "tomcat not running"

fi

}

case "$1" in

start)

start

;;

stop)

stop

;;

restart)

stop

start

;;

status)

$tomcat_File/bin/catalina.sh version

;;

*)

echo "Usage: $0 {start|stop|restart|status}"

esac

exit 0

#----------輸入以下資訊---------------------

:wq! #儲存退出

# chmod 755 /etc/rc.d/init.d/tomcat #添加執行權限

# chkconfig --add tomcat #添加服務

# chkconfig tomcat on #設定開機啟動

# service tomcat stop #停止

# service tomcat start #啟動

# service tomcat restart #重新開機

# service tomcat status #檢視狀态資訊

————————————————————————————————————————————————————————————————————————————————————————————

【nginx-1.7.6.tar.gz的安裝】

》先下載下傳nginx-1.7.6.tar.gz

》下載下傳URL:http://nginx.org/download/nginx-1.7.6.tar.gz

》把nginx-1.7.6.tar.gz放到/usr/java/tools目錄下

# cd /usr/local/

# tar -zxvf /usr/java/tools/nginx-1.7.5.tar.gz

# cd nginx-1.7.6/

# yum -y install pcre-devel

# yum install -y zlib-devel

# ./configure

# make && make install

# cd /usr/local/nginx

# cd sbin

# ./nginx

# /etc/rc.d/init.d/iptables stop

》配置伺服器啟動方式

# vi /etc/init.d/nginx

#---------輸入以下資訊------------------

# 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: /software/nginx/logs/nginx.pid

# config: /software/nginx/conf/nginx.conf

nginxd=/usr/local/nginx/sbin/nginx

nginx_config=/usr/local/nginx/conf/nginx.conf

nginx_pid=/usr/local/nginx/logs/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 "nginx already 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 /usr/local/nginx/logs/nginx.pid

}

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

#---------輸入以下資訊------------------

# chmod 755 /etc/init.d/nginx && chkconfig nginx on

# service nginx start

# service nginx stop

# service nginx restart

# ps -ef | grep nginx

# netstat -pant | grep 80

》測試在浏覽器中輸入廣域網IP看看能不能看到歡迎界面,如果能就表示成功了。

————————————————————————————————————————————————————————————————————————————————————————————

【配置規則】

# vi /etc/sysconfig/iptables

增加如下配置:

-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

-A INPUT -m state --state NEW -m tcp -p tcp --dport 8888 -j ACCEPT

-A INPUT -m state --state NEW -m tcp -p tcp --dport 6666 -j ACCEPT

# service iptables restart

》系統啟動的方式為自啟動

# chkconfig mysql on

# chkconfig nginx on

# chkconfig tomcat on

----------------------------------------------------------------------------------------------------

所有環境安裝完成。歡迎使用CentOS6.5,祝大家一用便會。

----------------------------------------------------------------------------------------------------