CentOS 7系统下程序部署(JAVA+tomcat+mysql)
CentOS 7系统下程序部署(JAVA+tomcat+mysql)
龙_沐风 发表于1年前
CentOS 7系统下程序部署(JAVA+tomcat+mysql)
  • 发表于 1年前
  • 阅读 149
  • 收藏 2
  • 点赞 0
  • 评论 0

腾讯云 技术升级10大核心产品年终让利>>>   

CentOS 7系统安装和配置请到网上查询相关资料(百度经验里有),注意安装的时候,一定要选择安装的软件和设置网络连接为打开,不然系统默认按照最小化安装,禁用网络连接(后期配置很烦)

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

一、安装和配置JAVA开发环境

[root@promote test]# java -version         ——查看java版本信息

openjdk version "1.8.0_65"

OpenJDK Runtime Environment (build 1.8.0_65-b17)

OpenJDK 64-Bit Server VM (build 25.65-b01, mixed mode)

[root@promote test]#

[root@promote test]# rpm -qa | grep java         ——进一步查看JDK信息

javapackages-tools-3.4.1-11.el7.noarch

java-1.8.0-openjdk-1.8.0.65-3.b17.el7.x86_64

java-1.7.0-openjdk-headless-1.7.0.91-2.6.2.3.el7.x86_64

python-javapackages-3.4.1-11.el7.noarch

java-1.8.0-openjdk-headless-1.8.0.65-3.b17.el7.x86_64

java-1.7.0-openjdk-1.7.0.91-2.6.2.3.el7.x86_64

tzdata-java-2015g-1.el7.noarch

[root@promote test]#

/*上述标记颜色的为已安装的java版本,下面5条指令为卸载指令*/

[root@promote test]# rpm -e --nodeps java-1.8.0-openjdk-1.8.0.65-3.b17.el7.x86_64

[root@promote test]# rpm -e --nodeps java-1.7.0-openjdk-headless-1.7.0.91-2.6.2.3.el7.x86_64

[root@promote test]# rpm -e --nodeps java-1.8.0-openjdk-headless-1.8.0.65-3.b17.el7.x86_64

[root@promote test]# rpm -e --nodeps java-1.7.0-openjdk-1.7.0.91-2.6.2.3.el7.x86_64

[root@promote test]# rpm -e --nodeps tzdata-java-2015g-1.el7.noarch

[root@promote test]#

[root@promote test]# rpm -qa | grep java         ——重新查看JDK信息(已卸载)

javapackages-tools-3.4.1-11.el7.noarch

python-javapackages-3.4.1-11.el7.noarch

[root@promote test]#

 

从Oracle网站上下载最新的JDK文件

下载网址:http://www.oracle.com/technetwork/java/javase/downloads/index.html

JDK版本:jdk-8u111-linux-x64.rpm ——这里选择下载rpm格式的,方便安装

 

用浏览器下载完成后,默认是存放在/home/test/downloads文件夹下(安装了桌面环境),执行cd /home/test/downloads/ 跳转到downloads目录下(装了gnome和网络应用软件,也可以直接连接网址下载)

 

[root@promote test]# cd /home

[root@promote home]# ls

test

[root@promote home]# cd test/

[root@promote test]# ls

Desktop Documents Downloads Music Pictures Public Templates Videos

[root@promote test]# cd Downloads/

[root@promote Downloads]# ls

jdk-8u111-linux-x64.rpm         ——找到下载的jdk文件后将文件移到/usr/local目录下

[root@promote Downloads]# mv jdk-8u111-linux-x64.rpm /usr/local/

[root@promote Downloads]# cd /usr/local

[root@promote local]# ls

bin etc games include jdk-8u111-linux-x64.rpm lib lib64 libexec sbin share src

[root@promote local]#

[root@promote local]# rpm -ivh jdk-8u111-linux-x64.rpm     ——执行安装指令

Preparing... ################################# [100%]

Updating / installing...

1:jdk1.8.0_111-2000:1.8.0_111-fcs ################################# [100%]

Unpacking JAR files...

tools.jar...

plugin.jar...

javaws.jar...

deploy.jar...

rt.jar...

jsse.jar...

charsets.jar...

localedata.jar... ——安装完毕,JDK默认安装在/usr/java中

[root@promote local]# ls

bin etc games include jdk-8u111-linux-x64.rpm lib lib64 libexec sbin share src

[root@promote local]# cd ..

[root@promote usr]# ls ——跳转到/usr/java/,查看目录中的的文件

bin etc games include java lib lib64 libexec local sbin share src tmp

[root@promote usr]# cd java/

[root@promote java]# ll

total 4

lrwxrwxrwx. 1 root root 16 Nov 17 21:33 default -> /usr/java/latest

drwxr-xr-x. 9 root root 4096 Nov 17 21:33 jdk1.8.0_111

lrwxrwxrwx. 1 root root 22 Nov 17 21:33 latest -> /usr/java/jdk1.8.0_111

[root@promote java]# cd

[root@promote ~]#

/*执行下面三条指令验证java安装结果,都出来指令即说明安装成功*/

[root@promote ~]# java

[root@promote ~]# javac

[root@promote ~]# java -version

 

至此,Centos中java安装完毕!

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

配置环境变量

我的机器安装完jdk-7-linux-x64.rpm后不用配置环境变量也可以正常执行javac、java –version操作,但为了以后的使用方便,还是配置一下,具体操作如下:

修改系统环境变量文件

vi + /etc/profile

向文件里面追加以下内容:

JAVA_HOME=/usr/java/jdk1.8.0_111

JRE_HOME=/usr/java/jdk1.8.0_111/jre

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

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

export JAVA_HOME JRE_HOME PATH CLASSPATH

 

使修改生效

[root@localhost ~]# source /etc/profile   //使修改立即生效

[root@localhost ~]# echo $PATH   //查看PATH值

 

查看系统环境状态

[root@localhost ~]# echo $PATH

/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/usr/java/jdk1.8.0_25/bin:/usr/java/jdk1.8.0_25/jre/bin

[root@promote bin]# $JAVA_HOME
bash: /usr/java/jdk1.8.0_111: Is a directory

[root@promote bin]# $JRE_HOME
bash: /usr/java/jdk1.8.0_111/jre: Is a directory

[root@promote bin]#

============================================================

2.安装和配置tomcat

网上下载tomcat到本机,默认存放在/home/test/Downloads/目录下

下载网址:http://tomcat.apache.org/download-80.cgi

Tomcat版本包:apache-tomcat-8.0.39.tar.gz

 

[root@promote ~]# cd /home/test/

[root@promote test]# ls

Desktop Documents Downloads Music Pictures Public Templates Videos

[root@promote test]# cd Downloads/

[root@promote Downloads]# ls         ——进入Downloads目录查看文件

apache-tomcat-8.0.39.tar.gz

[root@promote Downloads]# mv apache-tomcat-8.0.39.tar.gz /usr/local

[root@promote Downloads]# cd /usr/local

[root@promote local]# ls         ——移动到/usr/local/目录下

apache-tomcat-8.0.39.tar.gz bin etc games include lib lib64 libexec sbin share src

 

[root@promote local]# mkdir tomcat8         ——创建tomcat目录并解压文件到此目录

[root@promote local]# tar -zxvf apache-tomcat-8.0.39.tar.gz -C /usr/local/tomcat8/

[root@promote local]# ls

apache-tomcat-8.0.39.tar.gz bin etc games include lib lib64 libexec sbin share src tomcat8

[root@promote local]#

[root@promote local]# cd tomcat8/

[root@promote tomcat8]# ls

apache-tomcat-8.0.39             ——发现多一级目录

[root@promote tomcat8]# cd apache-tomcat-8.0.39/

[root@promote apache-tomcat-8.0.39]# ls             ——进入目录后才是tomcat安装文件

bin conf lib LICENSE logs NOTICE RELEASE-NOTES RUNNING.txt temp webapps work

 

/*执行如下语句更换tomcat的安装目录,并删除原目录*/

[root@promote local]# mv /usr/local/tomcat8/apache-tomcat-8.0.39/* /usr/local/tomcat8/

[root@promote local]# cd tomcat8/

[root@promote tomcat8]# ls

apache-tomcat-8.0.39 bin conf lib LICENSE logs NOTICE RELEASE-NOTES RUNNING.txt temp webapps work

[root@promote tomcat8]# cd apache-tomcat-8.0.39/

[root@promote apache-tomcat-8.0.39]# ls

[root@promote apache-tomcat-8.0.39]# cd ..

[root@promote tomcat8]# rm -rf apache-tomcat-8.0.39/

[root@promote tomcat8]# ls                 ——子一级目录已删除

bin conf lib LICENSE logs NOTICE RELEASE-NOTES RUNNING.txt temp webapps work

[root@promote tomcat8]# cd ..

[root@promote local]# ls

apache-tomcat-8.0.39.tar.gz bin etc games include lib lib64 libexec sbin share src tomcat8

[root@promote local]# rm -rf apache-tomcat-8.0.39.tar.gz ——删除安装包

[root@promote local]#

 

至此,tomcat安装完成,tomcat配置的相关操作(包括修改端口、配置JVM和默认的java环境)网上资源有很多,此处不做描述。(后期如果有时间再整理)

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

启动和调试tomcat

[root@promote local]# /usr/local/tomcat8/bin/startup.sh ——启动tomcat

Using CATALINA_BASE: /usr/local/tomcat8

Using CATALINA_HOME: /usr/local/tomcat8

Using CATALINA_TMPDIR: /usr/local/tomcat8/temp

Using JRE_HOME: /usr/java/jdk1.8.0_111/jre

Using CLASSPATH: /usr/local/tomcat8/bin/bootstrap.jar:/usr/local/tomcat8/bin/tomcat-juli.jar

Tomcat started.                                                     ——tomcat启动成功,本机可以正常登录

[root@promote local]#

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

Tomcat启动成功后,并不意味着工作的结束,还需要放开tomcat配置的端口,否则外网是无法访问tomcat发布的应用程序的,具体操作如下(假设需要放开8080和80端口):

[root@promote bin]# firewall-cmd --zone=public --add-port=8080/tcp --permanent

success

[root@promote bin]# firewall-cmd --zone=public --add-port=80/tcp --permanent

success

[root@promote bin]# firewall-cmd --reload

success

[root@promote bin]#

 

——至此,tomcat的安装、配置和发布即完成。

 

============================================================

3.安装和配置mysql

 

CentOS 7的yum源中没有正常安装MySQL时的mysql-sever文件,需要去官网上下载

 

 

[root@promote local]# wget http://repo.mysql.com//mysql57-community-release-el7-9.noarch.rpm

[root@promote local]# rpm -ivh mysql57-community-release-el7-9.noarch.rpm

[root@promote local]# yum install mysql-community-server

 

安装完毕后,密码修改有些问题,参照:http://blog.csdn.net/yzl11/article/details/52643276

或者参照:《Mysql-01.安装和配置》中Linux系统下安装和配置mysql章节:https://my.oschina.net/u/3016592/blog/784166

 

MySql安装完毕后,创建数据库之后执行授权指令

grant all on db_name.* to user_name@localhost identified by 'password'; ——本地用户

grant all on db_name.* to user_name@'%' identified by 'password'; ——所有用户

grant all on db_name.* to user_name@'IP' identified by 'password'; ——指定IP用户

 

授权完毕后,默认情况下是无法访问的,因为CentOS防火墙屏蔽了mysql的3306端口,需要开启CentOS的3306端口,执行如下操作;

[root@promote ~]#

[root@promote ~]# firewall-cmd --zone=public --add-port=3306/tcp --permanent

success

[root@promote ~]# firewall-cmd --reload

success

[root@promote ~]#

 

另外,也可以执行如下指令停止或者禁用防火墙(不推荐)

systemctl stop firewalld.service #停止

systemctl disable firewalld.service #禁用

共有 人打赏支持
粉丝 0
博文 7
码字总数 7121
×
龙_沐风
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
* 金额(元)
¥1 ¥5 ¥10 ¥20 其他金额
打赏人
留言
* 支付类型
微信扫码支付
打赏金额:
已支付成功
打赏金额: