服务器部署日记 DAY2 Mysql&Redis
Redis
基本安装
// 下载
wget http://download.redis.io/releases/redis-4.0.12.tar.gz
// 解压
tar -zxvf redis-4.0.12.tar.gz -C /usr/local
// 重命名
cd /usr/local
mv redis-4.0.12/ reids/
配置
cd utils/
cp redis_init_script /etc/init.d/redis
vi /etc/init.d/redis
// 修改
// 端口
REDISPORT=6379
// 服务端
EXEC=/usr/local/redis/src/redis-server
// 客户端
CLIEXEC=/usr/local/redis/src/redis-cli
# pid 位置 默认即可
PIDFILE=/var/run/redis_${REDISPORT}.pid
# 配置文位置
CONF="/usr/local/redis/redis.conf"
启动
// 开机启动
chkconfig redis on
// 启动
service redis start
Mysql
前提环境
// 查看是否安装其他数据库
yum list installed | grep mysql
yum list installed | grep mariadb
// 当前环境华为服务器centos7
yum remove mariadb-libs.x86_64
创建配置文件(仅参考)
配置文件优先级
-
/etc/my.cnf
-
/etc/mysql/my.cnf
-
/usr/local/mysql/etc/my.cnf
-
~/.my.cnf
-
-defaults-file=#, 只读取指定的文件(不再读取其他配置文件)
-
-defaults-extra-file=#, 从其他优先级更高的配置文件中读取全局配置后,再读取指定的配置文件(有些选项可以覆盖掉全局配置从的设定值)
cd /etc
touch my.cnf
rm -rf my.cnf
vi my.cnf
// 文件内容
[client]
port=3306
socket=/usr/local/mysql/mysql.sock
[mysql]
socket=/usr/local/mysql/mysql.sock
[mysqld]
basedir=/usr/local/mysql/
datadir=/usr/local/mysql/data/
socket=/usr/local/mysql/mysql.sock
port=3306
character_set_server=utf8
lower_case_table_names = 1
max_connections = 4000
max_connect_errors = 1000
user=mysql
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
[mysqld_safe]
log-error=/usr/local/mysql/logs/error.log
pid-file=/usr/local/mysql/mysql.pid
log_bin=on
log_bin_basename=/usr/local/mysql/logs/mysql-bin
log_bin_index=/usr/local/mysql/logs/mysql-bin.index
server-id=123456
// 下载 mysql 5.7
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
// 解压
tar -zxvf mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz -C /usr/local
// 重命名文件
cd /usr/local
mv mysql-5.7.24-linux-glibc2.12-x86_64/ mysql/
// 创建配置相关文件根据需求
touch mysql.sock
touch mysql.pid
mkdir logs
touch logs/error.log
// 创建用户
groupadd -r mysql && useradd -r -g mysql -s /sbin/nologin -M mysql
// 初始化数据库 会有默认随机密码可以记住,我嫌麻烦没都是跳过密码登录
./bin/mysqld --initialize
// 修改权限
chown -R mysql:mysql /usr/local/mysql
./bin/mysqld_safe --skip-grant-tables &
// 打开mysql客户端
./bin/mysql -u root -p
// enter
// 修改密码
// alter user 'root'@'localhost' identified BY '${pwd}'; (跳过密码模式不能用)
update mysql.user set authentication_string=password('${pwd}') where user ='root' and Host = 'localhost';
// 刷新权限
// flush privileges;
exit
// 重启数据库
kill -9 ${pid1} && kill -9 ${pid2}
./usr/local/mysql/support-files/mysql.server start
创建远程用户
todo add users
配置远程连接
// 如果出现问题 ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
alter user 'root'@'localhost' identified BY '${pwd}';
grant all privileges on *.* to root@'%' identified by 'pwd';
flush privileges;
// create user '${user}'@'%' identified by '${pwd}';
防火墙设置
firewall-cmd --zone=public --add-port=3306/tcp --permanent && firewall-cmd --reload
service 命令配置 & 开机启动
// 复制启动文件 & 命名mysqld
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
// 授权
chmod +x /etc/init.d/mysqld
chkconfig --add mysqld
// chkconfig --level 345 mysqld on
chkconfig --list
// 结果
// mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
// 配置客户端 mysql 命令
vi /etc/profile
// 添加如下内容
# mysql
export MYSQL_HOME=/usr/local/mysql
export PATH=$PATH:$MYSQL_HOME/bin
// 刷新文件
source /etc/profile
// 如果遇到 vi ls等命令在刷新文件之后不能使用
// 1.检查profile 有问题修改后刷新
/bin/vim /etc/profile
// 2.重新连接ssh
网友评论