一、简介
- 本次安装持续更新,如果发现文章安装流程出现错误。可以留言评论指正,大家一起完善。如果有其他的需要安装的应用,可以留言,我争取加入进来。
- 此次安装全部为二进制安装,后续会出一个docker版本,系统为CentOs7,我会将所有的安装包放到网盘中。
复制代码 二、服务器配置修改
1 防火墙相关配置
- systemctl status firewalld
- systemctl enable firewalld
- systemctl start firewalld
- firewall-cmd --reload
- firewall-cmd --list-all
复制代码- # 开启端口
- firewall-cmd --zone=public --add-port=6030-6060/tcp --permanent
- firewall-cmd --zone=public --add-port=3306/tcp --permanent
- # 临时开启协议规则
- firewall-cmd --permanent --add-port=3306/tcp
- firewall-cmd --permanent --add-port=9200/tcp
- # 删除规则
- firewall-cmd --permanent --remove-port=3306/tcp
- firewall-cmd --permanent --remove-port=9200/tcp
复制代码 2 配置本地yum源(内网环境必要配置)
2.1 下载地址
清华大学网站
下载本身服务器类型的ios镜像(下载链接中含Everything)的比如 CentOS-7-x86_64-Everything-2009.iso;
2.2 上传安装
- 1.系统内执行命令,查看文件系统的磁盘空间占用情况,确认镜像的上传位置(df -h)
- 2.比如:我放到/root下
- 3.创建新的目录:/root/localyum
- 4.通过命令将yum挂载到/root/localyum下
- mount -o loop /root/CentOS-7-x86_64-Everything-2009.iso /root/localyum
- mount -a
- 5. df -h查看是否成功
复制代码
2.3 配置本地yum
- vi /etc/yum.repos.d/Centos-7.repo
- [base]
- name= yum repo
- baseurl=file:///root/localyum
- enabled=1
- gpgcheck=0
复制代码- 执行
- 执行以下命令,清除原始yum缓存; yum clean all
- 执行以下命令,查看目前拥有的yum源仓库; yum repolist all
- 执行以下命令,刷新缓存; yum makecache
- 执行以下命令,显示所有可以安装的程序包,当可用软件包的来源名称是我们配置的yum源名称时,表示yum配置成功;
- yum list available |more
复制代码 3 安装须要环境(确保本地yum安装完毕大概服务器能上网)
3.1 安装gcc
- yum install -y gcc git wget vim ntp lsof
- yum install -y pcre pcre-devel zlib zlib-devel openssl openssl-devel
复制代码 3.2 修改系统配置文件
- vim /etc/security/limits.conf
复制代码 添加以下内容
- * hard nofile 131072
- * soft nproc 2048
- * hard nproc 4096
复制代码 继承修改另一个配置文件
添加以下内容
- vm.swappiness=1
- vm.max_map_count=655360
复制代码 修改时区(时区有问题时利用)
- rm -f /etc/localtime
- ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
复制代码 刷新配置文件
selinux设置必要重启服务器
- vi /etc/sysconfig/selinux
复制代码
4 NTP 同步时间安装
4.1 安装命令
4.2 修改配置文件
- server ntp.aliyun.com iburst
复制代码 假如服务器是内部服务器将三台的的时间都指向一个服务器就行(三台都写一个)
- server 192.168.200.161 iburst
复制代码 4.3 启动服务
启动
开机自启
三、Linux二进制安装JDK1.8
1 下载JDK
百度网盘分享(软件扩展->Linux安装包中)百度网盘分享
官网下载 JDK官网下载地址
选择必要的版本下载就行;
2 安装JDK
将文件压缩包传上传到服务器/home目录下
解压压缩文件
- cd /usr/local/
- mkdir java
- tar -zxvf /home/jdk-8u371-linux-x64.tar.gz -C /usr/local/java/
复制代码 查看是否成功
3 配置环境变量
编辑/etc/profile文件
按i进入编辑,在profile文件尾部添加如下内容(JAVA_HOME的值是jdk安装目录)
- export JAVA_HOME=/usr/local/java/jdk1.8.0_371
- export JRE_HOME=${JAVA_HOME}/jre
- export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib:$CLASSPATH
- export JAVA_PATH=${JAVA_HOME}/bin:${JRE_HOME}/bin
- export PATH=$PATH:${JAVA_PATH}
复制代码 按Esc退出编辑状态,然后输入:wq生存并退出
通过命令source /etc/profile
让profile文件立刻生效
测试是否安装成功
四、Linux二进制安装TDengine集群
文章参考:集群部署和管理
规划物理节点:
IP地址hostname192.168.200.161node161192.168.200.162node162192.168.200.163node163 1 修改服务器hostname
到3台服务器中修改对应的hostname,并重启服务器
2 修改/etc/hosts
对应服务器修改/etc/hosts,在最后添加对应的服务器的节点ip、hostname
- vi /etc/hosts
- # 添加对应的节点
- 192.168.200.161 node161
- 192.168.200.162 node162
- 192.168.200.163 node163
复制代码 设置完成后,查抄服务器之间是否能ping通,ping通则说明配置成功
3 开放端口
发起不要直接关闭防火墙
- # 添加一个TCP端口范围(6030至6060)
- firewall-cmd --zone=public --add-port=6030-6060/tcp --permanent
- # 重启防火墙
- firewall-cmd --reload
- # 检查端口是否开放
- firewall-cmd --list-all
复制代码 4 服务器时钟同步 NTP
详情看 NTP 同步时间安装
5 官网下载对应必要的安装server文件
官方网站下载:官网下载地址
百度网盘下载:网盘链接
6 安装TDengine
6.1 上传解压
将文件上传到/opt下
解压下载的文件包
- tar -zxvf /opt/TDengine-server-3.2.2.0-Linux-x64.tar.gz
复制代码 进入文件夹
- cd /opt/TDengine-server-3.2.2.0
复制代码 6.2 开始安装
看好这个步骤很紧张:
6.2.1 实行./install.sh
后,会出现本身本机的hostname,点击回车键进入下一步
6.2.2 回车后会出现此选项,相当于设置集群的主节点。firstEp 是每个数据节点首次启动后毗连的第一个数据节点
6.2.3 设置后点击回车(必须设置)
6.2.4 此步直接回车
6.2.5 安装成功后,进入配置文件查看
7 启动TDengine
启动服务进程
竣事服务进程
重启服务进程
查看服务状态
开机自启
移除开机自启
8 启动taosAdapter
紧张是利用REST毗连时利用
启动服务进程
- systemctl start taosadapter
复制代码 竣事服务进程
- systemctl stop taosadapter
复制代码 重启服务进程
- systemctl restart taosadapter
复制代码 查看服务状态
- systemctl status taosadapter
复制代码 开机自启
- systemctl enable taosadapter
复制代码 移除开机自启
- systemctl disable taosadapter
复制代码 9 添加数据节点
在服务器任意节点(一般实行主节点)实行 taos(没有修改过密码直接实行,默认密码 taosdata)
实行 show dnodes可以看到只有一个节点
加入其他节点后再次实行 show dnodes;在其他节点上实行可以看到全部都是一样的。
- create dnode 'node162:6030';
复制代码- create dnode 'node163:6030';
复制代码
10 安装TDengine客户端(windows)
官方下载:官方链接
百度网盘:网盘链接
实行安装程序,按提示选择默认值,完成安装
10.1 修改windows的配置
修改 C:\Windows\System32\drivers\etc\hosts,在文件最后添加服务器的ip以及hostname
- 192.168.200.161 node161
- 192.168.200.162 node162
- 192.168.200.163 node163
复制代码 10.2 修改TDengine客户端的配置
修改 C:\TDengine\cfg\taos.cfg
10.3 毗连
实行 C:\TDengine 的 taos.exe 大概桌面上的快捷键(假如你修改了密码,那么taos.exe 就会点不开,必要进入cmd实行大概通过桌面快捷方式实行)
进入C:\TDengine 实行 taos (没有修改密码就只必要taos)
10.4 利用示例
- # 查看所有用户
- taos> show users;
- name | privilege | create_time | account |
- ============================================================================================
- _root | writable | 2022-04-06 15:12:53.714 | root |
- monitor | writable | 2022-04-06 15:12:53.714 | root |
- root | super | 2022-04-06 15:12:53.714 | root |
-
- # 修改当前root用户密码为123456
- taos> alter user root pass '123456';
- Query OK, 0 of 0 row(s) in database (0.067138s)
- # 创建用户test密码为123456
- taos> create user test pass '123456';
- Query OK, 0 of 0 row(s) in database (0.072157s)
- # 删除test用户
- taos> drop user wanwu;
- Query OK, 0 of 0 row(s) in database (0.075751s)
复制代码 11 安装DBeaver客户端(windows)
也可以通过DBeaver毗连: DBeaver毗连方式
12 JAVA 毗连TDengine报错整理
TDengine ERROR (0x80000020): some vnode/qnode/mnode(s) out of service
- 本机或者服务器的host文件没有修改、查看本机是否开启了vpn
- 使用REST 方式进行连接时,记得端口由6030改为6041,需要开启taosadapter
复制代码 13 在其他服务器毗连步骤
在其他服务器上启动带有TDengine的jar包是失败的,因为jia包所在的服务必要安装客户端举行毗连
安装包利用只管利用同等的。我的网盘中都有 网盘下载
毗连方式很简单,就是在必要毗连的服务器 /etc/hosts上先配置TDengine集群的IP映射;然后根据步骤举行安装就行。安装链接
五、Linux二进制安装MariaDB
1 卸载mariadb
1.1 卸载相关的服务(mysql
和mariadb都查询一下)
查抄MySQL mariadb
- rpm -qa|grep mysql
- rpm -qa|grep mariadb
复制代码 假如存在,删除服务
- rpm -ev mariadb-libs-5.5.68-1.el7.x86_64 --nodeps
复制代码
1.2 查找MySQL和mariadb相关的文件目录
- find / -name mysql
- find / -name mariadb
复制代码
删除目录(因为我docker里也安装了mysql
,以是根据本身情况删除 )
- rm -rf /usr/lib64/mysql
- rm -rf /usr/local/mysql
- rm -rf /usr/local/mysql
- /bin/mysql
- rm -rf /usr/local/mysql
- /include/mysql
- rm -rf /home/kibana-7.9.3-linux-x86_64/node_modules/monaco-editor/dev/vs/basic-languages/mysql
- rm -rf /home/kibana-7.9.3-linux-x86_64/node_modules/monaco-editor/esm/vs/basic-languages/mysql
- rm -rf /home/kibana-7.9.3-linux-x86_64/node_modules/monaco-editor/min/vs/basic-languages/mysql
- rm -rf /data/mysql
- rm -rf /data/mysql
- /mysql
复制代码
2 安装mariadb
2.1 mariadb下载地址
下载地址: https://mariadb.org/download
百度网盘下载链接:百度网盘
2.2 将安装包放入到服务器中并解压 (我放到opt下)
- #解压命令
- tar -zxvf mariadb-10.2.43-linux-systemd-x86_64.tar.gz
复制代码
2.3 将解压后的目录移动到安装目录下
- mv /opt/mariadb-10.2.43-linux-systemd-x86_64 /usr/local/mariadb
复制代码
2.4 创建数据目录(根据本身情况修改)
我的数据位置在/usr/local/data/mariadb
- cd /usr/local
- mkdir data
- cd data
- mkdir mariadb
复制代码 2.5 添加用户组和用户及其权限
- #1.创建组
- groupadd mariadb
- #2.创建用户,赋予权限(注意目录)
- useradd -g mariadb mariadb
- #3.给mysql
- 用户赋予权限(第二步可能会报错,不用管,直接第三步,原因还未找到.解决可以评论和私信我)
- chown -R mariadb.mariadb /usr/local/data/mariadb /usr/local/mariadb
复制代码 2.5.1 组和用户的操作命令
- 一,组操作
- #1,创建组 增加一个test组
- groupadd test
- #2,修改组 将test组的名子改成test2
- groupmod -n test2 test
- #3,删除组 删除 组test2
- groupdel test2
- #4,查看组
- a),查看当前登录用户所在的组 groups,查看apacheuser所在组groups apacheuser
- b),查看所有组 cat /etc/group
- c),有的linux系统没有/etc/group文件的,这个时候看下面的这个方法
- cat /etc/passwd |awk -F [:] '{print $4}' |sort|uniq | getent group |awk -F [:] '{print $1}'
- 这里用到一个命令是getent,可以通过组ID来查找组信息,如果这个命令没有的话,那就很难查找,系统中所有的组了.
- 二,用户操作
- #1,增加用户
- 查看复制打印?
- [root@krlcgcms01 mytest]# useradd --help
- Usage: useradd [options] LOGIN
-
- Options:
- -b, --base-dir BASE_DIR 设置基本路径作为用户的登录目录
- -c, --comment COMMENT 对用户的注释
- -d, --home-dir HOME_DIR 设置用户的登录目录
- -D, --defaults 改变设置
- -e, --expiredate EXPIRE_DATE 设置用户的有效期
- -f, --inactive INACTIVE 用户过期后,让密码无效
- -g, --gid GROUP 使用户只属于某个组
- -G, --groups GROUPS 使用户加入某个组
- -h, --help 帮助
- -k, --skel SKEL_DIR 指定其他的skel目录
- -K, --key KEY=VALUE 覆盖 /etc/login.defs 配置文件
- -m, --create-home 自动创建登录目录
- -l, 不把用户加入到lastlog文件中
- -M, 不自动创建登录目录
- -r, 建立系统账号
- -o, --non-unique 允许用户拥有相同的UID
- -p, --password PASSWORD 为新用户使用加密密码
- -s, --shell SHELL 登录时候的shell
- -u, --uid UID 为新用户指定一个UID
- -Z, --selinux-user SEUSER use a specific SEUSER for the SELinux user mapping
- useradd test
- passwd test
- 增加用户test,有一点要注意的,useradd增加一个用户后,不要忘了给他设置密码,不然不能登录的。
- #2,修改用户
- usermod -d /home/test -G test2 test
- 将test用户的登录目录改成/home/test,并加入test2组,注意这里是大G。
- gpasswd -a test test2 将用户test加入到test2组
- gpasswd -d test test2 将用户test从test2组中移出
- #3,删除用户
- userdel test
- 将test用户删除
- #4,查看用户
- a),查看当前登录用户
- [root@krlcgcms01 ~]# w
- [root@krlcgcms01 ~]# who
- b),查看自己的用户名
- [root@krlcgcms01 ~]# whoami
- c),查看单个用户信息
- [root@krlcgcms01 ~]# finger apacheuser
- [root@krlcgcms01 ~]# id apacheuser
- d),查看用户登录记录
- [root@krlcgcms01 ~]# last 查看登录成功的用户记录
- [root@krlcgcms01 ~]# lastb 查看登录不成功的用户记录
- e),查看所有用户
- [root@krlcgcms01 ~]# cut -d : -f 1 /etc/passwd
- [root@krlcgcms01 ~]# cat /etc/passwd |awk -F \: '{print $1}'
复制代码 2.6 安装mariadb
- cd /usr/local/mariadb/
- ./scripts/mysql
- _install_db --basedir=/usr/local/mariadb --datadir=/usr/local/data/mariadb --skip-name-resolve --user=mariadb
复制代码 安装成功
查看数据目录
2.7 创建配置文件 /etc/my.cnf
- cd /etc/
- #展示my.cnf文件,没有不展示
- ls -ltr my.cnf
- #有的话,备份删除
- mv my.cnf my.cnf.backup
- #创建新的文件
- vi my.cnf
复制代码 my.cnf详细配置(网上有很多,找一个就行,但是注意目录的修改)
2.8 新增mariadb.service配置文件
- cd /usr/lib/systemd/system
- vi mariadb.service
复制代码- # It's not recommended to modify this file in-place, because it will be
- # overwritten during package upgrades. If you want to customize, the
- # best way is to create a file "/etc/systemd/system/mariadb.service",
- # containing
- # .include /usr/lib/systemd/system/mariadb.service
- # ...make your changes here...
- # or create a file "/etc/systemd/system/mariadb.service.d/foo.conf",
- # which doesn't need to include ".include" call and which will be parsed
- # after the file mariadb.service itself is parsed.
- #
- # For more info about custom unit files, see systemd.unit(5) or
- # https://mariadb.com/kb/en/mariadb/systemd/
- #
- # Copyright notice:
- #
- # This file is free software; you can redistribute it and/or modify it
- # under the terms of the GNU Lesser General Public License as published by
- # the Free Software Foundation; either version 2.1 of the License, or
- # (at your option) any later version.
- [Unit]
- Description=MariaDB 11.3.2 database server
- Documentation=man:mariadbd(8)
- Documentation=https://mariadb.com/kb/en/library/systemd/
- After=network.target
- [Install]
- WantedBy=multi-user.target
- [Service]
- ##############################################################################
- ## Core requirements
- ##
- Type=notify
- # Setting this to true can break replication and the Type=notify settings
- # See also bind-address mariadbd option.
- PrivateNetwork=false
- ##############################################################################
- ## Package maintainers
- ##
- User=mariadb
- Group=mariadb
- # CAP_IPC_LOCK To allow memlock to be used as non-root user
- # CAP_DAC_OVERRIDE To allow auth_pam_tool (which is SUID root) to read /etc/shadow when it's chmod 0
- # does nothing for non-root, not needed if /etc/shadow is u+r
- # CAP_AUDIT_WRITE auth_pam_tool needs it on Debian for whatever reason
- CapabilityBoundingSet=CAP_IPC_LOCK CAP_DAC_OVERRIDE CAP_AUDIT_WRITE
- # PrivateDevices=true implies NoNewPrivileges=true and
- # SUID auth_pam_tool suddenly doesn't do setuid anymore
- PrivateDevices=false
- # Prevent writes to /usr, /boot, and /etc
- ProtectSystem=false
- # Database dir: '/usr/local/mariadb/data' should be writable even
- # ProtectSystem=full prevents it
- ReadWritePaths=-/usr/local/data/mariadb
- # Doesn't yet work properly with SELinux enabled
- # NoNewPrivileges=true
- # Prevent accessing /home, /root and /run/user
- ProtectHome=false
- # Execute pre and post scripts as root, otherwise it does it as User=
- PermissionsStartOnly=true
- # Perform automatic wsrep recovery. When server is started without wsrep,
- # galera_recovery simply returns an empty string. In any case, however,
- # the script is not expected to return with a non-zero status.
- # It is always safe to unset _WSREP_START_POSITION environment variable.
- # Do not panic if galera_recovery script is not available. (MDEV-10538)
- ExecStartPre=/bin/sh -c "systemctl unset-environment _WSREP_START_POSITION"
- ExecStartPre=/bin/sh -c "[ ! -e /usr/local/mariadb/bin/galera_recovery ] && VAR= || \
- VAR=`cd /usr/local/mariadb/bin/..; /usr/local/mariadb/bin/galera_recovery`; [ $? -eq 0 ] \
- && systemctl set-environment _WSREP_START_POSITION=$VAR || exit 1"
- # Needed to create system tables etc.
- # ExecStartPre=/usr/local/mariadb/scripts/mysql
- _install_db -u mariadb
- # Start main service
- # MYSQLD_OPTS here is for users to set in /etc/systemd/system/mariadb.service.d/MY_SPECIAL.conf
- # Use the [Service] section and Environment="MYSQLD_OPTS=...".
- # This isn't a replacement for my.cnf.
- # _WSREP_NEW_CLUSTER is for the exclusive use of the script galera_new_cluster
- ExecStart=/usr/local/mariadb/bin/mariadbd $MYSQLD_OPTS $_WSREP_NEW_CLUSTER $_WSREP_START_POSITION
- # Unset _WSREP_START_POSITION environment variable.
- ExecStartPost=/bin/sh -c "systemctl unset-environment _WSREP_START_POSITION"
- KillSignal=SIGTERM
- # Don't want to see an automated SIGKILL ever
- SendSIGKILL=no
- # Restart crashed server only, on-failure would also restart, for example, when
- # my.cnf contains unknown option
- Restart=on-abort
- RestartSec=5s
- UMask=007
- ##############################################################################
- ## USERs can override
- ##
- ##
- ## by creating a file in /etc/systemd/system/mariadb.service.d/MY_SPECIAL.conf
- ## and adding/setting the following under [Service] will override this file's
- ## settings.
- # Useful options not previously available in [mysql
- d_safe]
- # Kernels like killing mariadbd when out of memory because its big.
- # Lets temper that preference a little.
- # OOMScoreAdjust=-600
- # Explicitly start with high IO priority
- # BlockIOWeight=1000
- # If you don't use the /tmp directory for SELECT ... OUTFILE and
- # LOAD DATA INFILE you can enable PrivateTmp=true for a little more security.
- PrivateTmp=false
- # Set an explicit Start and Stop timeout of 900 seconds (15 minutes!)
- # this is the same value as used in SysV init scripts in the past
- # Galera might need a longer timeout, check the KB if you want to change this:
- # https://mariadb.com/kb/en/library/systemd/#configuring-the-systemd-service-timeout
- TimeoutStartSec=900
- TimeoutStopSec=900
- # Set the maximium number of tasks (threads) to 99% of what the system can
- # handle as set by the kernel, reserve the 1% for a remote ssh connection,
- # some monitoring, or that backup cron job. Without the directive this would
- # be 15% (see DefaultTasksMax in systemd man pages).
- TasksMax=99%
- ##
- ## Options previously available to be set via [mysql
- d_safe]
- ## that now needs to be set by systemd config files as mysql
- d_safe
- ## isn't executed.
- ##
- # Number of files limit. previously [mysql
- d_safe] open-files-limit
- LimitNOFILE=32768
- # Maximium core size. previously [mysql
- d_safe] core-file-size
- # LimitCore=
- # Nice priority. previously [mysql
- d_safe] nice
- # Nice=-5
- # Timezone. previously [mysql
- d_safe] timezone
- # Environment="TZ=UTC"
- # Library substitutions. previously [mysql
- d_safe] malloc-lib with explicit paths
- # (in LD_LIBRARY_PATH) and library name (in LD_PRELOAD).
- # Environment="LD_LIBRARY_PATH=/path1 /path2" "LD_PRELOAD=
- # Flush caches. previously [mysql
- d_safe] flush-caches=1
- # ExecStartPre=sync
- # ExecStartPre=sysctl -q -w vm.drop_caches=3
- # numa-interleave=1 equalivant
- # Change ExecStart=numactl --interleave=all /usr/local/mariadb/bin/mariadbd......
- # crash-script equalivent
- # FailureAction=
复制代码 不修改会报错
报错详情:详细信息看
2.9 启动服务
- systemctl daemon-reload
- systemctl enable mariadb.service
- systemctl start mariadb.service
- systemctl status mariadb.service
复制代码 systemctl enable mariadb.service 实行后,会出现提示.我是已经实行过一次了.
2.10 配置环境变量
添加
- export PATH=$PATH:/usr/local/mariadb/bin
复制代码
配置立刻生效
3 mysql
测试和配置
3.1 测试毗连(未配置密码)
- [root@localhost ~]# mysql
- Welcome to the MariaDB monitor. Commands end with ; or \g.Your MariaDB connection id is 11Server version: 10.2.43-MariaDB-log MariaDB ServerCopyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.MariaDB [(none)]> show databases;+--------------------+| Database |+--------------------+| information_schema || mysql
- || performance_schema || test |+--------------------+4 rows in set (0.01 sec)MariaDB [(none)]> select version();+---------------------+| version() |+---------------------+| 10.2.43-MariaDB-log |+---------------------+1 row in set (0.01 sec)MariaDB [(none)]> Ctrl-C -- exit!Aborted[root@localhost ~]#
复制代码 3.2 选择mysql
数据库
- [root@localhost ~]# mysql
- Welcome to the MariaDB monitor. Commands end with ; or \g.Your MariaDB connection id is 12Server version: 10.2.43-MariaDB-log MariaDB ServerCopyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.MariaDB [(none)]> use mysql
- ;Database changedMariaDB [mysql
- ]>
复制代码 3.3 为root用户设置密码
- MariaDB [(none)]> use mysql
- ;Database changedMariaDB [mysql
- ]> set password for root@localhost=password('123456');Query OK, 0 rows affected (0.00 sec)MariaDB [mysql
- ]> select user,host,password from mysql
- .user;+------+-----------------------+-------------------------------------------+| user | host | password |+------+-----------------------+-------------------------------------------+| root | localhost | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 || root | localhost.localdomain | || root | 127.0.0.1 | || root | ::1 | || | localhost | || | localhost.localdomain | |+------+-----------------------+-------------------------------------------+6 rows in set (0.00 sec)MariaDB [mysql
- ]>
复制代码 3.4 测试账号密码
3.5 设置外部毗连访问
利用数据库工具访问失败,因为没有配置外部访问;
进入数据库
设置mysql
允许外部毗连访问(授权):
- //授权
- grant all privileges on *.* to root@'%' identified by '123456' with grant option;
- //刷新
- flush privileges;
复制代码 指定ip地址授权(毗连时失败报错1130弹出的地址)
- grant all privileges on *.* to root@'ip地址' identified by '密码' with grant option;
- flush privileges;
复制代码- [root@localhost ~]# mysql
- -uroot -pEnter password: Welcome to the MariaDB monitor. Commands end with ; or \g.Your MariaDB connection id is 15Server version: 10.2.43-MariaDB-log MariaDB ServerCopyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.MariaDB [(none)]> use mysql
- ;Database changedMariaDB [mysql
- ]> select user.User,user.host,user.Password from user;+------+-----------------------+-------------------------------------------+| User | host | Password |+------+-----------------------+-------------------------------------------+| root | localhost | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 || root | localhost.localdomain | || root | 127.0.0.1 | || root | ::1 | || | localhost | || | localhost.localdomain | |+------+-----------------------+-------------------------------------------+6 rows in set (0.00 sec)MariaDB [mysql
- ]> grant all privileges on *.* to root@'%' identified by '123456' with grant option;Query OK, 0 rows affected (0.00 sec)MariaDB [mysql
- ]> flush privileges;Query OK, 0 rows affected (0.00 sec)MariaDB [mysql
- ]>
复制代码 毗连成功
六、MariaDB主从复制
1 主从赋值前必要注意事项
- 1. 主从复制肯定需要一主一从了,两个数据库先装好
- 2. 虽然不强制,但是尽量两台数据库的密码相同
- 3. 下面就使用A和B数据库来代替,A是主B是从
复制代码 2 开始举行主从同步操作
2.1 修改配置文件
A和B数据库都举行修改,没有的话就添加
- # 服务器id,即唯一id,推荐使用ip的最后一节(主从不一样)
- server-id = 161
- # 该值为整个结构中服务器的总数(主从一样)
- auto-increment-increment = 2
- # 避免主键冲突,主从服务器需要设置不同的值(主从不一样)
- auto-increment-offset = 1
复制代码 2.2 防火墙设置
A:(192.168.200.161)
- firewall-cmd --permanent --add-rich-rule 'rule family=ipv4 source address= 192.168.200.162 port port=3306 protocol=tcp accept'
- firewall-cmd --reload
复制代码 B:(192.168.200.162)
- firewall-cmd --permanent --add-rich-rule 'rule family=ipv4 source address= 192.168.200.161 port port=3306 protocol=tcp accept'
- firewall-cmd --reload
复制代码 2.3 创建同步所需的用户
A:(192.168.200.161)
- # mysql
- -uroot -p123456grant replication slave on *.* to copy1@192.168.200.162 identified by '123456';
复制代码 B:(192.168.200.162)
- # mysql
- -uroot -p123456grant replication slave on *.* to copy2@192.168.200.161 identified by '123456';
复制代码 2.4 配置同步
A:(192.168.200.161)
- MariaDB [(none)]> show master status; 记录下A的File和Position| mysql
- -bin.000003 | 562 | | |
复制代码 B:(192.168.200.162)
- MariaDB [(none)]> show master status; 记录下B的File和Position| mysql
- -bin.000005 | 546 | | |
复制代码 A:(192.168.200.161)
- change master to master_host='192.168.200.162',master_user='copy2',master_password='123456',master_log_file='mysql
- -bin.000005',master_log_pos=546,master_port=3306;start slave;
复制代码 B:(192.168.200.162)
- change master to master_host='192.168.200.161', master_user='copy1',master_password='123456',master_log_file='mysql
- -bin.000003',master_log_pos=562 ,master_port=3306;start slave;
复制代码 最后查看是否成功:
看到这样就是成功了
3 查抄报错(出现问题时利用)
- MariaDB [(none)]> stop slave;
- MariaDB [(none)]> reset slave;
- MariaDB [(none)]> flush logs;
- MariaDB [(none)]> show master status;
- MariaDB [(none)]> change master to master_host='【另一台的IP】', master_user='copy1',master_password='EV7F4!RX',master_log_file='【另一台的File】',master_log_pos=【另一台的Position】,master_port=3306;
复制代码 免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。 |