Centos7安装MySQL5.7和Redis6.0流水账

安装mysql

使用rpm包安装

yum remove mariadb-libs.x86_64
yum install perl
rpm -ivh mysql-community-common-5.7.31-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.31-1.el7.x86_64.rpm 
rpm -ivh mysql-community-client-5.7.31-1.el7.x86_64.rpm 
rpm -ivh mysql-community-server-5.7.31-1.el7.x86_64.rpm 
systemctl is-enabled mysqld
systemctl start mysqld
systemctl status mysqld
# 查看密码
vi /var/log/mysqld.log

配置mysql

mysql> set password=password('Test.123');
mysql> create user 'testuser'@'%' identified by 'testuser.123';
mysql> create database testdb default character set utf8 collate utf8_general_ci;
mysql> grant all on testdb.* to 'testuser'@'%';

配置文件/etc/my.cnf

datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

join_buffer_size = 128M
sort_buffer_size = 8M
read_rnd_buffer_size = 8M
key_buffer_size=32M
max_allowed_packet=16M
read_buffer_size = 4M
tmp_table_size = 128M
max_connections = 256
max_heap_table_size = 256M

防火墙

firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --zone=public --add-port=6379/tcp --permanent
firewall-cmd --reload

编译安装Redis

yum install gcc-c++
yum install centos-release-scl
yum install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils
scl enable devtoolset-9 bash

tar zxvf redis-6.0.10.tar.gz 
cd redis-6.0.10
make
yum install tcl
make test
make PREFIX=/opt/redis/redis-6.0.10 install

配置

cp ~/backup/redis-6.0.10/redis.conf ./redis_6379.conf
vi redis_6379.conf
# 修改
bind 0.0.0.0
port 6379
daemonize yes
logfile "/data/redis/logs/redis_6379.log"
dir /data/redis/db/
requirepass foobared
maxmemory 1073741824
# 结束

优化项 transparent_hugepage

cd /etc/rc.d/
chmod +x rc.local 
vi /etc/rc.d/rc.local 
# 结尾增加
if test -f /sys/kernel/mm/transparent_hugepage/enabled; then
  echo madvise > /sys/kernel/mm/transparent_hugepage/enabled
fi
# 结束

优化项 open files

vi /etc/security/limits.d/20-nproc.conf 
# 修改为
*          soft    nofile    10240
*          hard    nofile    10240
*          soft    nproc     10240
*          hard    nproc     10240
root       soft    nproc     unlimited
#

优化项 net.core.somaxconn, vm.overcommit_memory

vi /etc/sysctl.conf 
# 末尾增加
net.core.somaxconn = 1024
vm.overcommit_memory = 1
# 结束
sysctl -p

添加到服务

vi /usr/lib/systemd/system/redis.service
# 内容
[Unit]
Description=Redis
After=network.target
 
[Service]
Type=forking
PIDFile=/var/run/redis_6379.pid
ExecStart=/opt/redis/latest/bin/redis-server /opt/redis/latest/conf/redis_6379.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/opt/redis/latest/bin/redis-cli -p 6379 shutdown
PrivateTmp=true
 
[Install]
WantedBy=multi-user.target
# 内容结束
systemctl enable redis

posted on 2021-01-17 23:15  Milton  阅读(119)  评论(0编辑  收藏  举报

导航