开源办公开发平台丨Mysql5.7两套四节点主从结构环境搭建教程(一)

O2OA企业信息化平台 2021-02-23 16:40:50
办公 开发 开源 平台 公开


一、Mysql5.7.29服务器下载

服务器下载链接:https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.29-linux-glibc2.12-x86_64.tar.gz

 

二、单实例服务器安装过程

2.1、创建安装包存放目录:

mkdir -p /server/tools

2.2、创建应用软件解压安装目录:

mkdir -p /application

2.3、在安装包存放目录中解压服务器程序:

tar -xf mysql-5.7.29-linux-glibc2.12-x86_64.tar.gz

2.4、将解压的服务器目录移动到安装目录:

mv mysql-5.7.29-linux-glibc2.12-x86_64 /application/mysql

服务器目录规划:

image.png

 

2.5、创建数据库数据存放目录:

mkdir -p /data/mysql/data

2.6、创建mysql启动用户:

useradd -s /sbin/nologin mysql

2.7、修改环境变量,将mysqld命令添加到环境变量:

vim /etc/profile
export PATH=/application/mysql/bin:$PATH

image.png

source /etc/profile

 

2.8、查询Mysql服务器版本

mysql -V

 

2.9、报错解决:

mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory

解决方法:yum install libncurses*

image.png

 

2.11 目录授权:

chown -R mysql.mysql /application/*

chown -R mysql.mysql /data

 

三、初始化数据(创建系统数据)

3.1 初始化命令

5.6版本  初始化命令:

/application/mysql/scripts/mysql_install_db

5.7版本  初始化命令:

mkdir -p /data/mysql/data

chown -R mysql.mysql /data

mysqld --initialize --user=mysql --basedir=/application/mysql --datadir=/data/mysql/data

说明:

--initialize 参数:

1、对于密码复杂度进行定制:12位,4种

2、密码过期时间:180

3、给root@localhost用户设置临时密码

image.png

如果需要初始化时不生成初始密码,那么可以使用--initialize-insecure进行数据初始化

先删除原来生成的数据,如果未生成可以跳过此步骤:

\rm -rf /data/mysql/data/*

mysqld --initialize-insecure --user=mysql --basedir=/application/mysql --datadir=/data/mysql/data

 

四、数据库配置及启动

4.1 添加配置文件:

cat >/etc/my.cnf <<EOF

[mysqld]

user=mysql

basedir=/application/mysql

datadir=/data/mysql/data

socket=/tmp/mysql.sock

server_id=21

port=3306

[mysql]

socket=/tmp/mysql.sock

EOF

 

4.2 启动数据库

1. sys-v  

1) 使用mysqld命令直接启动

cp /application/mysql/support-files/mysql.server /etc/init.d/mysqld

service mysqld restart

image.png

启动成功!

 

2) /etc/init.d/mysqld restart 或者 /etc/init.d/mysqld --defaults-file=/etc/my.cnf restart

image.png

4.2.2 使用systemctl启动数据库

1、创建服务mysqld3306.service

cat >/etc/systemd/system/mysqld3306.service<<EOF

[Unit]

Description=MySQL Server

Documentation=man:mysqld(8)

Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html

After=network.target

After=syslog.target

 

[Install]

WantedBy=multi-user.target

 

[Service]

User=mysql

Group=mysql

 

ExecStart=/application/mysql/bin/mysqld --defaults-file=/etc/my.cnf

LimitNOFILE = 5000

EOF

 

检查SELINUX配置:

永久关掉需要修改 /etc/selinux/config 再重启机器就好

SELINUX=disabled

 

2、启动数据库

systemctl start mysqld3306

 

 

4.3 启动情况及端口查询

netstat -lnp|grep 3306

image.png

 

 

五、管理员密码的设定(root@localhost)

mysqladmin -uroot -p password zone2018

image.png

 

 

出现问题后,查询问题的方法:

1、错误日志:/data/3307/mysql.log

2、systemctl status mysqld3307.service

3、journalctl -xe

image.png

解决办法:永久关掉需要修改 /etc/selinux/config 再重启机器就好

SELINUX=disabled

(转自公众号:浙江兰德网络)

版权声明
本文为[O2OA企业信息化平台]所创,转载请带上原文链接,感谢
https://my.oschina.net/o2oa/blog/4960820

  1. J2EE
  2. Vue uses SDK to upload seven cows
  3. k8s-dns
  4. JavaScript mailbox verification - regular verification
  5. k8s-dashboard
  6. How many questions can you answer?
  7. Spring annotation -- transactional
  8. [k8s cluster] construction steps
  9. k8s-kubeadm
  10. k8s-etcd
  11. Using HashMap to improve search performance in Java
  12. There is no class problem when Maven publishes jar package
  13. JavaScriptBOM操作
  14. J2EE
  15. k8s-prometheus-memory
  16. k8s-prometheus disk
  17. k8s-prometheus
  18. JavaScript BOM operation
  19. k8s-prometheus-memory
  20. k8s-prometheus disk
  21. k8s-prometheus
  22. Linux Disk Command
  23. Linux FS
  24. 使用docker-compose &WordPress建站
  25. Linux Command
  26. This time, thoroughly grasp the depth of JavaScript copy
  27. Linux Disk Command
  28. Linux FS
  29. Using docker compose & WordPress to build a website
  30. Linux Command
  31. 摊牌了,我 HTTP 功底贼好!
  32. shiro 报 Submitted credentials for token
  33. It's a showdown. I'm good at it!
  34. Shiro submitted credentials for token
  35. Linux Stress test
  36. Linux Root Disk Extension
  37. Linux Stress test
  38. Linux Root Disk Extension
  39. Redis高级客户端Lettuce详解
  40. springboot学习-综合运用(一)
  41. 忘记云服务器上MySQL数据库的root密码时如何重置密码?
  42. Detailed explanation of lettuce, an advanced client of redis
  43. Springboot learning integrated application (1)
  44. Linux File Recover
  45. Linux-Security
  46. How to reset the password when you forget the root password of MySQL database on the cloud server?
  47. Linux File Recover
  48. Linux-Security
  49. LiteOS:盘点那些重要的数据结构
  50. Linux Memory
  51. Liteos: inventory those important data structures
  52. Linux Memory
  53. 手把手教你使用IDEA2020创建SpringBoot项目
  54. Hand in hand to teach you how to create a springboot project with idea2020
  55. spring boot 整合swagger2生成API文档
  56. Spring boot integrates swagger2 to generate API documents
  57. linux操作系统重启后 解决nginx的pid消失问题
  58. Solve the problem of nginx PID disappearing after Linux operating system restart
  59. JAVA版本号含义
  60. The meaning of java version number