Home > Database > Redis > body text

How to install Redis and Tomcat under Centos

WBOY
Release: 2023-05-29 08:25:05
forward
784 people have browsed it

Install Redis and Tomcat on the server

Redis installation

Preparation

Execute the following command on the server to download the Redis compressed package. You can ignore the first two steps and do it yourself Just select a suitable directory:

  • mkdir /root/redis  (新建目录作为Redis的安装目录)
    Copy after login
  • cd /root/redis  (进入这个目录)
    Copy after login
  • wget https://download.redis.io/releases/redis-6.0.13.tar.gz  (将Redis压缩包下载到当前打开的目录下)
    Copy after login

Or go here to select the appropriate version and Place it on the server.

Unzip

After the download is complete, execute the following command:

  • tar -zxvf redis-6.0.13.tar.gz  (解压缩)
    Copy after login
  • mv redis-6.0.13 redis6  (改名为redis6,这个目录就是Redis的安装目录)
    Copy after login
  • cd redis6  (进入这个安装目录)
    Copy after login

Compile

In this step, you need to ensure that you have gcc on your server, because you need to use gcc to compile. We can use the following command to check whether you have gcc on your server:

  • gcc -v
    Copy after login

If you have gcc on your server, we can see the content as shown below:
How to install Redis and Tomcat under Centos

Continue Next we officially start compilation, execute the following command and wait for it to complete:

  • make
    Copy after login

If successful, we will see the content as shown below:
How to install Redis and Tomcat under Centos

Test

After the previous step is successful, we perform the following steps to test whether Redis is installed successfully:

  • cd src  (进入Redis安装目录下的src目录)
    Copy after login
  • ./redis-server  (启动Redis)
    Copy after login

If successful, you will see something like the following picture:
How to install Redis and Tomcat under Centos

Background startup

If this happens every time If started, we will not be able to continue executing other commands on the server unless Redis is stopped, so we do not want Redis to start in this way, then we have to let it start in the background and execute the following command:

  • cd /root/redis/redis6/src  (进入src目录)
    Copy after login
  • mkdir conf  (新建配置文件目录)
    Copy after login
  • cp ../redis.conf conf/  (将其原来的配置文件复制一份到刚刚新建的配置文件目录中)
    Copy after login
  • vim conf/redis.conf  (编辑这个配置文件)
    Copy after login
  • :set nu  (这里必须手动输入命令,因为是在文件内部里的vim操作,这个命令是显示文件的行号)
    Copy after login
  • 然后找到224行左右,将 daemonize no 修改为 daemonize yes  (表示由不允许后台允许到允许后台运行)
    Copy after login
  • :wq  (保存离开)
    Copy after login
  • ./redis-cli shutdown  (关闭一下Redis,以免发生端口占用)
    Copy after login
  • ./redis-server conf/redis.conf  (以指定的配置文件启动Redis,测试其是否变成后台运行,成功的话是没有任何提示的)
    Copy after login

Close Redis

Redis will naturally be shut down after it is started. The following is the shutdown command of Redis:

  • cd /root/redis/redis6/src  (进入src目录)
    Copy after login
  • ./redis-cli shutdown  (关闭Redis)
    Copy after login

Remote connection

Redis itself does not recommend remote connection due to security issues, but it can also be connected remotely and only needs to be modified. The contents of the configuration file redis.conf are as shown below:

How to install Redis and Tomcat under Centos

We only need to comment out bind 127.0.0.1 or modify it to bind 0.0.0.0, and then change protected Change -mode yes to protected-mode no. After saving and exiting, restart Redis with this configuration file. It should be noted that the redis port can be set in the following lines of this picture. If it needs to be connected remotely, this port must be open.

Tomcat installation

Preparation

Download the Tomcat compressed package and place it on the server. You can directly download it to the server through the following command:

  • mkdir /root/tomcat  (新建目录放置压缩包)
    Copy after login
  • cd /root/tomcat
    Copy after login
  • wget https://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-8/v8.5.66/bin/apache-tomcat-8.5.66.tar.gz
    Copy after login

You can also click here to download it locally and then upload it to the server.

Unzip

  • cd /root/tomcat/  (进入压缩包所在目录)
    Copy after login
  • tar -zxvf apache-tomcat-8.5.66.tar.gz  (解压缩)
    Copy after login
  • mv apache-tomcat-8.5.66 tomcat8  (重命名解压后的目录名)
    Copy after login

Modify the configuration file

  • cd tomcat8  (进入Tomcat安装目录)
    Copy after login
  • vim conf/server.xml  (修改端口等信息)
    Copy after login

How to install Redis and Tomcat under Centos
As shown in the picture above, find this location and modify the port. You only need to modify 8080 to another port. Just save and exit. There will be no modifications here for the time being. Use port 8080 directly.

Configure Tomcat environment variables

Execute the following command to configure Tomcat environment variables:

  • vim /etc/profile
    Copy after login
  • 在文件末尾加入以下内容:
    expert CATALINA_HOME=/root/tomcat/tomcat8  (值为Tomcat安装目录)
    export PATH=$PATH:${CATALINA_HOME}/bin
    Copy after login
  • source /etc/profile  (使修改生效)
    Copy after login

Test Tomcat

  1. Start Tomcat and execute the following command:

  • startup.sh
    Copy after login

Wait quietly for a while...

  1. Access in a local browser, assuming your server IP is 112.125.18.23, then the address we are going to access is 112.125.18.23:8080 , just press Enter. If Tomcat is installed and configured successfully, we will see the web page as shown below:
    How to install Redis and Tomcat under Centos

Close Tomcat

Just execute the following command:

  • shutdown.sh
    Copy after login

The above is the detailed content of How to install Redis and Tomcat under Centos. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!