Centos7 安装 jdk8 解压版、Mysql5.7解压版、Redis5解压版

JDK安装

1、装备安装包

这里我放在了 /root/share 目录下,完整路径是 /root/share/jdk-8u45-linux-x64.tar.gz
装备安装到**/usr/local/java8** 目录

[root@11 ~]# cd /usr/local

2.解压,移到Java8文件夹下

[root@11 local]# tar -vxzf /root/share/jdk-8u45-linux-x64.tar.gz
[root@11 local]# ls
bin  etc  games  include  jdk1.8.0_221  lib  lib64  libexec  sbin  share  src
[root@11 local]# mv jdk1.8.0_221 java8
[root@11 local]# ls
bin  etc  games  include  java8  lib  lib64  libexec  sbin  share  src

3.配置Java环境变量

   [root@11 local]# vim /etc/profile #使用vim打开配置文件(也可以直接下载到本地修改再传回服务器,替换原文件)
   
   #在文件结尾追加环境变量 (vim 使用 i 键进入编辑模式,esc键退出编辑,进入常规模式,dd快速删除一行,:wq保存退出,:q!强制退出不保存)
   
   JAVA_HOME=/usr/local/java8
   PATH=$JAVA_HOME/bin:$PATH
   CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tool.jar
   export JAVA_HOME
   export PATH
   export CLASSPATH
   
   #这里其实和windows的环境变量差不多,只不过,path用:分割

保存并退出编辑器,这时候可以选择重启或者使用命令使改动生效。

[root@11 local]# source /etc/profile

4.验证Java

[root@11 local]# java -version
java version "1.8.0_221"
Java(TM) SE Runtime Environment (build 1.8.0_221-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.221-b11, mixed mode)
[root@11 local]# javac -version
javac 1.8.0_221

Mysql 5.7

1、装备安装包

这里我放在了 /root/share 目录下,完整路径是 /root/share/mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
装备安装到**/usr/local/mysql5.7** 目录
数据库文件存放在**/data/mysqlData5.7** 目录

[root@11 ~]# cd /usr/local
[root@11 local]# ls
bin  etc  games  include  java8  lib  lib64  libexec  mysql-5.7.24-linux-glibc2.12-x86_64  sbin  share  src

2、解压,移动到mysql5.7目录下

[root@11 local]#  tar -zxvf /root/share/mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
[root@11 local]# ls
bin  etc  games  include  java8  lib  lib64  libexec  mysql-5.7.24-linux-glibc2.12-x86_64  sbin  share  src
[root@11 local]# mv mysql-5.7.24-linux-glibc2.12-x86_64 mysql5.7 
[root@11 local]# ls
bin  etc  games  include  java8  lib  lib64  libexec  mysql5.7  sbin  share  src

3、创建data目录

[root@11 local]# cd /
[root@11 /]# ls
bin  boot  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
[root@11 /]# mkdir -p data/mysqlData5.7
[root@11 /]# ls data
mysqlData5.7

4、创建mysql用户和用户组

[root@11 /]# groupadd mysql
[root@11 /]# useradd -r -s /sbin/nologin -g mysql mysql -d /usr/local/mysql5.7

#useradd -r参数表示mysql用户是系统用户,不可用于登录系统
#

5、改变mysql目录权限,之前是root权限,现在设置成mysql权限

[root@11 /]# chown -R mysql.mysql /usr/local/mysql5.7/
[root@11 /]# cd  /usr/local/mysql5.7/
[root@11 mysql5.7]# ll
总用量 36
drwxr-xr-x.  2 mysql mysql  4096 8月  24 14:57 bin
-rw-r--r--.  1 mysql mysql 17987 10月  4 2018 COPYING
drwxr-xr-x.  2 mysql mysql    55 8月  24 14:57 docs
drwxr-xr-x.  3 mysql mysql  4096 8月  24 14:57 include
drwxr-xr-x.  5 mysql mysql   230 8月  24 14:57 lib
drwxr-xr-x.  4 mysql mysql    30 8月  24 14:57 man
-rw-r--r--.  1 mysql mysql  2478 10月  4 2018 README
drwxr-xr-x. 28 mysql mysql  4096 8月  24 14:57 share
drwxr-xr-x.  2 mysql mysql    90 8月  24 14:57 support-files

6、初始化数据库

[root@11 mysql5.7]# ./bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql5.7/ --datadir=/data/mysqlData5.7
2020-08-24 15:15:00 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
2020-08-24 15:15:04 [WARNING] The bootstrap log isn't empty:
2020-08-24 15:15:04 [WARNING] 2020-08-24T07:15:00.742852Z 0 [Warning] --bootstrap is deprecated. Please consider using --initialize instead
2020-08-24T07:15:00.743504Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000)
2020-08-24T07:15:00.743515Z 0 [Warning] Changed limits: table_open_cache: 431 (requested 2000)

7、把mysql放到本地系统服务中

[root@11 mysql5.7]# cp -a ./support-files/mysql.server /etc/init.d/mysqld

8、编辑的 /etc 下面的my.cnf文件(这里我直接上传了以前配置好的一个简单)

[root@11 mysql5.7]# mv /root/share/my.cnf   /etc/my.cnf
mv:是否覆盖"/etc/my.cnf"? y
[root@11 mysql5.7]# vi /etc/my.cnf
[mysqld]

basedir=/usr/local/mysql5.7
datadir=/data/mysqlData5.7
socket=/tmp/mysql.sock
user=mysql
port=3306
character-set-server=utf8mb4

[mysql]
default-character-set=utf8mb4

[client]
default-character-set=utf8mb4

# 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

#########################################################################


[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
~
~

[root@11 mysql5.7]# chmod 644 /etc/my.cnf 

最后这一步非常重要,上传的文件权限是777,mysql会认为文件不安全,然后忽略掉配置文件,使用默认配置

9、尝试启动mysql服务

[root@11 mysql5.7]# service mysqld start
Starting MySQL.Logging to '/data/mysqlData5.7/11.err'.
 SUCCESS! 

10、查看初始密码,尝试登陆mysql

[root@11 mysql5.7]# 

 - [ ] cat /root/.mysql_secret

# Password set for user 'root@localhost' at 2020-08-24 15:15:00 
DZbrxjuRh3zX
[root@11 mysql5.7]# bin/mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.24

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

11、登陆成功,修改密码,开启允许远程登录

mysql> SET PASSWORD FOR 'root'@localhost=PASSWORD('123456');
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> select 'host' from user where user='root';
+------+
| host |
+------+
| host |
+------+
1 row in set (0.00 sec)

mysql> update user set host = '%' where user ='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

12、配置mysql环境变量,修改/etc/profile文件,加入开机自启。

[root@localhost ~]# vi /etc/profile

1.在文件结尾追加

export PATH=$PATH:/usr/local/mysql5.7/bin

2.使其生效

[root@11 mysql5.7]# source /etc/profile

3.配置开机启动

[root@11 mysql5.7]# chmod +x /etc/init.d/mysqld
[root@11 mysql5.7]# chkconfig --add mysqld
[root@11 mysql5.7]# chkconfig --list

注:该输出结果只显示 SysV 服务,并不包含
原生 systemd 服务。SysV 配置数据
可能被原生 systemd 配置覆盖。 

      要列出 systemd 服务,请执行 'systemctl list-unit-files'。
      查看在具体 target 启用的服务请执行
      'systemctl list-dependencies [target]'。

mysqld          0:关    1:关    2:开    3:开    4:开    5:开    6:关
netconsole      0:关    1:关    2:关    3:关    4:关    5:关    6:关
network         0:关    1:关    2:开    3:开    4:开    5:开    6:关

列表显示mysql的服务,并且3,4,5都是on的话则成功

4.重启电脑,查看mysql运行状态

[root@11 mysql5.7]#  reboot

[root@11 ~]#  service mysqld status
 SUCCESS! MySQL running (1216)

Redis 5

1、准备安装包,安装依赖

安装包放在了 /root/share 目录下,完整路径是 /root/share/redis-5.0.8.tar.gz
装备安装到**/usr/local/redis-5.0.8** 目录

[root@11 ~]# cd /usr/local
[root@11 local]# yum install -y gcc
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.bfsu.edu.cn
 * extras: mirrors.bfsu.edu.cn
 * updates: mirrors.bfsu.edu.cn
软件包 gcc-4.8.5-39.el7.x86_64 已安装并且是最新版本
无须任何处理

2、解压 、编译

[root@11 local]#  tar -zxvf /root/share/redis-5.0.8.tar.gz
[root@11 local]# ls
bin  etc  games  include  java8  lib  lib64  libexec  mysql5.7  redis-5.0.8  sbin  share  src
[root@11 local]# cd redis-5.0.8
[root@11 redis-5.0.8]# make 
[root@11 redis-5.0.8]#make install

3、启动

redis-server redis.conf
5631:C 24 Aug 2020 17:38:03.796 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
5631:C 24 Aug 2020 17:38:03.797 # Redis version=5.0.8, bits=64, commit=00000000, modified=0, pid=5631, just started
5631:C 24 Aug 2020 17:38:03.797 # Configuration loaded
5631:M 24 Aug 2020 17:38:03.798 * Increased maximum number of open files to 10032 (it was originally set to 1024).
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 5.0.8 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                   
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 5631
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           http://redis.io        
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               

5631:M 24 Aug 2020 17:38:03.800 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
5631:M 24 Aug 2020 17:38:03.800 # Server initialized
5631:M 24 Aug 2020 17:38:03.800 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
5631:M 24 Aug 2020 17:38:03.800 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
5631:M 24 Aug 2020 17:38:03.800 * Ready to accept connections

4、配置

[root@11 redis-5.0.8]# vi redis.conf
  1. 设置后台启动 daemonize=yes
  2. 开启允许远程连接 注释掉bind 127.0.0.1
  3. 开启密码登录 requirepass 123456

5、启动,验证配置文件无误

[root@11 redis-5.0.8]# redis-server redis.conf
5638:C 24 Aug 2020 17:48:50.350 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
5638:C 24 Aug 2020 17:48:50.350 # Redis version=5.0.8, bits=64, commit=00000000, modified=0, pid=5638, just started
5638:C 24 Aug 2020 17:48:50.350 # Configuration loaded
[root@11 redis-5.0.8]# redis-cli
127.0.0.1:6379> auth 123456
OK
127.0.0.1:6379> keys *
(empty list or set)
127.0.0.1:6379> quit

5、设置开机自启

1、进入安装目录,检查默认配置文件,确认设置为守护进程 daemonize yes

[root@yy ~]# cd /usr/local/redis-5.0.8
[root@yy redis-5.0.8]# ll
总用量 280
-rw-rw-r--.  1 root root 118338 3月  12 23:07 00-RELEASENOTES
-rw-rw-r--.  1 root root     53 3月  12 23:07 BUGS
-rw-rw-r--.  1 root root   2381 3月  12 23:07 CONTRIBUTING
-rw-rw-r--.  1 root root   1487 3月  12 23:07 COPYING
drwxrwxr-x.  6 root root    192 8月  24 17:30 deps
-rw-r--r--.  1 root root     92 9月   9 09:26 dump.rdb
-rw-rw-r--.  1 root root     11 3月  12 23:07 INSTALL
-rw-rw-r--.  1 root root    151 3月  12 23:07 Makefile
-rw-rw-r--.  1 root root   6888 3月  12 23:07 MANIFESTO
-rw-rw-r--.  1 root root  20555 3月  12 23:07 README.md
-rw-rw-r--.  1 root root  61801 8月  24 17:48 redis.conf
-rwxrwxr-x.  1 root root    275 3月  12 23:07 runtest
-rwxrwxr-x.  1 root root    280 3月  12 23:07 runtest-cluster
-rwxrwxr-x.  1 root root    373 3月  12 23:07 runtest-moduleapi
-rwxrwxr-x.  1 root root    281 3月  12 23:07 runtest-sentinel
-rw-rw-r--.  1 root root   9710 3月  12 23:07 sentinel.conf
drwxrwxr-x.  3 root root   8192 8月  24 17:37 src
drwxrwxr-x. 11 root root    182 3月  12 23:07 tests
drwxrwxr-x.  8 root root   4096 3月  12 23:07 utils

[root@yy redis-5.0.8]# vim redis.conf
# TCP keepalive.
#
# If non-zero, use SO_KEEPALIVE to send TCP ACKs to clients in absence
# of communication. This is useful for two reasons:
#
# 1) Detect dead peers.
# 2) Take the connection alive from the point of view of network
#    equipment in the middle.
#
# On Linux, the specified value (in seconds) is the period used to send ACKs.
# Note that to close the connection the double of the time is needed.
# On other kernels the period depends on the kernel configuration.
#
# A reasonable value for this option is 300 seconds, which is the new
# Redis default starting with Redis 3.2.1.
tcp-keepalive 300

################################# GENERAL #####################################

# By default Redis does not run as a daemon. Use 'yes' if you need it.
# Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
daemonize yes
######…………

下面其它部分省略,重点在上面最后一行 daemonize yes 默认no之前配置的时候已经改成了yes就不需要变了

2、进入utils 目录,找到安装服务的脚本install_server.sh 并执行

安装注意事项:

  1. 直接敲回车表示使用默认值
  2. 输错了只能用del键删除,Ctrl+C退出程序
  3. redis-server的路径一定要核对清楚
[root@yy redis-5.0.8]# cd utils
[root@yy utils]# ll
总用量 52
-rw-rw-r--. 1 root root  593 3月  12 23:07 build-static-symbols.tcl
-rw-rw-r--. 1 root root 1303 3月  12 23:07 cluster_fail_time.tcl
-rw-rw-r--. 1 root root 1098 3月  12 23:07 corrupt_rdb.c
drwxrwxr-x. 2 root root   60 3月  12 23:07 create-cluster
-rwxrwxr-x. 1 root root 2149 3月  12 23:07 generate-command-help.rb
drwxrwxr-x. 3 root root   31 3月  12 23:07 graphs
drwxrwxr-x. 2 root root   39 3月  12 23:07 hashtable
drwxrwxr-x. 2 root root   70 3月  12 23:07 hyperloglog
-rwxrwxr-x. 1 root root 9567 3月  12 23:07 install_server.sh
drwxrwxr-x. 2 root root   63 3月  12 23:07 lru
-rw-rw-r--. 1 root root 1277 3月  12 23:07 redis-copy.rb
-rwxrwxr-x. 1 root root 1352 3月  12 23:07 redis_init_script
-rwxrwxr-x. 1 root root 1047 3月  12 23:07 redis_init_script.tpl
-rw-rw-r--. 1 root root 1762 3月  12 23:07 redis-sha1.rb
drwxrwxr-x. 2 root root  135 3月  12 23:07 releasetools
-rwxrwxr-x. 1 root root 3787 3月  12 23:07 speed-regression.tcl
-rwxrwxr-x. 1 root root  693 3月  12 23:07 whatisdoing.sh
[root@yy utils]# 

###执行安装脚本#######在提示地方直接敲回车表示默认值######输错了用del键删除###########
[root@yy utils]# ./install_server.sh
Welcome to the redis service installer
This script will help you easily set up a running redis server
#######指定端口 默认为6379##########################################################
Please select the redis port for this instance: [6379] 
Selecting default: 6379
#######指定配置文件,会自动拷贝生成这个文件,不需要手动取这个目录添加###################
Please select the redis config file name [/etc/redis/6379.conf] 
Selected default - /etc/redis/6379.conf
#######指定日志文件地址,使用默认就可以了############################################
Please select the redis log file name [/var/log/redis_6379.log] 
Selected default - /var/log/redis_6379.log
#######指定数据文件保存地址,这个最好是自定义,后期迁库备份什么的好找##################
Please select the data directory for this instance [/var/lib/redis/6379] /data/redisData 
######redis的启动服务路径,这个一定要核对清楚,######################################
######5.0的版本没lib目录,在安装目录下就能直接使用redis-server来启动服务##############
######但是这个文件其实在src目录下#################
Please select the redis executable path [/usr/local/bin/redis-server] /usr/local/redis-5.0.8/src/redis-server
Selected config:
Port           : 6379
Config file    : /etc/redis/6379.conf
Log file       : /var/log/redis_6379.log
Data dir       : /data/6379
Executable     : /usr/local/redis-5.0.8/src/redis-server
Cli Executable : /usr/local/bin/redis-cli
Is this ok? Then press ENTER to go on or Ctrl-C to abort.
Copied /tmp/6379.conf => /etc/init.d/redis_6379
Installing service...
Successfully added to chkconfig!
Successfully added to runlevels 345!
/var/run/redis_6379.pid exists, process is already running or crashed
Installation successful!
[root@yy utils]# 

Installation successful!就是成功了,在/etc/init.d/目录下可以看到redis_6379这个自启动脚本

[root@yy utils]# cd /etc/init.d
[root@yy init.d]# ll
总用量 64
-rwxr-x---. 1 root  root    961 8月  25 17:16 fdfs_storaged
-rwxr-x---. 1 root  root    963 8月  25 17:16 fdfs_trackerd
-rw-r--r--. 1 root  root  18104 1月   3 2018 functions
-rwxr-xr-x. 1 mysql mysql 10576 10月  4 2018 mysqld
-rwxr-xr-x. 1 root  root   4334 1月   3 2018 netconsole
-rwxr-xr-x. 1 root  root   7293 1月   3 2018 network
-rw-r--r--. 1 root  root   1160 4月  11 2018 README
-rwxr-xr-x. 1 root  root   1702 9月   9 10:17 redis_6379
[root@yy init.d]# 

3、使用chkconfig --list命令查看,可以看到redis程序在2,3,4,5这四个等级下是开机自启动的。

[root@yy init.d]# chkconfig --list

注:该输出结果只显示 SysV 服务,并不包含
原生 systemd 服务。SysV 配置数据
可能被原生 systemd 配置覆盖。 

      要列出 systemd 服务,请执行 'systemctl list-unit-files'。
      查看在具体 target 启用的服务请执行
      'systemctl list-dependencies [target]'。

fdfs_storaged   0:关    1:关    2:开    3:开    4:开    5:开    6:关
fdfs_trackerd   0:关    1:关    2:开    3:开    4:开    5:开    6:关
mysqld          0:关    1:关    2:开    3:开    4:开    5:开    6:关
netconsole      0:关    1:关    2:关    3:关    4:关    5:关    6:关
network         0:关    1:关    2:开    3:开    4:开    5:开    6:关
redis_6379      0:关    1:关    2:开    3:开    4:开    5:开    6:关

4、重启虚拟机查看redis是否正常启动

Last login: Wed Sep  9 09:42:49 2020 from 192.168.0.106
[root@yy ~]# systemctl status redis_6379 -l
● redis_6379.service - LSB: start and stop redis_6379
   Loaded: loaded (/etc/rc.d/init.d/redis_6379; bad; vendor preset: disabled)
   Active: active (running) since 三 2020-09-09 10:24:44 CST; 42s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 896 ExecStart=/etc/rc.d/init.d/redis_6379 start (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/redis_6379.service
           └─921 /usr/local/bin/redis-server *:6379              

9月 09 10:24:44 yy systemd[1]: Starting LSB: start and stop redis_6379...
9月 09 10:24:44 yy redis_6379[896]: Starting Redis server...
9月 09 10:24:44 yy systemd[1]: Started LSB: start and stop redis_6379.
[root@yy ~]# 

5、使用redis-cli客户端连接

[root@yy ~]# redis-cli
127.0.0.1:6379> auth 123456
OK
127.0.0.1:6379> keys *
(empty list or set)
127.0.0.1:6379> quit

至此 redis 安装配置、开机自启就完成了


参考:Centos7下Redis设置开机自启动服务

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值