CentOS Install redis and MySQL

  • 2021-12-11 09:21:35
  • OfStack

10MySQL (MariaDB)

111, Description

MariaDB database management system is a branch of MySQL, which is mainly maintained by the open source community and licensed by GPL.

One of the reasons for developing this branch is that after Oracle acquired MySQL, there was a potential risk of closing the source of MySQL, so the community adopted the branch method to avoid this risk.

That is to say, MySQL will be charged soon

The MariaDB is fully compatible with the MySQL, including the API and the command line, making it an easy replacement for the MySQL.

The Red Hat Enterprise Linux/CentOS 7.0 release has switched the default database from MySQL to MariaDB.

122. Add MariaDB yum warehouse

Current environment: Alibaba Cloud's yum source

Direct yum install mariadb found that the version is particularly low, or version 5.5, and the official version 10.1 has been released

According to the programmer's urine, of course, download the latest official version ~


#  First of all,  RHEL/CentOS  And  Fedora  Add to the operating system  MariaDB  Adj.  YUM  Configuration file  MariaDB.repo  Files. 
mkdir mariadb.repo
#  Then edit and create mariadb.repo Warehouse documents 
vi /etc/yum.repos.d/MariaDB.repo
#  Re-enter  i  Enter edit mode and add repo Warehouse configuration 
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.1/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

Here spit out 1 wave ~ the official server is abroad, and the download is too slow! !

133. Install MariaDB


#  When  MariaDB  After adding the warehouse address, you can use the following 1 Line command easy installation  MariaDB . 
yum install MariaDB-server MariaDB-client -y

Start MariaDB related commands


systemctl start mariadb # Start MariaDB
systemctl stop mariadb # Stop MariaDB
systemctl restart mariadb # Restart MariaDB

systemctl enable mariadb # Set up startup 

144. Initialize MariaDB

Do not use the MariaDB database software immediately after confirming that it has been installed and started successfully. In order to ensure the security and normal operation of the database, it is necessary to initialize the database program first. This initialization involves the following five steps.

Set the password value of root administrator in the database (note that this password is not the password of root administrator in the system, the password value here should be empty by default, and you can press Enter directly).

Set the root administrator's unique password in the database.

:: Then delete the anonymous account and log in to the database remotely using the root administrator to ensure that the industry running on the database

Service security.

Delete the default test database and cancel the series 1 access rights of the test database.

Refresh the authorization list so that the initialized settings take effect immediately.

Note: Ensure that after the mariadb server starts, execute the command initialization

mysql_secure_installation

Then there is the 1-way Y to the end. You can also configure it according to your own needs, such as:

  出现 Disallow root login remotely? [Y/n]  --> 禁止root用户从远程登录, 可以选<n>呀 !

155. Set MariaDB to support Chinese

MariaDB and MySQL1, the database format is Latin, the default does not support Chinese

We have to change its data format to utf-8


#  Open configuration file 
vim /etc/my.cnf
#  First  dG  Empty the folder. Press if you don't empty it  g  Back to the first line,   Again  dG  Empty 
#  Press again  i  Enter edit mode   Copy the following code 
[mysqld]
character-set-server=utf8
collation-server=utf8_general_ci
log-error=/var/log/mysqld.log
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid

#
# include all files from the config directory
#
!includedir /etc/my.cnf.d

#  Finally   Press  Esc  Key, enter command mode,  :wq!  Save forced exit 

I'm afraid you forget how to operate vim, so the steps are all in it! Be intimate ~

166, Login

Note: Restart the database before logging in


systemctl restart mariadb 
mysql -uroot -p #  You are right, this is the login command 

#  After logging in 
MariaDB [(none)]> \s #  View encoding settings 

Other commands are like MySQl

If you don't understand, go and read my blog on MySQL

20redis installation

211, yum Installation


# The premise is to configure Alibaba Cloud yum Source, epel Source 
# Check to see if there are redis Bag 
yum list redis
# Installation redis
yum install redis -y
# Installed and started redis
systemctl start redis

There are also two scenarios without configuring the source:

Solution 1: Go to my last blog and configure domestic sources

Option 2: Keep looking at ⬇

Check whether redis is working

redis-cli # redis Client Tools

# After entering the interactive environment, execute ping and return pong to indicate successful installation

127.0.0.1:6379 > ping

PONG

222, source code compilation and installation redis


# 1. Download redis Source code,   Yes  cd /opt  Download to this directory 
wget http://download.redis.io/releases/redis-4.0.10.tar.gz
# 2. Decompression 
tar -zxf redis-4.0.10.tar.gz
# 3. Switch redis Source catalog 
cd redis-4.0.10
# 4. Compile source file 
make && make install 
# 5. Start redis Server side 
./redis-server

Description of redis executable file


./redis-benchmark #  Used for carrying out redis Tools for performance testing 
./redis-check-dump # Used to fix the problem dump.rdb Documents 
./redis-cli # redis Client of 
./redis-server # redis Server side of 
./redis-check-aof #  Used to fix the problem AOF Documents 
./redis-sentinel #  Used for cluster management 

By default, redis-server runs as a non-daemon, and the default service port is 6379.

Here, redis can run normally ~

The following is about security ~

233. Switch redis port

Purpose: Since redis port is 6379 by default, hackers can use this point to invade your server, so they have to change a port to run redis that they can't think of

Another one is that after configuring redis, when starting redis-server server, it will not be mounted by default. It will run the server in the background, so you can run the client without switching windows.


# 1.  Switch to the destination directory first 
cd /opt/redis-4.0.10/
# 2.  Create a file 
touch redis-6380.conf
# 3.  Create a folder 
mkdir 6380
# 4.  Open this file 
vi /opt/redis-4.0.10/redis-6380.conf
 # 5.  Press  i  Go to Edit Default and copy the following code 
port 6380 #  Run in 6380 Adj. redis Database instance 
daemonize yes #  Running in the background redis 
pidfile /opt/redis-4.0.10/6380/redis.pid #  Storage redis pid File of 
loglevel notice #  Log level 
logfile "/opt/redis-4.0.10/6380/redis.log" #  Specify redis Generate directory of log files 
dir /opt/redis-4.0.10/6380 #  Specify redis Directory of data folder 
protected-mode yes
requirepass  123 #  Settings redis The password, change the password yourself 
#  And then   Press  Esc  Key, enter command mode, enter  :wq!  Save and force exit 
#  For compatibility, delete the comments when copying! ! ! 

You can also configure the file path according to your own needs ~

The start redis server command becomes like this

redis-server redis-6380.conf 

The startup client command has also changed


redis-cli -p 6380 -a 123
  # -p  Settings redis Linked port 
  # -a  Display the password filled in 

#  Or 
redis-cli -p 6380
auth 123

Summarize

The above is the site for you to collect CentOS installation configuration MySQL, redis all content, I hope the article can help you solve CentOS installation configuration MySQL, redis encountered program development problems.


Related articles: