欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

linux下安装java环境

程序员文章站 2024-01-16 20:54:04
...
安装系统环境是: centos6.5 64位 

一.安装jdk
*如果linux上没安装ftp,是无法上传软件的,先执行以下命令:
yum install -y vsftpd 
/etc/init.d/vsftpd start 

//假设传不了文件先安装lrzsz:
yum -y install lrzsz
rz   将资料开始上传

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/jdk;export JAVA_HOME
JRE_HOME=/usr/local/jdk/jre;export JRE_HOME
PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin;export 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 mysql

上一篇: react踩坑记录

下一篇: