linux怎么安装java环境

linux怎么安装java环境,第1张

安装系统环境是: centos6.5 64位

一.安装jdk

1.下载Java文件jdk-6u45-Linux-x64.bin

2.运行./jdk-6u45-linux-x64.bin

3.移动该文件到/usr/local/jdk目录下

mv jdk-6u45-linux-x64 /usr/local/jdk

4.配置java环境变量,在文件/etc/profile最后添加以下内容:

#set java

JAVA_HOME=/usr/local/jdkexport JAVA_HOME

JRE_HOME=/usr/local/jdk/jreexport JRE_HOME

PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/binexport PATH

export CLASSPATH=$CLASSPATH:$PATH:$JAVA_HOME/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib:$JRE_HOME/lib:.

5.source /etc/profile (重新激活)

6.运行java -version查看是否成功

二.安装tomcat

1.下载tomcat文件:apache-tomcat-7.0.47.tar.gz

2.解压tar -zxvf apache-tomcat-7.0.47.tar.gz

3.移动该文件到/usr/local下,并命名为tomcat

mv apache-tomcat-7.0.47 /usr/local/tomcat

4.到tomcat/bin目录下setclasspath.sh文件中设置java环境,加入以下两行即可:

export JAVA_HOME=/usr/local/jdk

export JRE_HOME=/usr/local/jdk/jre

5.设置tomcat 服务启动

把下面内容保存到/etc/init.d/目录,文件名为tomcat

#!/bin/bash

# /etc/rc.d/init.d/tomcat

# init script for tomcat precesses

#

# processname: tomcat by ton

# description: tomcat is a j2se server

# chkconfig: 2345 86 16

# description: Start up the Tomcat servlet engine.

set -m (有时不加这个,secureFX会话失效时,会导致tomcat自动stop)

CATALINA_HOME="/usr/local/tomcat"

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

# running tomcat services

RETVAL=$?

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

restart)

if [ -f $CATALINA_HOME/bin/startup.sh ]then

echo $"Starting Tomcat"

$CATALINA_HOME/bin/startup.sh

fi

sleep 5

if [ -f $CATALINA_HOME/bin/shutdown.sh ]then

echo $"Stopping Tomcat"

$CATALINA_HOME/bin/shutdown.sh

fi

*)

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

exit 1

esac

exit $RETVAL

6.为该文件添加运行权限

chmod +x /etc/init.d/tomcat

三.安装MySQL

linux下主要是编译安装,需准备:cmake工具

1.yum install gcc gcc-c++ ncurses-devel perl (安装编译源码所需的工具和库)

2.下载cmake-3.0.1.tar.gz ,然后输入命令:

tar -xzvf cmake-3.0.1.tar.gz

cd cmake-3.0.1

./bootstrap make make install

3.新增mysql用户组和用户命令:

groupadd mysql

useradd -r -g mysql mysql

4.新建mysql安装目录和存放数据目录:

mkdir -p /usr/local/mysql

cd /usr/local/mysql

chown -R mysql:mysql . (分配权限)

mkdir -p /var/mysqldata

cd /var/mysqldata

chown -R mysql:mysql . (分配权限)

5.下载mysql-5.5.38.tar.gz ,解压:

tar -zxvf mysql-5.5.38.tar.gz

cd mysql-5.5.38(先进入目录下)

6.(先进入mysql-5.5.38目录下)再执行cmake命令:

cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \

-DMYSQL_UNIX_ADDR=/var/mysqldata/mysql.sock \

-DDEFAULT_CHARSET=utf8 \

-DDEFAULT_COLLATION=utf8_general_ci \

-DWITH_EXTRA_CHARSETS:STRING=utf8,gbk \

-DWITH_MYISAM_STORAGE_ENGINE=1 \

-DWITH_INNOBASE_STORAGE_ENGINE=1 \

-DWITH_MEMORY_STORAGE_ENGINE=1 \

-DWITH_READLINE=1 \

-DENABLED_LOCAL_INFILE=1 \

-DMYSQL_DATADIR=/var/mysqldata \

-DMYSQL_USER=mysql \

-DMYSQL_TCP_PORT=3306

7.再编译:

make

make install

8.复制配置文件,在/usr/local/mysql下执行:

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

9 初始化数据库

执行前需赋给scripts/mysql_install_db文件执行权限

chmod 755 scripts/mysql_install_db

scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ \

--datadir=/var/mysqldata/

10. 设置mysqld的开机启动

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

chmod 755 /etc/init.d/mysql

chkconfig mysql on

11.MySQL配置环境变量

export PATH=/usr/local/mysql/bin:$PATH

alias mysql_start="mysqld_safe &"

alias mysql_stop="mysqladmin –u root -p shutdown"

source /etc/profile (重启配置)

12.启动mysql服务

/etc/init.d/mysql start

ps -ef |grep mysql (命令查看是否启动)

13.登陆mysql

# mysql -u root –p

14.修改MySQL用户root的密码

mysqladmin -u root password '123456' (更新密码)

Linux系统中安装Java步骤:

1.选择你所有安装的 *** 作系统类型(Linux,Linux AMD64,Solaris等)。一旦已经选择下载文件──要么是自解压缩执行文件,要么是自解压缩的RPM文件,可以安装它。当前,最新的版本是5.0:

# mkdir -p /usr/local/java

# cd /usr/local/java

# mv /path/to/jre-1_5_0_05-linux-amd64.bin .

# chmod u+x jre-1_5_0_05-linux-amd64.bin

# ./jre-1_5_0_05-linux-amd64.bin

2.通过编辑/etc/profile将Java添加到默认的PATH设置:

PATH=$PATH:/usr/local/java/jre1.5.0_05/bin

JAVA_HOME=/usr/local/java/jre1.5.0_05

export $PATH $JAVA_HOME


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/8286809.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-15
下一篇 2023-04-15

发表评论

登录后才能评论

评论列表(0条)

保存