Home  >  Article  >  Database  >  How to install Redis and Tomcat under Centos

How to install Redis and Tomcat under Centos

WBOY
WBOYforward
2023-05-29 08:25:05787browse

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的安装目录)
  • cd /root/redis  (进入这个目录)
  • wget https://download.redis.io/releases/redis-6.0.13.tar.gz  (将Redis压缩包下载到当前打开的目录下)

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  (解压缩)
  • mv redis-6.0.13 redis6  (改名为redis6,这个目录就是Redis的安装目录)
  • cd redis6  (进入这个安装目录)

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

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

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目录)
  • ./redis-server  (启动Redis)

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

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目录)
  • ./redis-cli shutdown  (关闭Redis)

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  (新建目录放置压缩包)
  • cd /root/tomcat
  • wget https://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-8/v8.5.66/bin/apache-tomcat-8.5.66.tar.gz

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

Unzip

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

Modify the configuration file

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

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
  • 在文件末尾加入以下内容:
    expert CATALINA_HOME=/root/tomcat/tomcat8  (值为Tomcat安装目录)
    export PATH=$PATH:${CATALINA_HOME}/bin
  • source /etc/profile  (使修改生效)

Test Tomcat

  1. Start Tomcat and execute the following command:

  • startup.sh

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

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!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete