centOS7下如何搭建memcached+mongodb+jdk+tomcat的基础应用环境

本文详细介绍如何在CentOS7系统中安装并配置memcached、mongodb、jdk和tomcat,包括解决安装过程中的常见问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

centOS7下如何搭建memcached+mongodb+jdk+tomcat的基础应用环境

本文主要介绍自己在centOS7下搭建服务环境的内容,略有简陋,格式也未过多调整,如有遇到其余问题,可私聊与我讨论。

  • memcached安装
  • mongodb安装
  • jdk安装
  • tomcat安装

memcached安装

  • 安装libevent

    libevent即Memcached的依赖包。

    1. 下载或者复制libevent到/opt文件夹下
      mv /setup/libevent-2.0.20-stable.tar.gz /opt/
    2. 在/opt文件夹下,解压libevent
      tar –zxvf libevent-2.0.20-stable.tar.gz
    3. 进入libevent目录
      cd libevent-2.0.20-stable
    4. 编辑安装libevent
      sudo ./configure
      sudo make
      sudo make install
      安装过程中如果make报错,可能是没有安装GCC,可执行如下指令自动安装GCC
      yum –y install gcc
  • 安装memcached

    1. 下载或者复制memcached到/opt文件夹下
      mv /setup/memcached-1.4.21.tar.gz /opt/
      1. 到/opt目录下解压memcached
        tar –zxvf memcached-1.4.21.tar.gz
      2. 进入memcached目录
        cd memcached-1.4.21
      3. 编译安装memcached
        sudo ./configure
        sudo make
        当报如下错误:
        这里写图片描述
        先安装依赖包automake-1.14.1:
        ① 下载或者复制automake到/opt文件夹下
        mv /setup/automake-1.14.1.tar.gz /opt/
        ② 到/opt目录下解压automake
        tar -zxvf automake-1.14.1.tar.gz
        ③ 进入automake目录
        cd automake-1.14.1
        ④ 编译安装automake
        sudo ./configure
        sudo make
        sudo make install
        再执行sudo autoreconf –ivf,最后需进行重新编译:
        sudo ./configure
        sudo make
        sudo make install
      4. 查看安装结果
        ls -al /usr/local/bin/memcached
      5. 启动memcached
        /usr/local/bin/memcached -d -u root –m 512 -p 11211 –P /tmp/memcached.pid
  • 启动memcached报错 解决方式1
    /usr/local/bin$ /usr/local/bin/memcached –d -u root –m 512 -p 11211 -P /tmp/memcached.pid
    /usr/local/bin/memcached: error while loading shared libraries: libevent-2.0.so.5: cannot open shared object file: No such file or directory
    /usr/local/lib下安装有libevent2.0相关的包。

    解决方法:建立软连接
    sudo ln -s /usr/local/lib/libevent-2.0.so.5 /usr/lib/libevent-2.0.so.

  • 启动memcached报错 解决方式2

    如果启动不了,执行如下:
    安装memcache时,需要建立文件索引或者说文件连接(link),类似windows下的快捷方式
    启动服务时出现:
    error while loading shared libraries: libevent-2.0.so.5: cannot open shared object file: No such file or directory
    root@localhost>whereis libevent-2.0.so.5
    libevent-2.0.so.5: /usr/local/lib/libevent-2.0.so.5
    root@localhost> ldd /usr/local/bin/memcached (ldd指令不熟悉的去查看下)
    libevent-2.0.so.5 => not found (没有找到该文件)
    libpthread.so.0 => /lib64/libpthread.so.0 (0x00002b83fce0e000)
    libc.so.6 => /lib64/libc.so.6 (0x00002b83fd029000)
    librt.so.1 => /lib64/librt.so.1 (0x00002b83fd381000)
    /lib64/ld-linux-x86-64.so.2 (0x00002b83fc9b0000)
    root@localhost> LD_DEBUG=libs ./memcached –v 找到默认路径 /usr/lib/
    root@localhost>sudo ln -s /usr/lib/libevent-2.0.so.5 /usr/lib64/libevent-2.0.so.5
    root@localhost>sudo ldd /usr/local/bin/memcached
    libevent-2.0.so.5 => /usr/lib64/libevent-2.0.so.5 (0x00002b83fcbcd000)
    libpthread.so.0 => /lib64/libpthread.so.0 (0x00002b83fce0e000)
    libc.so.6 => /lib64/libc.so.6 (0x00002b83fd029000)
    librt.so.1 => /lib64/librt.so.1 (0x00002b83fd381000)
    /lib64/ld-linux-x86-64.so.2 (0x00002b83fc9b0000)

mongodb安装

  • 安装mongodb数据库

安装方式如下:


  1. 下载或者复制移动mongodb到/opt文件夹下

mv /setup/mongodb.tar.gz /opt/

  • 到/opt目录下解压mongodb

    tar –zxvf mongodb.tar.gz

  • 进入mongodb目录

    cd mongodb

  • 创建data文件夹及logs文件夹,创建mongodb.conf配置文件

    //存放数据库
    mkdir data
    //存放日志信息
    mkdir logs
    //创建、编辑mongodb.conf配置文件
    touch mongodb.conf 或者 vi mongodb.conf
    vi mongodb.conf 进入编辑配置文件
    port=27017 #端口号
    dbpath=/opt/mongodb/data/ #数据库路径
    logpath=/opt/mongodb/logs/mongodb.log #日志输出文件路径
    logappend=true #日志输出方式
    fork=true #以守护进程的方式运行,创建服务器进程

  • 进入bin文件夹,启动mongodb数据库
    cd /opt/mongodb/bin
    ./mongod –config /opt/mongodb/mongodb.conf
    这里写图片描述

  • 在浏览器地址栏输入http://IP:27017/,如果显示下面一行字,则说明安装成功

    You are trying to access MongoDB on the native driver port .For http diagnostic access, add 1000 to the port number

  • 通过MongoDBVUE客户端连接
    Linux下部署的MongoDB,需将linux防火墙关闭,CentOS7.0 64位关闭防火墙执行

    CentOS 6指令:
    chkconfig iptables on #开启防火墙(重启生效)
    chkconfig iptables off #关闭防火墙(重启生效)
    service iptables stop #关闭防火墙(即时生效)
    service iptables start # 启动防火墙(即时生效)
    service iptables status #查看防火墙状态
    CentOS 7指令:
    systemctl stop firewalld #关闭防火墙
    systemctl disable firewalld.service #禁止防火墙开启启动
    systemctl status firewalld #查看防火墙状态

  • 若启动报如下错误

    Assertion: 14043:clear tmp files caught exception exception: locale::facet::_S_create_c_locale name not valid
    exception in initAndListen: 14043 clear tmp files caught exception exception: locale::facet::_S_create_c_locale name not valid, terminating


  • 则需要在启动mongodb前输入export LC_ALL=”C”


    • 导入数据
      MongoDB的数据库导入命令为:mongorestore –h 要导入的数据库的ip地址,-port 要导入的数据库的端口号,-d 要导入的数据库名称 -directoryperdb 导出的目录\数据库备份的目录。

    导入数据库指令:
    mongorestore -h 114.215.206.138 –port 27017 –drop i:\xxx\db\
    • 使用可视化工具
      MongoDB可视化工具文件位于准备文件目录下。解压后运行安装文件,按照提示完成工具的安装。
      这里写图片描述

    jdk安装

    本处示例jdk1.7.0_79的安装
    1. 下载或者复制移动jdk到/opt/文件夹下
    mv /setup/jdk-7u79-linux-x64.rpm /opt/
    核实是否有执行权限:
    ls -al
    授予执行权限:
    chmod +x jdk-7u79-linux-x64.rpm
    2. 查看、卸载、安装jdk
    确认JDK版本:
    rpm -qa|grep jdk
    rpm -qa|grep gcj
    卸载JDK:
    rpm -e –nodeps jdk版本
    安装JDK:
    rpm -ivh jdk-7u79-linux-x64.rpm
    3. 配置环境变量
    用文本编辑器打开/etc/profile,在profile文件末尾加入:
    vi /etc/profile
    export JAVA_HOME=/opt/jdk1.7.0_79 #JDK安装路径
    export PATH= $JAVA_HOME/bin: $PATH
    export
    CLASSPATH=.: $JAVA_HOME/lib/dt.jar: $JAVA_HOME/lib/tools.jar
    编辑完保存退出:按键盘ESC 输入“:wq”即可。
    输入命令source /etc/profile使修改后的profile生效。
    4. 验证jdk是否安装
    输入java -version验证是否安装成功,如下图:
    这里写图片描述

    tomcat安装

    本处示例apache-tomcat-6.0.37的安装


    1. 下载或者复制移动tomcat到/opt/文件夹下
      mv /setup/apache-tomcat-6.0.37.tar.gz /opt/
    2. 进入apache-tomcat-6.0.37文件目录
      cd apache-tomcat-6.0.37
      若需设置端口,请根据实际需求修改端口:
      vi /opt/apache-tomcat-6.0.37/conf/server.xml
      标红端口根据实际环境配置修改,本项目分布部署在多台服务器上,因此使用默认端口:

    [root@iZ23k4z9esoZ conf]# vi server.xml
      <?xml version='1.0' encoding='utf-8'?>
      <!--
      Licensed to the Apache Software Foundation (ASF) under one or more
      contributor license agreements.  See the NOTICE file distributed with
      this work for additional information regarding copyright ownership.
      The ASF licenses this file to You under the Apache License, Version 2.0
      (the "License"); you may not use this file except in compliance with
      the License.  You may obtain a copy of the License at
    
          http://www.apache.org/licenses/LICENSE-2.0
    
      Unless required by applicable law or agreed to in writing, software
      distributed under the License is distributed on an "AS IS" BASIS,
      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      See the License for the specific language governing permissions and
      limitations under the License.
    -->
      <!-- Note:  A "Server" is not itself a "Container", so you may not
         define subcomponents such as "Valves" at this level.
         Documentation at /docs/config/server.html
     -->
    <Server port="8005" shutdown="SHUTDOWN">
    
        <!--APR library loader. Documentation at /docs/apr.html -->
        <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
        <!--Initialize Jasper prior to webapps are loaded. Documentation at /docs/jasper-howto.html -->
        <Listener className="org.apache.catalina.core.JasperListener" />
        <!-- Prevent memory leaks due to use of particular java/javax APIs-->
        <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
      <!-- JMX Support for the Tomcat server. Documentation at /docs/non-existent.html -->
      <Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" />
      <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
    
      <!-- Global JNDI resources
           Documentation at /docs/jndi-resources-howto.html
      -->
      <GlobalNamingResources>
        <!-- Editable user database that can also be used by
             UserDatabaseRealm to authenticate users
        -->
        <Resource name="UserDatabase" auth="Container"
                  type="org.apache.catalina.UserDatabase"
                  description="User database that can be updated and saved"
                  factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
                  pathname="conf/tomcat-users.xml" />
      </GlobalNamingResources>
    
      <!-- A "Service" is a collection of one or more "Connectors" that share
           a single "Container" Note:  A "Service" is not itself a "Container",
           so you may not define subcomponents such as "Valves" at this level.
           Documentation at /docs/config/service.html
       -->
      <Service name="Catalina">
    
        <!--The connectors can use a shared executor, you can define one or more named thread pools-->
        <!--
        <Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
            maxThreads="150" minSpareThreads="4"/>
        -->
    
    
        <!-- A "Connector" represents an endpoint by which requests are received
             and responses are returned. Documentation at :
             Java HTTP Connector: /docs/config/http.html (blocking & non-blocking)
             Java AJP  Connector: /docs/config/ajp.html
             APR (HTTP/AJP) Connector: /docs/apr.html
             Define a non-SSL HTTP/1.1 Connector on port 8080
        -->
        <Connector port="8080" protocol="HTTP/1.1"
                   connectionTimeout="20000"
                   redirectPort="8443" 
    URIEncoding="UTF-8" /> 
      <!-- URIEncoding="UTF-8" 处理乱码 -->
        <!-- A "Connector" using the shared thread pool-->
        <!--
        <Connector executor="tomcatThreadPool"
                   port="8080" protocol="HTTP/1.1"
                   connectionTimeout="20000"
                   redirectPort="8443" />
        -->
        <!-- Define a SSL HTTP/1.1 Connector on port 8443
             This connector uses the JSSE configuration, when using APR, the
             connector should be using the OpenSSL style configuration
             described in the APR documentation -->
        <!--
        <Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
                   maxThreads="150" scheme="https" secure="true"
                   clientAuth="false" sslProtocol="TLS" />
        -->
    
        <!-- Define an AJP 1.3 Connector on port 8009 -->
        <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
    
    
        <!-- An Engine represents the entry point (within Catalina) that processes
             every request.  The Engine implementation for Tomcat stand alone
             analyzes the HTTP headers included with the request, and passes them
             on to the appropriate Host (virtual host).
             Documentation at /docs/config/engine.html -->
    
        <!-- You should set jvmRoute to support load-balancing via AJP ie :
        <Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">
        -->
        <Engine name="Catalina" defaultHost="localhost">
    
          <!--For clustering, please take a look at documentation at:
              /docs/cluster-howto.html  (simple how to)
              /docs/config/cluster.html (reference documentation) -->
          <!--
          <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
          -->
    
          <!-- The request dumper valve dumps useful debugging information about
               the request and response data received and sent by Tomcat.
               Documentation at: /docs/config/valve.html -->
          <!--
          < Valve className="org.apache.catalina.valves.RequestDumperValve"/>
          -->
    
          <!-- This Realm uses the UserDatabase configured in the global JNDI
               resources under the key "UserDatabase".  Any edits
               that are performed against this UserDatabase are immediately
               available for use by the Realm.  -->
          <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
                 resourceName="UserDatabase"/>
    
          <!-- Define the default virtual host
               Note: XML Schema validation will not work with Xerces 2.2.
           -->
          <Host name="localhost"  appBase="webapps"
                unpackWARs="true" autoDeploy="true"
                xmlValidation="false" xmlNamespaceAware="false">
    
            <!-- SingleSignOn valve, share authentication between web applications
                 Documentation at: /docs/config/valve.html -->
            <!--
            <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
            -->
    
            <!-- Access log processes all example.
                 Documentation at: /docs/config/valve.html -->
            <!--
            <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
                   prefix="localhost_access_log." suffix=".txt" pattern="common" resolveHosts="false"/>
            -->
    
          </Host>
        </Engine>
      </Service>
    </Server>

    结束语

    markdown编辑器不是很会用,如有格式问题请原谅。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值