Redis,Mysql 安装记录


配置了无数次了,蠢死自己了,就是记不住,每次配置这些东西都要百度,干脆自己写一个文档记录,说写就写
1.服务器-阿里云
2.系统-centos7
3.Mysql安装及配置及简单使用
4.redis安装及配置及简单使用

Redis安装

redis 官网

#1.选择安装目录
cd /usr/local  或 cd /home
#2.下载redis
wget http://download.redis.io/releases/redis-5.0.5.tar.gz
#3.解压redis
tar xzf redis-5.0.5.tar.gz
#4.编译
cd redis-5.0.5
make
#5.开启redis服务
src/redis-server  官方启动方式

redis 启动是通过 redis-server 来启动的,存放在目录 redis-5.0.5/src 下的
如果通过 ./redis-server 需指定配置文件,redis是使用的是内部的conf文件,而不是安装目录下的,最好启动时指定配置文件。

启动:
cd /redis-5.05 或者 cd /redis-5.05/src
src/redis-server /usr/local/redis/redis-5.0.5/myredis.conf
1> src/redis-server 或者 src/redis-server /home/redis-5.0.5/redis.conf
2>./redis-server /home/redis-5.0.5/redis.conf
关闭:
1> redis-cli shutdown
2>有密码的: redis-cli -a [password] 回车后输入:shutdown
3>粗暴点的: ps -ef | grep redis 然后 kill -9

查看redis密码;可查看 redis 安装根目录下的配置文件:redis-conf 中SECURITY下面的 requirepass 后面的内容

Redis配置

1.配置文件详解:
参考原文地址:
https://blog.csdn.net/Super_RD/article/details/89498797
https://www.cnblogs.com/xuliangxing/p/7151685.html
如果不清楚 可以直接翻译 redis的配置文件的注释
redis 配置文件地址: redis-5.05/redis.conf
本文总结参考地址:redis配置详情

2.Redis 常见的性能调优
参考原文地址:
https://www.infoq.cn/article/tq-redis-memory-usage-optimization-storage/
直接上参数

################################GENERAL#####################################
#以后台daemon方式运行
daemonize yes   
#pid文件位置
pidfile /home/pid/redis_6379.pid 
#监听的端口号 建议修改 
port 6379 
#mim 
requirepass 123456
#所有ip都可访问
bind 0.0.0.0
#超市时间,120秒redis主动断开
timeout 120
#检测挂掉的对端。降低中间设备出问题而导致网络看似连接却已经与对端端口的问题。
tcp-keepalive 60
#log信息级别
loglevel debug
#log文件位置
logfile /home/log/redis_6379.log
#开启数据库的数量
databases 16
################################SNAPSHOTTING(rdb)################################
## 把数据库存到磁盘上:
# 会在指定秒数和数据变化次数之后把数据库写到磁盘上。
# 下面的例子将会进行把数据写入磁盘的操作:
# 900秒(15分钟)之后,且至少1次变更
# 300秒(5分钟)之后,且至少10次变更
# 60秒之后,且至少10000次变更
#
# 注意:你要想不写磁盘的话就把所有save设置注释掉就行了。
save 900 1
save 300 10
save 60 10000
rdbcompression yes  
dbfilename dump.rdb
dir /home/redis-5.0.5/var/
############################## APPEND ONLY MODE(aof) ###############################
# 默认情况下,Redis是异步的把数据导出到磁盘上。这种情况下,当Redis挂掉的时候,最新的数据就丢了。
# 如果不希望丢掉任何一条数据的话就该用纯累加模式:一旦开启这个模式,Redis会把每次写入的数据在接收后都写入 appendonly.aof 文件。
# 每次启动时Redis都会把这个文件的数据读入内存里。
appendonly no
# always:每次写操作都立刻写入到aof文件。慢,但是最安全。
appendfsync always
#如果AOF的同步策略设置成 "always" 或者 "everysec",那么后台的存储进程(后台存储或写入AOF日志)会产生很多磁盘I/O开销
no-appendfsync-on-rewrite no
################################ REDIS CLUSTER###############################
#集群开关,默认是不开启集群模式。
cluster-enabled no
#cluster-config-file nodes-6379.conf
#cluster-node-timeout 15000
#cluster-require-full-coverage yes

通过运行命令开启这个redis.conf

Redis简单使用

使用就不写了,还请各位小伙伴根据自身学习语言去使用,redis的五大数据类型操作
下面提供了几篇文件可以参考:
python
https://www.cnblogs.com/aadmina/p/9337021.html
https://www.cnblogs.com/aadmina/p/9340025.html
java
https://blog.csdn.net/qq_38872310/article/details/81474659
php
https://blog.csdn.net/u010505805/article/details/88217639

Mysql安装

推荐1:
centos7 yum安装
mysql常用指令:
开机自动启动:systemctl enable mysqld
开机不自动启动:systemctl disable mysqld
停止服务:service mysqld stop
查询状态:service mysqld status
启动服务:service mysqld start
重启服务:service mysqld restart

推荐2:

1.Mysql官网 选择
https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz在这里插入图片描述
在这里插入图片描述
2.下载mysql到服务器上

"""
1-未安装wget指令,需要先安装。
yum -y install wget 

2-使用wget下载
wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.18-linux-glibc2.12-x86_64.tar.xz
或者-下载好上传到服务器上 比如ftp

3-解压下载好的mysql.tar
tar xvf mysql-8.0.18-linux-glibc2.12-x86_64.tar.xz 
为啥xvf 自行查看 tar 解压命令含义, 修改文件名为mysql-8.0.18

4-编辑my.cnf 文件, 在etc/my.cnf
vim /etc/my.cnf 
注意:路径问题

5-添加系统mysql组和mysql用户:
groupadd mysql
useradd -g mysql mysql

6-修改mysql 目录权限
chmod -R 755 /usr/local/mysql

7-将mysql目录的所有者更换为mysql用户
chown -R mysql:mysql /usr/local/mysql

8-创建配置文件相关目录
mkdir -p {data,binlogs,log,etc,run}

9-修改配置目录的权限
chown -R mysql:mysql ./{data,binlogs,log,etc,run}

10-初始化数据库
/usr/local/mysql/mysql-8.0.18/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql/mysql-8.0.18 --datadir=/usr/local/mysql/data


报错了:
/usr/local/mysql/mysql-8.0.18-linux-glibc2.12-x86_64/bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
解决方案:
缺少安装包libaio和libaio-devel.
yum install -y libaio 命令

如果my.cnf 不争确,会在log中提示,根据报错内容逐一修改!然后删除所有文件,重写新建,执行8,9,10
mkdir -p {data,binlogs,log,etc,run}
chown -R mysql:mysql ./{data,binlogs,log,etc,run}
/usr/local/mysql/mysql-8.0.18/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql/mysql-8.0.18 --datadir=/usr/local/mysql/data

"""

在这里插入图片描述
成功的话会提示生成一个临时密码!记住这个临时密码!!
3.设置启动文件和环境变量

"""
1-把mysq.server 拷贝到目录 /etc/init.d/mysql并设置运行权限,这样就可以使用service mysql命令启动/停止服务
cp /usr/local/mysql/mysql-8.0.18/support-files/mysql.server  /etc/init.d/mysql

2-注册启动服务:
chkconfig --add mysql

3-查看是否添加成功
chkconfig --list
mysql           0:off   1:off   2:on    3:on    4:on    5:on    6:off

4-添加环境变量
vim /etc/profile
添加:export PATH=$PATH:/usr/local/mysql/mysql-8.0.18/bin
或者:echo "export PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
激活
source /etc/profile

5-启动
开机自动启动:systemctl enable mysql
开机不自动启动:systemctl disable mysql
停止服务:service mysql stop
查询状态:service mysql status
启动服务:service mysql start
重启服务:service mysql restart

mysql -uroot -p
输入日志里的密码
登陆成功
exit; 退出
代表成功了!!!!

"""

4.接下来就是修改密码

1.mysql 初始密码重置
先mysql -uroot -p 进去mysql
mysql> alter user 'root'@'localhost' identified by 'youpassword';

2.修改密码
1.1 用SET PASSWORD命令 
首先登录MySQL。 
格式:mysql> set password for 用户名@localhost = password('新密码'); 
例子:mysql> set password for root@localhost = password('GGJ.123456');

1.2:用mysqladmin 
格式:mysqladmin -u用户名 -p旧密码 password 新密码 
例子:mysqladmin -uroot -p123456 password 123 

1.3:用UPDATE直接编辑user表 
首先登录MySQL。 
mysql> use mysql;
mysql> update user set password=password('GGJ.123456') where user='root' and host='localhost'; 
mysql> flush privileges; 
update user set password=password(GGJ12345) where user=root;

1.4 8.0修改密码
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';

再此一上我修改的时候均不行,出错:ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'use set password=password('123456') where use='root'' at line 1
暂未找到原因:
1、解决方式:
SET PASSWORD = '123456'
2、解决方式:
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';

我更悲催,使用了第一种方法,重置的密码也丢了。
解决方式:
1.修改my.cnf 在 [mysqld] 添加 skip-grant-tables  取消密码验证登陆
2.ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
3.第二步报错的话执行:flush privileges;  再次执行2就好了。
4.修改my.cnf 加上密码验证

5.拓展,mysql允许外网访问

1.登陆mysql
mysql> use mysql;
2.查询host
mysql> select host,user from user;
3.更新域属性,'%'表示允许外部访问:
mysql> update user set host='%' where user ='root';
4.更新
mysql> FLUSH PRIVILEGES;
5.再执行授权语句:
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'WITH GRANT OPTION;

6.navicat 如果出现错误:
ERROR 2059 (HY000): Authentication plugin 'caching_sha2_password' cannot be loaded
请进入mysql重置密码

Mysql 配置

my.cnf
```clike
[client]
port = 3306
socket = /usr/local/mysql/run/mysql.sock
 
[mysqld]
port = 3306
basedir	= /usr/local/mysql/mysql-8.0.18
socket = /usr/local/mysql/run/mysql.sock
pid_file = /usr/local/mysql/run/mysql.pid
datadir = /usr/local/mysql/data
default_storage_engine = InnoDB
max_allowed_packet = 512M
max_connections = 2048
open_files_limit = 65535
 
skip-name-resolve
lower_case_table_names=1
 
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
init_connect='SET NAMES utf8mb4'
 
 
innodb_buffer_pool_size = 1024M
innodb_log_file_size = 2048M
innodb_file_per_table = 1
innodb_flush_log_at_trx_commit = 0
 
 
key_buffer_size = 64M
 
log-error = /usr/local/mysql/log/mysql_error.log
log-bin = /usr/local/mysql/binlogs/mysql-bin
slow_query_log = 1
slow_query_log_file = /usr/local/mysql/log/mysql_slow_query.log
long_query_time = 5
 
 
tmp_table_size = 32M
max_heap_table_size = 32M
#query_cache_type = 0
#query_cache_size = 0
 
server-id=1
# 根据您的服务器IOPS能力适当调整
# 一般配普通SSD盘的话,可以调整到 10000 - 20000
# 配置高端PCIe SSD卡的话,则可以调整的更高,比如 50000 - 80000
innodb_io_capacity = 50000
innodb_io_capacity_max = 80000
innodb_flush_sync = 0
innodb_flush_neighbors = 0
innodb_write_io_threads = 8
innodb_read_io_threads = 8
innodb_purge_threads = 4
innodb_page_cleaners = 4
innodb_open_files = 65535
innodb_max_dirty_pages_pct = 50
innodb_flush_method = O_DIRECT
innodb_lru_scan_depth = 4000
innodb_checksum_algorithm = crc32
innodb_lock_wait_timeout = 10
innodb_rollback_on_timeout = 1
innodb_print_all_deadlocks = 1
innodb_file_per_table = 1
innodb_online_alter_log_max_size = 4G
innodb_stats_on_metadata = 0


#innodb monitor
innodb_monitor_enable="module_innodb"
innodb_monitor_enable="module_server"
innodb_monitor_enable="module_dml"
innodb_monitor_enable="module_ddl"
innodb_monitor_enable="module_trx"
innodb_monitor_enable="module_os"
innodb_monitor_enable="module_purge"
innodb_monitor_enable="module_log"
innodb_monitor_enable="module_lock"
innodb_monitor_enable="module_buffer"
innodb_monitor_enable="module_index"
innodb_monitor_enable="module_ibuf_system"
innodb_monitor_enable="module_buffer_page"
innodb_monitor_enable="module_adaptive_hash"

transaction_isolation = REPEATABLE-READ
#innodb_additional_mem_pool_size = 16M
innodb_buffer_pool_size = 45875M
innodb_buffer_pool_instances = 4
innodb_buffer_pool_load_at_startup = 1
innodb_buffer_pool_dump_at_shutdown = 1
innodb_data_file_path = ibdata1:1G:autoextend
innodb_flush_log_at_trx_commit = 1
innodb_log_buffer_size = 32M
innodb_log_file_size = 2G
innodb_log_files_in_group = 2
innodb_max_undo_log_size = 4G
innodb_undo_directory = /usr/local/mysql/log/undolog
innodb_undo_tablespaces = 95
#
## my.cnf for MySQL 5.7/8.0

[client]
port	= 3306
socket	= /usr/local/mysql/run/mysql.sock

[mysql]
prompt="\u@ \R:\m:\s [\d]> "
no-auto-rehash

[mysqld]
user	= mysql
port	= 3306
default_storage_engine = InnoDB
basedir	= /usr/local/mysql/mysql-8.0.18
pid_file = /usr/local/mysql/run/mysql.pid
datadir	= /usr/local/mysql/data
socket	= /usr/local/mysql/run/mysql.sock
slow_query_log_file = /usr/local/mysql/data/slow.log
log-error = /usr/local/mysql/log/mysql_error.log
log-bin = /usr/local/mysql/data/mybinlog
innodb_undo_directory = /usr/local/mysql/data/undolog

character-set-server = utf8mb4
skip_name_resolve = 1

#若你的MySQL数据库主要运行在境外,请务必根据实际情况调整本参数
#default_time_zone = "+8:00"

open_files_limit    = 65535
back_log = 1024
max_connections = 1024
max_connect_errors = 1000000
table_open_cache = 1024
table_definition_cache = 1024
table_open_cache_instances = 64
thread_stack = 512K
external-locking = FALSE
max_allowed_packet = 32M
sort_buffer_size = 4M
join_buffer_size = 4M
thread_cache_size = 1536
interactive_timeout = 600
wait_timeout = 600
tmp_table_size = 32M
max_heap_table_size = 32M
slow_query_log = 1
log_timestamps = SYSTEM

long_query_time = 0.1
log_queries_not_using_indexes =1
log_throttle_queries_not_using_indexes = 60
min_examined_row_limit = 100
log_slow_admin_statements = 1
log_slow_slave_statements = 1
server-id = 3306
sync_binlog = 1
binlog_cache_size = 4M
max_binlog_cache_size = 2G
max_binlog_size = 1G

#注意:MySQL 8.0开始,binlog_expire_logs_seconds选项也存在的话,会忽略expire_logs_days选项
expire_logs_days = 7
# 精确到秒
binlog_expire_logs_seconds = 604800

master_info_repository = TABLE
relay_log_info_repository = TABLE
gtid_mode = on
enforce_gtid_consistency = 1
log_slave_updates
slave-rows-search-algorithms = 'INDEX_SCAN,HASH_SCAN'
binlog_format = row
binlog_checksum = 1
relay_log_recovery = 1
relay-log-purge = 1
key_buffer_size = 32M
read_buffer_size = 8M
read_rnd_buffer_size = 4M
bulk_insert_buffer_size = 64M
myisam_sort_buffer_size = 128M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1
lock_wait_timeout = 3600
explicit_defaults_for_timestamp = 1
innodb_thread_concurrency = 0
innodb_sync_spin_loops = 100
innodb_spin_wait_delay = 30

transaction_isolation = REPEATABLE-READ
#innodb_additional_mem_pool_size = 16M
innodb_buffer_pool_size = 43008M
innodb_buffer_pool_instances = 4
innodb_buffer_pool_load_at_startup = 1
innodb_buffer_pool_dump_at_shutdown = 1
innodb_data_file_path = ibdata1:1G:autoextend
innodb_flush_log_at_trx_commit = 1
innodb_log_buffer_size = 32M
innodb_log_file_size = 2G
innodb_log_files_in_group = 2
innodb_max_undo_log_size = 4G
innodb_undo_tablespaces = 95

# 根据您的服务器IOPS能力适当调整
# 一般配普通SSD盘的话,可以调整到 10000 - 20000
# 配置高端PCIe SSD卡的话,则可以调整的更高,比如 50000 - 80000
innodb_io_capacity = 50000
innodb_io_capacity_max = 80000
innodb_flush_sync = 0
innodb_flush_neighbors = 0
innodb_write_io_threads = 8
innodb_read_io_threads = 8
innodb_purge_threads = 4
innodb_page_cleaners = 4
innodb_open_files = 65535
innodb_max_dirty_pages_pct = 50
#innodb_flush_method = O_DIRECT
innodb_lru_scan_depth = 4000
innodb_checksum_algorithm = crc32
innodb_lock_wait_timeout = 10
innodb_rollback_on_timeout = 1
innodb_print_all_deadlocks = 1
innodb_file_per_table = 1
innodb_online_alter_log_max_size = 4G
innodb_stats_on_metadata = 0

#注意:MySQL 8.0.16开始删除该选项
#internal_tmp_disk_storage_engine = InnoDB

# some var for MySQL 8
log_error_verbosity = 3
innodb_print_ddl_logs = 1
#innodb_dedicated_server = 0

innodb_status_file = 1
#注意: 开启 innodb_status_output & innodb_status_output_locks 后, 可能会导致log-error文件增长较快
innodb_status_output = 0
innodb_status_output_locks = 0

#performance_schema
performance_schema = 1
performance_schema_instrument = '%memory%=on'
performance_schema_instrument = '%lock%=on'

#innodb monitor
innodb_monitor_enable="module_innodb"
innodb_monitor_enable="module_server"
innodb_monitor_enable="module_dml"
innodb_monitor_enable="module_ddl"
innodb_monitor_enable="module_trx"
innodb_monitor_enable="module_os"
innodb_monitor_enable="module_purge"
innodb_monitor_enable="module_log"
innodb_monitor_enable="module_lock"
innodb_monitor_enable="module_buffer"
innodb_monitor_enable="module_index"
innodb_monitor_enable="module_ibuf_system"
innodb_monitor_enable="module_buffer_page"
innodb_monitor_enable="module_adaptive_hash"

[mysqldump]
quick
max_allowed_packet = 32M

参数参考:
Mysql参数说明
my.cnf生成工具

Mysql 简单使用

总结

Mysql 安装建议使用 yum 安装或者源安装,简单又方便,不推荐压缩包,问题多的一批~

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值