zoukankan      html  css  js  c++  java
  • Linux jdk+tomcat+mysql 安装及配置

    一、配置环境:
    OS:CentOS release 6.5 x86_64
    IP:192.168.2.110
    二、配置jdk+tomcat+MySQL jsp站点环境
    在linux下配置简单易用的java环境so easy! 真的很简单。因为linux系统集成了jdk,因此只需要安装tomcat和MySQL就好。
    三、事例配置(jdk+tomcat+mysql):
    1.查看Linux系统JDK版本号:
    [root@super ~]# java -version
    java version "1.7.0_45"
    OpenJDK Runtime Environment (rhel-2.4.3.3.el6-x86_64 u45-b15)
    OpenJDK 64-Bit Server VM (build 24.45-b08, mixed mode)

    可以查看到以上环境集成1.7版本的jdk
    2.下载tomcat并启动

    [root@super ~]# wget http://apache.opencas.org/tomcat/tomcat-7/v7.0.69/bin/apache-tomcat-7.0.69.tar.gz # 下载tomcat压缩包
    [root@super ~]# tar xf apache-tomcat-7.0.64.tar.gz -C /usr/local/ # 把tomcat压缩包解压到/usr/local/ 目录下。
    [root@super ~]# cd /usr/local/apache-tomcat-7.0.64/bin/
    # 进入tomcat解压文件的bin目录下。
    [root@super bin]# sh startup.sh # 启动tomcat

    Using CATALINA_BASE: /usr/local/apache-tomcat-7.0.64
    Using CATALINA_HOME: /usr/local/apache-tomcat-7.0.64
    Using CATALINA_TMPDIR: /usr/local/apache-tomcat-7.0.64/temp
    Using JRE_HOME: /usr
    Using CLASSPATH: /usr/local/apache-tomcat-7.0.64/bin/bootstrap.jar:/usr/local/apache-tomcat-7.0.64/bin/tomcat-juli.jar
    Tomcat started.

    3.查看tomcat启动端口
    [root@super bin]# netstat -ntplu | grep 8080
    tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN 1589/java
    [root@super bin]# netstat -ntplu | grep 8009
    tcp 0 0 0.0.0.0:8009 0.0.0.0:* LISTEN 1589/java

    tomcat 服务默认启动8080端口和8009端口

    到这里tomcat安装完毕!

    4.安装MySQL

    [root@super ~]# wget http://mirrors.sohu.com/mysql/MySQL-5.5/mysql-5.5.45-linux2.6-x86_64.tar.gz # 下载mysql 5.5 版本,下载过程比较漫长,需要的等待一下
    [root@super ~]# tar xf mysql-5.5.45-linux2.6-x86_64.tar.gz -C /usr/local/ # 将mysql解压到 /usr/local/ 目录
    [root@super local]# cd /usr/local/ # 进入该目录
    [root@super local]# mv mysql-5.5.45-linux2.6-x86_64 mysql #重新命名mysql 这一步是必须的。
    [root@super local]# groupadd -r -g 306 mysql #创建mysql用户组
    [root@super local]# useradd -r -u 306 -g 306 -d /dev/null -s /sbin/nologin mysql #创建mysql用户
    [root@super local]# tail -n 1 /etc/passwd #查看是否创建了mysql用户
    mysql:x:306:306::/dev/null:/sbin/nologin
    [root@super local]# chown -R mysql:mysql /usr/local/mysql/ # 给mysql目录下所有文件mysql拥有者和拥有组权限
    [root@super local]# chmod -R 755 /usr/local/mysql/ # 给mysql目录下所有文件 755权限
    ################################  [root@super local]# mkdir /data # 创建数据库文件存放目录###########
    ################################[root@super local]# chown -R mysql:mysql /data/ # 给权限#################
    [root@super mysql]# cd /usr/local/mysql/support-files/
    [root@super support-files]# rpm -qa | grep mysql # 查看该系统mysql之前有没有装过
    mysql-libs-5.1.71-1.el6.x86_64
    [root@super support-files]# rpm -e --nodeps mysql-libs # 强制卸载该软件包
    [root@super support-files]# cp -a mysql.server /etc/init.d/mysqld # 添加mysql服务到默认目录
    [root@super support-files]# cp -a my-large.cnf /etc/my.cnf # 为mysql添加主配置文件
    ###################[root@super support-files]# vim /etc/my.cnf # 编辑mysql主配置文件###########################
    #######################39 thread_concurrency = 2 39行,该参数是设置CPU个数,一般都是实际CPU个数*2###################
    #########################40 datadir=/data 40行,该行为手动添加数据库文件存放目录#########################
    #########################然后保存退出####################################
    [root@super support-files]# cd .. # 退回上一级
    [root@super mysql]# ./scripts/mysql_install_db --user=mysql # mysql初始化
    注意:在初始化中有告警没关系,如果有报错请检查。
    [root@super mysql]# service mysqld start
    Starting MySQL.. [ OK ]

    以上为正确启动了mysql

    再使用ln -s /usr/local/mysql/bin/mysql /usr/bin 该命令边可以用mysql来进入进程
    [root@super apache-tomcat-7.0.64]# chkconfig --add mysqld
    [root@super apache-tomcat-7.0.64]# chkconfig --list mysqld
    mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off

    将mysql添加为开机启动服务
    [root@super ~]# vim /etc/rc.local
    #!/bin/sh
    #
    # This script will be executed *after* all the other init scripts.
    # You can put your own initialization stuff in here if you don't
    # want to do the full Sys V style init stuff.

    touch /var/lock/subsys/local
    /bin/sh /usr/local/apache-tomcat-7.0.64/bin/startup.sh # 添加tomcat为开机启动

    [root@super mysql]# vim /etc/profile.d/mysql.sh # 将mysql/bin目录添加到path环境变量这样方便执行mysql命令
    export PATH=$PATH:/usr/local/mysql/bin
    保存退出
    [root@super mysql]# source /etc/profile.d/mysql.sh # 执行立即生效

    [root@super ~]# vim /etc/sysconfig/iptables # 修改防火墙规则
    -A INPUT -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT
    -A INPUT -m state --state NEW -m tcp -p tcp --dport 8009 -j ACCEPT
    保存退出
    [root@super ~]# service iptables restart # 重启生效

    以上过程就jdk+tomcat+mysql配置的全过程。

    5. 测试环境是否配置正确

    http://192.168.2.110:8080/

  • 相关阅读:
    SilkTest Q&A 5
    SilkTest Q&A 6
    产生n不同随机数的算法
    根据日期计算星期小算法
    Linux $( )与${ }的区别
    UVA 10313(完全背包变形)
    HDU 4277 USACO ORZ
    Android Studio上手,基于VideoView的本地文件及流媒体播放器
    Mina框架项目运用
    【iOS】怎样推断文本文件的字符编码格式
  • 原文地址:https://www.cnblogs.com/xuexin/p/5257819.html
Copyright © 2011-2022 走看看