我是靠谱客的博主 欣慰红酒,最近开发中收集的这篇文章主要介绍centos7 下部署Java EE项目运行环境centos7 下部署Java EE项目运行环境,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

centos7 下部署Java EE项目运行环境

 

CentOS7.3部署环境搭建

一.虚拟机安装centos7.3

1.     新建虚拟机直接选择安装程序光盘映像文件:

2.      一直下一步,然后指定一下磁盘大小,再下一步后点击完成

3.     开启虚拟机 选择第一项进行安装 centos7.3

4.     语言选择简体中文

5.     本地化上 日期和时间->选择亚洲上海 键盘->选择汉语 语言支持->选择简体中文软件->选择本地介质 软件选择->GNOME桌面安装位置->选择自动分区网络连接名->选择并打开以太网最后点击开始安装

6.     安装界面选择设置root密码

7.     简单密码需要点击两次完成才能生效,等待安装完成

8.     安装完成重启系统,首次使用同意许可,设置独立用户名密码

 

二.安装tomcat8.0

1 准备工作

切换root用户登录,在usr文件夹下新建server目录,将apache-tomcat-8.0.20.tar.gz以及

jdk-7u80-linux-x64.rpm拷贝至文件夹下

2. 安装jdk

(1) 卸载预装openjdk环境

查看系统jdk信息命令:       rpm -qa | grep java

Centos预装有jdk环境:openjdk,需要先卸载掉

命令:rpm -e –nodeps (卸载项)

如:

rpm -e --nodepsjava-1.8.0-openjdk-1.8.0.102-4.b14.el7.x86_64

rpm -e --nodepsjavapackages-tools-3.4.1-11.el7.noarch

rpm -e --nodepsjava-1.8.0-openjdk-headless-1.8.0.102-4.b14.el7.x86_64

rpm -e --nodepstzdata-java-2016g-2.el7.noarch

rpm -e --nodepspython-javapackages-3.4.1-11.el7.noarch

rpm -e --nodepsjava-1.7.0-openjdk-headless-1.7.0.111-2.6.7.8.el7.x86_64

rpm -e --nodepsjava-1.7.0-openjdk-1.7.0.111-2.6.7.8.el7.x86_64


卸载完毕后,继续执行命令:rpm -qa | grep java

说明卸载完毕了

 

(2) 安装java se jdk环境

命令:     rpm -ivhjdk-7u80-linux-x64.rpm

JDK默认安装在/usr/java中

 

查看jdk是否安装成功

命令:        java

                   Javac

                   Java–version

 

使用gedit打开       etc目录下的profile

追加一下内容并保存:

JAVA_HOME=/usr/java/jdk1.7.0_80

JRE_HOME=/usr/java/jdk1.7.0_80/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

 

执行一下命令:

source /etc/profile  使修改立即生效

echo $PATH      查看PATH值


3. 安装tomcat8.0

 

(1)解压缩apache-tomcat-8.0.20.tar.gz

命令:tar -zxvf apache-tomcat-8.0.20.tar.gz

 

(2)修改apache-tomcat-8.0.20文件夹名称为tomcatAHJC

 

(3)启动tomcat

进入 tomcatAHJC/bin/目录下运行startup.sh

命令:cd tomcatAHJC/bin

           ./startup.sh

 

注:如遇到root用户执行./startup.sh命令时提示权限不足

执行命令即可:在tomcat bin目录下执行chmod u+x *.sh

 

打开浏览器输入地址:localhost:8080

若出现以上页面即代表启动成功

 

(4) 关闭tomcat

命令:./shutdown.sh

 

(5) 配置防火墙,开放8080端口号,让外网能够访问

命令:

firewall-cmd --zone=public--add-port=8080/tcp –permanent

firewall-cmd--reload              

移除端口:

firewall-cmd --zone=public --remove-port=8080/tcp --permanent


三.安装配置apache

1. 安装apache(版本为apache2.4.6)

命令:yum install httpd

默认安装即可

默认目录为:etc/httpd

常用命令:

systemctl starthttpd.service #启动apache

systemctl stophttpd.service #停止apache

systemctl restarthttpd.service #重启apache

systemctl enablehttpd.service #设置apache开机启动

 

卸载apache:

systemctl stophttpd.service

yum erasehttpd.x86_64

2. 修改apache配置

向conf/httpd.conf配置追加


#includeconf/balancer.conf

#提供基础的代理功能

LoadModuleproxy_module modules/mod_proxy.so

#提供负载均衡的功能

LoadModuleproxy_balancer_module modules/mod_proxy_balancer.so

#代理http协议

LoadModuleproxy_http_module modules/mod_proxy_http.so

 

#负载均衡的算法模块

LoadModulelbmethod_byrequests_module modules/mod_lbmethod_byrequests.so

LoadModuleslotmem_shm_module modules/mod_slotmem_shm.so

#兼容低版本访问

LoadModuleaccess_compat_module modules/mod_access_compat.so

 

ProxyRequests Off

ProxyPass /balancer://mycluster/ 

 

#设置代理的算法

#ProxySetlbmethod=bytraffic

 

#代理关联配置loadfactor可以分发请求权重,loadfactor越大,权重越大

<Proxybalancer://mycluster>

BalancerMember ajp://127.0.0.1:8009/loadfactor=1

</Proxy>

 

#负载均衡控制

<Location/balancer-manager>

   SetHandler balancer-manager

    Order Deny,Allow

    Allow from all

    #Allow from localhost

</Location>

 

Tomcat负载均衡使用ajp端口

 

注:

关闭8080端口,开启80端口,防火墙更改生效

firewall-cmd --zone=public --remove-port=8080/tcp --permanent

firewall-cmd --zone=public --add-port=80/tcp --permanent

firewall-cmd --reload

 

四.安装mysql

1. 查看系统里面有没有mysql 的repo

命令:yum repolist all |grep mysql

 

2. 如果没有发现,则需要配置repo

打开文件夹:/etc/yum.repos.d/

新建文件:mysql-community.repo

添加内容并保存:

# Enable to useMySQL 5.6

[mysql56-community]

name=MySQL 5.6Community Server

baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/6/$basearch/

enabled=1

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

 

3. 再次查看系统里面有没有mysql 的repo

如果存在则执行安装:yum installmysql-community-server

 

注:

安装过程中可能会出现错误:warning:rpmts_HdrFromFdno: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY

 

解决方法:打开文件夹:/etc/pki/rpm-gpg/                 新建文件:RPM-GPG-KEY-mysql

添加内容:

 

-----BEGIN PGP PUBLIC KEY BLOCK-----

Version: GnuPG v1.4.9 (SunOS)

mQGiBD4+owwRBAC14GIfUfCyEDSIePvEW3SAFUdJBtoQHH/nJKZyQT7h9bPlUWC3

RODjQReyCITRrdwyrKUGku2FmeVGwn2u2WmDMNABLnpprWPkBdCk96+OmSLN9brZ

fw2vOUgCmYv2hW0hyDHuvYlQA/BThQoADgj8AW6/0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LmuQT5NdKHGwHsXTPtl0klk4bQk4OajHsiy1BMahpT27jWjJlMiJc+IWJ0mghkK

Ht926s/ymfdf5HkdQ1cyvsz5tryVI3Fx78XeSYfQvuuwqp2H139pXGEkg0n6KdUO

etdZWhe70YGNPw1yjWJT1IhUBBgRAgAMBQJOdz3tBQkT+wG4ABIHZUdQRwABAQkQ

jHGNO1By4fUUmwCbBYr2+bBEn/L2BOcnw9Z/QFWuhRMAoKVgCFm5fadQ3Afi+UQl

AcOphrnJ

=443I

-----END PGP PUBLIC KEY BLOCK-----

 

然后继续安装:yum install mysql-community-server 即可

 

启动mysql:service mysqldstart

关闭mysql:service mysqldstop

登录mysql:mysql –p –uroot(注:默认安装无密码)

 

 

修改mysql密码为:123456

登录mysql后执行:

use mysql;

update user set password =Password('123456') where User = 'root';

flush privileges;

 

4. 安装workbench

 

(1).配置EPEL

执行命令:yum install epel-release.noarch

执行yum repolist,如果显示的信息里面有epel,则安装成功。

再执行:yum install tinyxml

 

(2).将mysql-workbench-community-6.3.9-1.el7.x86_64.rpm拷贝至

usr/mysql目录下,在该目录下执行:

yum install mysql-workbench-community-6.3.9-1.el7.x86_64.rpm

完成安装后在 应用程序->编程下 如果出现 mysql workbench表示安装成功



五.安装redis3.0.4

(1)      下载安装包:

在usr目录下执行命令:

wget http://download.redis.io/releases/redis-3.0.4.tar.gz

 

(2)      安装gcc编译器

yum -y install gcc automake autoconf libtool make

 

(3)      编译redis

命令:make

若报错:”jemalloc/jemalloc.h:没有那个文件或目录”

则执行:make MALLOC=libc

 

(4)      进行安装:

命令:make install

make install安装完成后,会在/usr/local/bin目录下生成下面几个可执行文件,它们的作用分别是:

redis-server:Redis服务器端启动程序

redis-cli:Redis客户端操作工具。也可以用telnet根据其纯文本协议来操作

redis-benchmark:Redis性能测试工具

redis-check-aof:数据修复工具

redis-check-dump:检查导出工具

 

(5)      修改配置:

编辑redis-3.0.4/redis.conf

将daemonize no改为daemonizeyes,使Redis进程在后台运行

 

查找到#masterauth <master-password>该行

修改为   masterauth 123456(顶格修改,前面不能留空格)

 

(6)      启动redis:

命令:./redis-server/usr/ redis-3.0.4/redis.conf

 

(7)      测试redis是否启动成功

进入usr/local/bin目录执行命令:       ./redis-cli

若出”127.0.0.1:6379>”  内容及表示启动成功。


最后

以上就是欣慰红酒为你收集整理的centos7 下部署Java EE项目运行环境centos7 下部署Java EE项目运行环境的全部内容,希望文章能够帮你解决centos7 下部署Java EE项目运行环境centos7 下部署Java EE项目运行环境所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(48)

评论列表共有 0 条评论

立即
投稿
返回
顶部