Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

CentOS 7 how to build the basic Java development environment JDK, Maven, Tomcat, MySQL,Redis

2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces CentOS 7 how to build the basic Java development environment JDK, Maven, Tomcat, MySQL,Redis, the article is very detailed, has a certain reference value, interested friends must read it!

First, set up the JDK environment

In general, the JDK that comes with CentOS 7 is OpenJDK, which is different from Oracel SUN JDK. In order to maintain the same JDK configuration and usage habits as on PC, it can be replaced with Oracle SUN JDK.

(1) Uninstall OpenJDK

First query the existing installation related to Java with the command:

Rpm-qa | grep java

The results are as follows:

Python-javapackages-3.4.1-11.el7.noarchjava-1.8.0-openjdk-1.8.0.171-8.b10.el7_5.x86_64tzdata-java-2018e-3.el7.noarchjavapackages-tools-3.4.1-11.el7.noarchjava-1.8.0-openjdk-headless-1.8.0.171-8.b10.el7_5.x86_64 uninstall one by one via rpm-e xx (xx is the above package), and check again and find that it has been downloaded clean The operation process is as follows: [root@centos jvm] # rpm-e java-1.8.0-openjdk-1.8.0.171-8.b10.el7_5.x86_64 [root@centos jvm] # rpm-e java-1.8.0-openjdk-headless-1.8.0.171-8.b10.el7_5.x86_64 [root@centos jvm] # rpm-e tzdata-java-2018e-3.el7.noarch [root@centos jvm] # rpm-e javapackages- Tools-3.4.1-11.el7.noarch [root@centos jvm] # rpm-e python-javapackages-3.4.1-11.el7.noarch [root@centos jvm] # rpm-qa | grep java [root@centos jvm] # java-versionbash: / usr/bin/java: No such file or directory

(2) download Oracle SUN JDK

Download JDK (https://www.oracle.com/technetwork/java/javase/downloads/index.html) from the Oracle website and select the appropriate version of the RPM installation package for CentOS 7.

For example: jdk-8u171-linux-x64.rpm

(3) install Oracle SUN JDK

Under the permission of root, you can install the downloaded version through the rpm command. Command example:

Rpm-ivh jdk-8u171-linux-x64.rpm

(4) verify the installation

Enter the command java-version. In addition, you can view the java installation version under the default installation path through ls / usr/java. The procedure is as follows:

[root@centos_vm2 tools] # java-versionjava version "1.8.0mm 171" Java (TM) SE Runtime Environment (build 1.8.0_171-b11) Java HotSpot (TM) 64-Bit Server VM (build 25.171-b11, mixed mode) [root@centos_vm2 tools] # ls / usr/javadefault jdk1.8.0_171-amd64 latest

(5) modify the configuration file of environment variables

Add the following lines to the / etc/profile file:

# java environment export JAVA_HOME=/usr/java/jdk1.8.0_171-amd64 export CLASSPATH=.:$ {JAVA_HOME} / jre/lib/rt.jar:$ {JAVA_HOME} / lib/dt.jar:$ {JAVA_HOME} / lib/tools.jar export PATH=$PATH:$ {JAVA_HOME} / bin

Then execute the source / etc/profile command to make the configuration effective; in some other Linux environments (such as Deepin), you can achieve the same effect by modifying / etc/bash.bashrc

Second, build the Maven development environment

(1) download the Maven installation package

Go to the apache website to download maven (http://maven.apache.org/download.cgi), select the desired version and download

(2) install Maven

It is recommended to install the directory: / usr/local/maven/, needs to create this directory with root permission:

Mkdir / usr/local/maven

First, extract a directory of the downloaded installation package (the author's installation package and installation package are all under the / var/ftp/tools/ directory):

Tar-zxvf apache-maven-3.5.4-bin.tar.gz

Then copy the directory to the installation directory:

Cp-r apache-maven-3.5.4/* / usr/local/maven/

You can then view the list of files and directories in the installation directory:

[root@centos_vm2 tools] # ls / usr/local/mavenbin boot conf lib LICENSE NOTICE README.txt

(3) modify the environment variable configuration file:

Add the environment variable MAVEN_HOME to the / etc/profile file and add it to PATH. Combined with the changes caused by the above JAVA environment variable, the total is as follows:

# java environment export JAVA_HOME=/usr/java/jdk1.8.0_171-amd64 export CLASSPATH=.:$ {JAVA_HOME} / jre/lib/rt.jar:$ {JAVA_HOME} / lib/dt.jar:$ {JAVA_HOME} / lib/tools.jar export MAVEN_HOME=/usr/local/maven export PATH=$PATH:$ {JAVA_HOME} / bin:$ {MAVEN_HOME} / bin

Execute the following command to make the configuration file effective

Source / etc/profile

(4) verify the installation

Execute mvn-v to view the version, and execute echo $MAVEN_HOME to view the environment variables, as follows:

[root@centos tools] # mvn-vApache Maven 3.5.4 (1edded0938998edf8bf061f1ceb3cfdeccf443fe 2018-06-18T02:33:14+08:00) Maven home: / usr/local/mavenJava version: 1.8.000171, vendor: Oracle Corporation, runtime: / usr/java/jdk1.8.0_171-amd64/jreDefault locale: en_US, platform encoding: UTF-8OS name: "linux", version: "3.10.0-693.el7.x86_64", arch: "amd64", family: "unix" [root@centos tools] # echo $MAVEN_HOME/usr/local/maven

Third, build the Tomcat environment

(1) download the Tomcat installation package

Go to the apache website to download Tomcat (http://tomcat.apache.org/), select the desired version and download

(2) install Tomcat

It is recommended to install the directory / usr/local/tomcat and extract the package:

Tar-zxvf apache-tomcat-9.0.10.tar.gz

Then copy the extracted directory to / usr/local/tomcat, as follows:

[root@centos usr] # su root [root@centos usr] # cd / usr/local [root@centos local] # mkdir tomcat [root@centos local] # cd / var/ftp/tools [root@centos tools] # cp-r apache-tomcat-9.0.10/* / usr/local/tomcat/

(3) Open the 8080 service port of Tomcat

Execute the following command to open port 8080:

Firewall-cmd-zone=public-add-port=8080/tcp-permanent

The meaning of the parameters in the above command:

-- zone # scope

-- add-port=8080/tcp # add port in the format: Port / communication protocol

-- permanent # is in effect forever. Without this parameter, it will expire after restart.

Then restart the firewall:

Firewall-cmd-reload

After that, under / usr/local/tomcat/bin, execute if you need to start the Tomcat service

. / startup.sh

To stop the Tomcat service, execute:

. / shutdown.sh

Fourth, make Tomcat service (optional step)

In many cases, it is convenient to manage Tomcat services, which usually includes the following steps:

(1) set environment variables, users and groups:

Environment variables can be set either through / etc/profile or in tomcat/bin/setenv.sh:

For example, set the relevant path in / etc/profile:

Export CLASS_PATH=.:$JAVA_HOME/libexport CATALINA_HOME=/usr/local/tomcatexport CATALINA_BASE=/usr/local/tomcatexport PATH=$PATH:$ {JAVA_HOME} / bin:$ {CATALINA_HOME} / bin

Then set the running parameters through / usr/local/tomcat/bin/setenv.sh. The contents of the file are as follows:

# add tomcat pid CATALINA_PID= "$CATALINA_BASE/tomcat.pid" # add java opts JAVA_OPTS= "- server-XX:MetaspaceSize=256M-XX:MaxMetaspaceSize=1024m-Xms512M-Xmx1024M-XX:MaxNewSize=256m"

You can configure the users and groups of the tomcat service runtime, and give them the appropriate permissions:

[root@snails ~] # getent group tomcat | | groupadd-r tomcat [root@snails ~] # getent passwd tomcat | | useradd-r-d / opt-s / bin/nologin-g tomcat tomcat [root@snails ~] # chown-R tomcat:tomcat / usr/local/tomcat [root@snails ~] # chmod a+rwx-R / usr/local/tomcat/logs

The above command getent is used for query. If no query is found, execute | | the following command; the parameter-r after groupadd or useradd indicates the system group and system user; the parameter-s / bin/nologin after useradd indicates that the user cannot log in directly and is only used by system jobs

Note: the source of this section is from: https://www.jianshu.com/p/29ecd624046f

(1) Service description document:

When managing a service with service or systemctl, you need to create a script file in the service management directory (that is, / usr/lib/systemd/system directory, or / lib/systemd/system directory, which is the soft connection to the former)

Vim / usr/lib/systemd/system/tomcat.service

To manage the start and stop of the service, examples are as follows:

[Unit] Description=Apache Tomcat 9After=network.target [Service] Type=forkingPIDFile=/usr/local/tomcat/tomcat.pidExecStart=/usr/local/tomcat/bin/startup.sh ExecReload=/bin/kill-s HUP $MAINPID ExecStop=/bin/kill-s QUIT $MAINPID PrivateTmp=true User=tomcatGroup=tomcat [Install] WantedBy=multi-user.target

The parameters in the above are described as follows:

[Unit]: description of the service

Description: describes the service

Documentation (optional): service documentation

After: describes the class of service

[Service] setting of service running parameters

Type=forking is a form of background operation. Available values are: simple, forking, oneshot, notify, dbus, where:

> simple (default): systemd believes that the service will be started immediately. The service process will not fork. If the service is going to start other services, do not start using this type unless the service is socket-activated.

> forking:systemd believes that the service starts successfully when the service process fork and the parent process exits. For regular daemons (daemon), unless you are sure that this startup method does not meet the requirements, you can use this type of startup. Using this startup type, you should also specify PIDFile=, so that systemd can track the main process of the service.

> oneshot: this option applies to services that perform only one task and then exit immediately. You may need to set RemainAfterExit=yes at the same time so that systemd still thinks the service is active after the service process exits.

> notify: same as Type=simple, but the contract service sends a signal to systemd when it is ready. The implementation of this notification is provided by libsystemd-daemon.so.

> dbus: if started in this way, when the specified BusName appears on the DBus system bus, systemd thinks the service is ready.

PIDFile: process ID file path. For the above tomcat configuration, the corresponding tomat/bin/catalina.sh needs to add the CATALINA_PID parameter. The reference method is # OS specific support at the beginning of the script. Add changes before the line, as shown in the following example:

#-CATALINA_PID=/usr/local/tomcat/tomcat.pid# OS specific support. $var _ must_ be set to either true or false.

ExecStartPre (optional): what to do before startup

ExecStart: specific run commands for the service

ExecReload: to restart the command, the kill command-s parameter is to send a signal to the process, and HUP is the signal to rerun

ExecStop: to stop the command, the kill command-s parameter sends a signal to the process, and QUIT is the signal to exit the program.

User, Group (optional): for users and groups used at run time, these two parameters do not appear in the configuration if the tomcat directory is not bound to this user

PrivateTmp=True represents a separate temporary space allocated to the service

Note: the start, restart and stop commands of [Service] all require absolute paths. If User and Group are not specified, the default is root.

[Install] related settings for service installation, which can be set to multi-user

Note: this section is referenced from: https://blog.csdn.net/younger_china/article/details/52539522

Then execute systemctl enable tomcat to start automatically, or stop the currently running tomcat through shutdown.sh under the tomcat/ bin subdirectory, and then execute systemctl start tomcat to run it.

(2) Boot blocking timeout:

In the new tomcat environment, there are no log files in the tomcat/ logs subdirectory without running it. Log files will be generated after the first run, and the most common problem is to locate the problem based on the catalina.out log file.

Tomcat startup sometimes fails due to timeout. The common reason is that the security random number takes time. You can see the alarm similar to the following in the startup log:

19-Jul-2018 22:43:02.156 WARNING [main] org.apache.catalina.util.SessionIdGeneratorBase.createSecureRandom Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [149396] milliseconds.19-Jul-2018 22:43:02.174 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/ usr/local/tomcat/webapps/ROOT] has finished in [149652] ms

This is due to the fact that in the server environment, there are few random number reference environment variables in the system, which leads to slow calculation. There are two solutions:

Method 1: you can configure JRE to use non-blocking Entropy Source:

Add this line to the catalina.sh:

-Djava.security.egd=file:/dev/./urandom

For example:

# Make the umask available when using the org.apache.catalina.security.SecurityListener

JAVA_OPTS= "$JAVA_OPTS-Djava.security.egd=file:/dev/urandom-Dorg.apache.catalina.security.SecurityListener.UMASK= `umask`"

Method 2: open $JAVA_HOME/jre/lib/security/java.security (this is the file in this installation and find the following:

Replace securerandom.source=file:/dev/random with:

Securerandom.source=file:/dev/./urandom

Note: the period in the middle of the path is in some versions where securerandom.source is set to / dev/urandom and it still uses / dev/random, so a workaround is used. If the version test verifies that it works well with securerandom.source=file:/dev/urandom, there is no need to use a path with a period.

(3) incomplete release of original thread and IP port when Tomcat is stopped

During the development and testing of some Tomcat web project versions, it is found that the shutdown.sh under tomcat/bin is not completely closed, and you need to manually use the kill process number to shut it down completely. Usually, this kind of problem is caused by the non-daemon thread that is opened and does not stop. You can take several steps:

Step 1: check the Tomcat process number

Ps-ef | grep tomcat

Step 2: analyze active threads with jstack tools included in JDK

$JAVA_HOME/bin/jstack

For a specific process number

Step 3: find the main thread main, and check whether the self-built thread is a daemon thread. If not, modify the corresponding Java code, set it to the daemon thread after an action similar to new Thread (), and then rerelease the version verification.

Step 4: if the IP port number is not released in time, in order not to affect the debugging, you can temporarily shut down the process through kill:

Kill

Later, you need to check the self-occupied port code to release port resources in time when the program exits.

Step 5: multiple instances of tomcat directories are running. If the shutdown fails, you need to record the process ID of each instance, and add the following actions in front of the corresponding tomcat/bin/catalina.sh code:

# if [- z "$CATALINA_PID"]; then CATALINA_PID=$PRGDIR/CATALINA_PID cat $CATALINA_PIDfi#

In the appropriate tomcat/bin/shutdown.sh:

Exec "$PRGDIR" / "$EXECUTABLE" stop "$@"

Add a parameter to force the stop, that is:

Exec "$PRGDIR" / "$EXECUTABLE" stop-force "$@"

5. Create a Maven multi-module project based on web project

A large number of Java projects are web projects, for enterprise applications, these projects are usually multi-module projects. In order to facilitate management, the project is usually layered. The top level is a parent project, and the parent contains multiple sub-modules. A single sub-module can be a collection of common packages and libraries, or it can be divided into sub-modules according to their functions. Or in order to facilitate the generation of a package required by a specific production environment, or the test package of the test environment also opens a separate package file that the user generates. The following is an example of a multi-module project that creates a basic web project.

(1) create a top-level project parent

Assuming that the top-level project is named sample-parent, enter the following command after entering the parent directory where it is located:

Mvn archetype:generate-DgroupId=com.sample-DartifactId=sample-parent-DarchetypeArtifactId=maven-archetype-quickstart

Note: in the example, groupId is com.sample and the project name is sample-parent. At the end of the command, you can add a parameter-DinteractiveMode=false to indicate that there is no need for interactive confirmation. This parameter is not added in this example, and you can reconfirm the version during execution. If you do not need to change it, enter directly.

After the above command is executed, the top-level project is created. The default packaging result of the project is jar, but the purpose of using the top-level project is only to manage multiple modules that do not output jar packages at the top level. To do this, go to the sample-parent directory, delete the src folder, and then modify the pom.xml file to change jar to pom.

(2) create a sub-project common

Put some of the most commonly used common classes, packages, etc., in a dependent sub-module, which is very conducive to code sharing in the team. For this reason, go to the sample-parent directory first, and then create a sample- sample-parent sub-project. In this way, the created sub-project automatically becomes a sub-module of the Commons. Enter the command as follows:

Mvn archetype:generate-DgroupId=com.sample-DartifactId=sample-common-DarchetypeArtifactId=maven-archetype-quickstart

After the command execution is complete, you can see that the sample-common is generated in the sample-parent directory, which contains the src directory and the pom.xml file. At the same time, the following is automatically added to the pom.xml file in the sample-parent directory:

Sample-common

Modify the pom.xml file in the sample-common directory to remove sample-common and 1.0-SNAPSHOT, and add jar

Because groupId and version will inherit groupId and version,packaging in sample-parent to set the packaging mode to jar

(3) create a sub-project web

Suppose you need to publish a war package that can run in Tomcat, which is located in a sub-module sample-web. After entering the sample-parent directory, you can execute the following command to create a web project:

Mvn archetype:generate-DgroupId=com.sample-DartifactId=sample-web-DarchetypeArtifactId=maven-archetype-webapp

Note: parameter-DarchetypeArtifactId=maven-archetype-webapp indicates that this is the creation of a web project. The default package is war package.

(4) add dependency inheritance and dependency

List the dependent version number through the properties tag in the pom.xml of the parent project, and then list the various dependent jar packages and modules, and then inherit the packages and modules already declared by the parent project when adding the dependencies required by the sub-project. There is no need to specify the specific version number. A similar mechanism applies to the parent project by declaring the maven plug-in required by build, and then adding the required maven plug-in to the child project without specifying the specific version number.

6. Build a MySQL environment

(1) download MySQL

Download the community version of MySQL (MySQL Community Server) from the MySQL official website download page (https://dev.mysql.com/downloads/mysql/), for example, choose to download: MySQL Community Server 5.7,

Installation instructions (Installation structions) can also be found on this page. According to the accompanying server operating system version CentOS7, this download is as follows:

Red Hat Enterprise Linux 7 / Oracle Linux 7 (x86, 64-bit), RPM Bundle 5.7.22 570.3m

(mysql-5.7.22-1.el7.x86_64.rpm-bundle.tar)

(2) upload the version to the CentOS server and extract the installation package

You can upload the version to a directory on the server with the help of client tools such as MobaXterm, for example: / var/ftp/tools

Then execute the extract command:

Tar-xvf mysql-5.7.22-1.el7.x86_64.rpm-bundle.tar

(3) install MySQL Server

Under the unzipped directory, execute the following command to install each rpm package:

Rpm-ivh mysql-community-common-5.7.22-1.el7.x86_64.rpmrpm-ivh mysql-community-libs-5.7.22-1.el7.x86_64.rpmrpm-ivh mysql-community-libs-compat-5.7.22-1.el7.x86_64.rpmrpm-ivh mysql-community-client-5.7.22-1.el7.x86_64.rpmrpm-ivh mysql-community-server-5.7.22-1.el7.x86_64.rpm

Note: if the system has previously installed other MySQL and MariaDB, the installation may fail due to conflicts. You should uninstall the previous installation first. You can query the previously installed rpm package through rpm-qa | grep mysql, and then uninstall the previous rpm package through rpm-e xxx.

(4) start MySQL

Execute the following command: (note that the service name of MySQL under CentOS is mysqld, and that of SUSE Linux is mysql)

Service mysqld start

Or

Systemctl start mysqld

After the installation is complete, mysqld is located after / usr/sbin/mysqld,reboot restarts the system:

> you can view the running status through systemctl status mysqld

> you can view the process number via ps-ef | grep ^ mysql

> you can view network services via netstat-anpl | grep mysql

> you can check the version number through mysqladmin-- version

(5) configure root user password

During the initial installation, MySQL generates an installation log (located at / var/log/mysqld.log), which records a random initial password, logs in with the root user and this initial password, and then modifies the root password

For example: vi / var/log/mysqld.log, find the following line

2018-07-15T16:11:30.955449Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.2018-07-15T16:11:30.956742Z 1 [Note] A temporary password is generated for root@localhost: / yBner_jl6Ii

Log in with user root initial password / yBner_j16Ii:

Mysql-uroot-p/yBner_jl6Ii

The operation process is as follows:

Mysql: [Warning] Using a password on the command line interface can be insecure.Welcome to the MySQL monitor. Commands end with; or\ g.Your MySQL connection id is 8Server version: 5.7.22Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or'\ h' for help. Type'\ c'to clear the current input statement.mysql > set password=password ('11211'); ERROR 1819 (HY000): Your password does not satisfy the current policy requirementsmysql > set password=password ('127212yZp'); ERROR 1819 (HY000): Your password does not satisfy the current policy requirementsmysql > set password=password (' 121132 MySQL'); Query OK, 0 rows affected, 1 warning (0.00 sec)

(6) configure remote login permissions

After logging in to MySQL, modify the login permissions of root, and perform the following two steps in turn

GRANT ALL PRIVILEGES ON *. * TO 'root'@'%' IDENTIFIED BY' 121132 MySQL 'WITH GRANT OPTION

Flush privileges

Note: the 121132@MySQL after BY in the command is the password of root. Enter the actual password for actual operation.

(7) use PC client tools to connect to MySQL

Such as the HedisSQL tool

(8) remedial measures when forgetting root password

Step 1: modify the configuration file / etc/my.cnf and add a new line after [mysqld] with the content skip-grant-tables, which is used to check the password of Fangtong MySQL.

Step 2: restart MySQL, for example, execute: service mysqld restart or systemctl restart mysqld

Step 3: log in to MySQL as a root user and log in to MySQL:mysql-uroot-p (enter directly and the password is empty)

Then execute it in turn on the MySQL command line:

Update user set authentication_string=password ('123456') where user='root';flush privileges

Note: the above 123456 is the new password. In practice, please enter the specific password.

Then execute quit to exit the MySQL command line

Step 4: restore the configuration file / etc/my.cnf, remove the skip-grant-tables added in the first step, and restart MySQL (see step 2)

(9) the root password is so simple that it fails to set the password.

After logging in to MySQL, under the MySQL command line, enter the command:

Set global validate_password_policy=0

The complexity of password verification can be set to 0

Enter the command:

Set global validate_password_length=0

The minimum password length can be set to 4

After that, you can enter the command to view password-related parameters:

SHOW VARIABLES LIKE 'validate_password%'

7. Build Redis environment

(1) download Redis

Download the Redis installation package from the Redis official website (https://redis.io/download), which contains the source code; copy the installation package to a directory on the server and extract it, for example:

Tar zxvf redis-5.0.0.tar.gz

(2) enter the decompressed directory, for example:

Cd redis-5.0.0/

(3) compiler

Before compiling, make sure that the system and gcc are installed, if not, install gcc (for example, execute yum install gcc), and then execute the following command:

Makecd srcmake install PREFIX=/usr/local/redis

Note: the above PREFIX=/usr/local/redis means to install to the / usr/local/redis directory

If the compilation fails because you did not install gcc before, delete the redis directory you just extracted, re-extract it, re-enter the extracted directory, and then recompile

(4) copy the configuration file to the installation directory

Execute the following commands in turn:

Cd..mkdir / usr/local/redis/etccp redis.conf / usr/local/redis/etc/

(5) Common configuration parameters

The configuration parameters are stored in the redis.conf file, which needs to be edited to configure, for example:

Vim / usr/local/redis/etc/redis.conf

Daemonize: if you need to run in the background, change the value of this item to yes

Pdifile: put the pid file in / var/run/redis.pid, which can be configured to another address

Bind: specifies that redis will only receive requests from this IP. If not set, all requests will be processed. It is best to set this item in the production process.

Port: listening port. Default is 6379.

Timeout: sets the timeout for client connection (in seconds)

Loglevel: levels are divided into four levels, debug,revbose,notice and warning. Notice is generally enabled in production environment.

Logfile: configure the log file address, using standard output by default, that is, printing on the port of the command line terminal

Database: sets the number of databases. The default database is 0

Save: sets the frequency of database mirroring by redis

Rdbcompression: whether to compress when making a mirror backup

Dbfilename: file name of the backup file that is mirrored

Dir: the path where the files backed up by database mirroring are placed

Slaveof: set this database to be a slave database for other databases

Masterauth: when the primary database connection requires password authentication, set it here

Requirepass: set the password that the client needs to use before making any other assignments after connecting

Maxclients: limit the number of clients connected at the same time

Maxmemory: sets the maximum memory that redis can use

Appendonly: when appendonly mode is enabled, redis appends every write operation received to the appendonly.aof file, and when redis restarts, it returns to the previous state of the file.

Appendfsync: sets how often appendonly.aof files are synchronized

Vm_enabled: whether to enable virtual memory support

Vm_swap_file: sets the path to the swap file for virtual memory

Vm_max_momery: sets the maximum physical memory that redis will use when virtual memory is enabled. Default is 0.

Vm_page_size: sets the size of virtual memory pages

Vm_pages: sets the total number of page for swap files

Vm_max_thrrads: sets the number of threads that vm IO uses simultaneously

(5) configure redis to start in the background

Edit the redis.conf file:

Vi / usr/local/redis/etc/redis.conf

Change daemonize no to daemonize yes in the file

(6) optional step 1: add redis to boot and edit / etc/rc.local file:

Vi / etc/rc.local

Just add content to it:

/ usr/local/redis/bin/redis-server / usr/local/redis/etc/redis.conf

Note: the command redis-server is called when booting, and the configuration file is redis.conf. This command can also be used to start the redis service manually.

(7) optional step 2: common operations

To stop redis manually, you can execute the following command:

Pkill redis-server

Or

/ usr/local/redis/bin/redis-cli shutdown

To uninstall redis, you can delete the above installation directory after stopping redis:

Rm-rf / usr/local/redis

Perform client connection redis

/ usr/local/redis/bin/redis-cli

(8) configure redis as a service that can be managed through systemctl

Refer to the above tomcat service configuration file, and similarly write a file describing the redis service (the meaning of the configuration parameters can be found in the above tomcat service configuration file). First, create the service description file and edit it:

Vim / usr/lib/systemd/system/redis.service

Examples of file contents are as follows:

[Unit] Description=RedisAfter=syslog.target network.target remote-fs.target nss-lookup.target [Service] Type=forking#PID Should be the same as redis.confPIDFile=/var/run/redis_6379.pid#For start: redis-server path and redis.conf pathExecStart=/usr/local/redis/bin/redis-server / usr/local/redis/etc/redis.conf#For restartExecReload=/bin/kill-s HUP $MAINPID#For stopExecStop=/bin/kill-s QUIT $MAINPIDPrivateTmp=true [Install] # System startup modeWantedBy=multi-user.target

Then perform a refresh of the system service configuration

Systemctl daemon-reload

Then activate the boot and start the redis service automatically

Systemctl enable redis

After that: you can view the status of the redis service with the following command

Systemctl status redis

Stop the redis service manually with the following command

Systemctl stop redis

Start redis manually with the following command

Systemctl start redis

Manually restart the redis service with the following command

System restart redis above is all the content of this article "how to build basic Java Development Environment JDK, Maven, Tomcat, MySQL,Redis in CentOS 7". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report