ToB企服应用市场:ToB评测及商务社交产业平台

标题: Linux(CentOs7)基础配置及安装本地yum源、redis、elasticsearch、kafka、ma [打印本页]

作者: 惊雷无声    时间: 2024-7-28 08:33
标题: Linux(CentOs7)基础配置及安装本地yum源、redis、elasticsearch、kafka、ma
一、简介

  1. 本次安装持续更新,如果发现文章安装流程出现错误。可以留言评论指正,大家一起完善。如果有其他的需要安装的应用,可以留言,我争取加入进来。
  2. 此次安装全部为二进制安装,后续会出一个docker版本,系统为CentOs7,我会将所有的安装包放到网盘中。
复制代码
二、服务器配置修改

1 防火墙相关配置

  1. systemctl status firewalld
  2. systemctl enable firewalld
  3. systemctl start firewalld
  4. firewall-cmd --reload
  5. firewall-cmd --list-all
复制代码
  1. # 开启端口
  2. firewall-cmd --zone=public --add-port=6030-6060/tcp --permanent
  3. firewall-cmd --zone=public --add-port=3306/tcp --permanent
  4. # 临时开启协议规则
  5. firewall-cmd --permanent --add-port=3306/tcp
  6. firewall-cmd --permanent --add-port=9200/tcp
  7. # 删除规则
  8. firewall-cmd --permanent --remove-port=3306/tcp
  9. firewall-cmd --permanent --remove-port=9200/tcp
复制代码
2 配置本地yum源(内网环境必要配置)

2.1 下载地址

清华大学网站
下载本身服务器类型的ios镜像(下载链接中含Everything)的比如 CentOS-7-x86_64-Everything-2009.iso;
2.2 上传安装

  1. 1.系统内执行命令,查看文件系统的磁盘空间占用情况,确认镜像的上传位置(df -h)
  2. 2.比如:我放到/root下
  3. 3.创建新的目录:/root/localyum
  4. 4.通过命令将yum挂载到/root/localyum下
  5. mount -o loop /root/CentOS-7-x86_64-Everything-2009.iso /root/localyum
  6. mount -a
  7. 5. df -h查看是否成功
复制代码

2.3 配置本地yum

  1. vi /etc/yum.repos.d/Centos-7.repo
  2. [base]
  3. name= yum repo
  4. baseurl=file:///root/localyum
  5. enabled=1
  6. gpgcheck=0
复制代码
  1. 执行
  2. 执行以下命令,清除原始yum缓存; yum clean all
  3. 执行以下命令,查看目前拥有的yum源仓库; yum repolist all
  4. 执行以下命令,刷新缓存; yum makecache
  5. 执行以下命令,显示所有可以安装的程序包,当可用软件包的来源名称是我们配置的yum源名称时,表示yum配置成功;  
  6. yum list available |more
复制代码
3 安装须要环境(确保本地yum安装完毕大概服务器能上网)

3.1 安装gcc

  1. yum install -y gcc git wget vim ntp lsof
  2. yum install -y pcre pcre-devel zlib zlib-devel openssl openssl-devel
复制代码
3.2 修改系统配置文件

  1. vim /etc/security/limits.conf
复制代码
添加以下内容
  1. * hard nofile 131072
  2. * soft nproc 2048
  3. * hard nproc 4096
复制代码
继承修改另一个配置文件
  1. vi /etc/sysctl.conf
复制代码
添加以下内容
  1. vm.swappiness=1
  2. vm.max_map_count=655360
复制代码
修改时区(时区有问题时利用)
  1. rm -f /etc/localtime
  2. ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
复制代码
刷新配置文件
  1. sysctl -p
复制代码
selinux设置必要重启服务器
  1. vi /etc/sysconfig/selinux
复制代码


4 NTP 同步时间安装

4.1 安装命令

  1. yum install ntp
复制代码
4.2 修改配置文件

  1. vi /etc/ntp.conf
复制代码

  1. server ntp.aliyun.com iburst
复制代码
假如服务器是内部服务器将三台的的时间都指向一个服务器就行(三台都写一个)
  1. server 192.168.200.161 iburst
复制代码
4.3 启动服务

启动
  1. systemctl start ntpd
复制代码
开机自启
  1. chkconfig ntpd on
复制代码
三、Linux二进制安装JDK1.8

1 下载JDK

百度网盘分享(软件扩展->Linux安装包中)百度网盘分享
官网下载 JDK官网下载地址

选择必要的版本下载就行;
2 安装JDK

将文件压缩包传上传到服务器/home目录下
  1. cd /home
复制代码
解压压缩文件
  1. cd /usr/local/
  2. mkdir java
  3. tar -zxvf /home/jdk-8u371-linux-x64.tar.gz -C /usr/local/java/
复制代码
查看是否成功
  1. cd /usr/local/java/
复制代码

3 配置环境变量

编辑/etc/profile文件
  1. vi /etc/profile
复制代码
按i进入编辑,在profile文件尾部添加如下内容(JAVA_HOME的值是jdk安装目录)
  1. export JAVA_HOME=/usr/local/java/jdk1.8.0_371
  2. export JRE_HOME=${JAVA_HOME}/jre
  3. export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib:$CLASSPATH
  4. export JAVA_PATH=${JAVA_HOME}/bin:${JRE_HOME}/bin
  5. export PATH=$PATH:${JAVA_PATH}
复制代码
按Esc退出编辑状态,然后输入:wq生存并退出

通过命令source /etc/profile

让profile文件立刻生效
  1. source /etc/profile
复制代码
测试是否安装成功
  1. java -version
复制代码

四、Linux二进制安装TDengine集群

文章参考:集群部署和管理
规划物理节点:
IP地址hostname192.168.200.161node161192.168.200.162node162192.168.200.163node163 1 修改服务器hostname

到3台服务器中修改对应的hostname,并重启服务器
  1. vi /etc/hostname
  2. node161
复制代码
2 修改/etc/hosts

对应服务器修改/etc/hosts,在最后添加对应的服务器的节点ip、hostname
  1. vi /etc/hosts
  2. # 添加对应的节点
  3. 192.168.200.161 node161
  4. 192.168.200.162 node162
  5. 192.168.200.163 node163
复制代码
设置完成后,查抄服务器之间是否能ping通,ping通则说明配置成功
3 开放端口

发起不要直接关闭防火墙
  1. # 添加一个TCP端口范围(6030至6060)
  2. firewall-cmd --zone=public --add-port=6030-6060/tcp --permanent
  3. # 重启防火墙
  4. firewall-cmd --reload
  5. # 检查端口是否开放
  6. firewall-cmd --list-all
复制代码
4 服务器时钟同步 NTP

详情看 NTP 同步时间安装
5 官网下载对应必要的安装server文件


官方网站下载:官网下载地址
百度网盘下载:网盘链接

6 安装TDengine

6.1 上传解压

将文件上传到/opt下

解压下载的文件包
  1. tar -zxvf /opt/TDengine-server-3.2.2.0-Linux-x64.tar.gz
复制代码
进入文件夹
  1. cd /opt/TDengine-server-3.2.2.0
复制代码
6.2 开始安装

  1. ./install.sh
复制代码
看好这个步骤很紧张:
6.2.1 实行./install.sh
后,会出现本身本机的hostname,点击回车键进入下一步



6.2.2 回车后会出现此选项,相当于设置集群的主节点。firstEp 是每个数据节点首次启动后毗连的第一个数据节点


6.2.3 设置后点击回车(必须设置)


6.2.4 此步直接回车



6.2.5 安装成功后,进入配置文件查看

  1. vi /etc/taos/taos.cfg
复制代码

7 启动TDengine

启动服务进程
  1. systemctl start taosd
复制代码
竣事服务进程
  1. systemctl stop taosd
复制代码
重启服务进程
  1. systemctl restart taosd
复制代码
查看服务状态
  1. systemctl status taosd
复制代码
开机自启
  1. systemctl enable taosd
复制代码
移除开机自启
  1. systemctl disable taosd
复制代码

8 启动taosAdapter

紧张是利用REST毗连时利用
启动服务进程
  1. systemctl start taosadapter
复制代码
竣事服务进程
  1. systemctl stop taosadapter
复制代码
重启服务进程
  1. systemctl restart taosadapter
复制代码
查看服务状态
  1. systemctl status taosadapter
复制代码
开机自启
  1. systemctl enable taosadapter
复制代码
移除开机自启
  1. systemctl disable taosadapter
复制代码
9 添加数据节点

在服务器任意节点(一般实行主节点)实行 taos(没有修改过密码直接实行,默认密码 taosdata)
  1. taos -u root -p123456
复制代码

实行 show dnodes可以看到只有一个节点
  1. show dnodes;
复制代码

加入其他节点后再次实行 show dnodes;在其他节点上实行可以看到全部都是一样的。
  1. create dnode 'node162:6030';
复制代码
  1. create dnode 'node163:6030';
复制代码

10 安装TDengine客户端(windows)

官方下载:官方链接
百度网盘:网盘链接
实行安装程序,按提示选择默认值,完成安装
10.1 修改windows的配置

修改 C:\Windows\System32\drivers\etc\hosts,在文件最后添加服务器的ip以及hostname
  1. 192.168.200.161 node161
  2. 192.168.200.162 node162
  3. 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 利用示例

  1. # 查看所有用户
  2. taos> show users;
  3.            name           | privilege |       create_time       |         account          |
  4. ============================================================================================
  5. _root                    | writable  | 2022-04-06 15:12:53.714 | root                     |
  6. monitor                  | writable  | 2022-04-06 15:12:53.714 | root                     |
  7. root                     | super     | 2022-04-06 15:12:53.714 | root                     |
  8. # 修改当前root用户密码为123456
  9. taos> alter user root pass '123456';
  10. Query OK, 0 of 0 row(s) in database (0.067138s)
  11. # 创建用户test密码为123456
  12. taos> create user test pass '123456';
  13. Query OK, 0 of 0 row(s) in database (0.072157s)
  14. # 删除test用户
  15. taos> drop user wanwu;
  16. 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

  1. 本机或者服务器的host文件没有修改、查看本机是否开启了vpn
  2. 使用REST 方式进行连接时,记得端口由6030改为6041,需要开启taosadapter
复制代码
13 在其他服务器毗连步骤

在其他服务器上启动带有TDengine的jar包是失败的,因为jia包所在的服务必要安装客户端举行毗连
安装包利用只管利用同等的。我的网盘中都有 网盘下载
毗连方式很简单,就是在必要毗连的服务器 /etc/hosts上先配置TDengine集群的IP映射;然后根据步骤举行安装就行。安装链接
五、Linux二进制安装MariaDB

1 卸载mariadb

1.1 卸载相关的服务(mysql
和mariadb都查询一下)


查抄MySQL mariadb
  1. rpm -qa|grep mysql
  2. rpm -qa|grep mariadb
复制代码
 假如存在,删除服务
  1. rpm -ev mariadb-libs-5.5.68-1.el7.x86_64 --nodeps
复制代码

1.2 查找MySQL和mariadb相关的文件目录

  1. find / -name mysql
  2. find / -name mariadb
复制代码

 删除目录(因为我docker里也安装了mysql
,以是根据本身情况删除 )
  1. rm -rf /usr/lib64/mysql
  2. rm -rf /usr/local/mysql
  3. rm -rf /usr/local/mysql
  4. /bin/mysql
  5. rm -rf /usr/local/mysql
  6. /include/mysql
  7. rm -rf /home/kibana-7.9.3-linux-x86_64/node_modules/monaco-editor/dev/vs/basic-languages/mysql
  8. rm -rf /home/kibana-7.9.3-linux-x86_64/node_modules/monaco-editor/esm/vs/basic-languages/mysql
  9. rm -rf /home/kibana-7.9.3-linux-x86_64/node_modules/monaco-editor/min/vs/basic-languages/mysql
  10. rm -rf /data/mysql
  11. rm -rf /data/mysql
  12. /mysql
复制代码

2 安装mariadb

2.1 mariadb下载地址

下载地址: https://mariadb.org/download
百度网盘下载链接:百度网盘

2.2 将安装包放入到服务器中并解压 (我放到opt下)


  1. #解压命令
  2. tar -zxvf mariadb-10.2.43-linux-systemd-x86_64.tar.gz
复制代码

2.3 将解压后的目录移动到安装目录下

  1. mv /opt/mariadb-10.2.43-linux-systemd-x86_64 /usr/local/mariadb
复制代码

2.4 创建数据目录(根据本身情况修改)

 我的数据位置在/usr/local/data/mariadb
  1. cd /usr/local
  2. mkdir data
  3. cd data
  4. mkdir mariadb
复制代码
2.5 添加用户组和用户及其权限

  1. #1.创建组
  2. groupadd mariadb
  3. #2.创建用户,赋予权限(注意目录)
  4. useradd -g mariadb mariadb
  5. #3.给mysql
  6. 用户赋予权限(第二步可能会报错,不用管,直接第三步,原因还未找到.解决可以评论和私信我)
  7. chown -R mariadb.mariadb /usr/local/data/mariadb /usr/local/mariadb
复制代码
2.5.1 组和用户的操作命令

  1. 一,组操作
  2. #1,创建组 增加一个test组
  3. groupadd  test
  4. #2,修改组 将test组的名子改成test2
  5. groupmod -n test2  test
  6. #3,删除组 删除 组test2
  7. groupdel test2
  8. #4,查看组
  9. a),查看当前登录用户所在的组 groups,查看apacheuser所在组groups apacheuser
  10. b),查看所有组 cat /etc/group
  11. c),有的linux系统没有/etc/group文件的,这个时候看下面的这个方法
  12. cat /etc/passwd |awk -F [:] '{print $4}' |sort|uniq | getent group |awk -F [:] '{print $1}'
  13. 这里用到一个命令是getent,可以通过组ID来查找组信息,如果这个命令没有的话,那就很难查找,系统中所有的组了.
  14. 二,用户操作
  15. #1,增加用户
  16. 查看复制打印?
  17. [root@krlcgcms01 mytest]# useradd --help  
  18. Usage: useradd [options] LOGIN  
  19.   
  20. Options:  
  21. -b, --base-dir BASE_DIR       设置基本路径作为用户的登录目录  
  22. -c, --comment COMMENT         对用户的注释  
  23. -d, --home-dir HOME_DIR       设置用户的登录目录  
  24. -D, --defaults                改变设置  
  25. -e, --expiredate EXPIRE_DATE  设置用户的有效期  
  26. -f, --inactive INACTIVE       用户过期后,让密码无效  
  27. -g, --gid GROUP               使用户只属于某个组  
  28. -G, --groups GROUPS           使用户加入某个组  
  29. -h, --help                    帮助  
  30. -k, --skel SKEL_DIR           指定其他的skel目录  
  31. -K, --key KEY=VALUE           覆盖 /etc/login.defs 配置文件  
  32. -m, --create-home             自动创建登录目录  
  33. -l,                           不把用户加入到lastlog文件中  
  34. -M,                           不自动创建登录目录  
  35. -r,                           建立系统账号  
  36. -o, --non-unique              允许用户拥有相同的UID  
  37. -p, --password PASSWORD       为新用户使用加密密码  
  38. -s, --shell SHELL             登录时候的shell  
  39. -u, --uid UID                 为新用户指定一个UID  
  40. -Z, --selinux-user SEUSER     use a specific SEUSER for the SELinux user mapping  
  41. useradd test
  42. passwd test
  43. 增加用户test,有一点要注意的,useradd增加一个用户后,不要忘了给他设置密码,不然不能登录的。
  44. #2,修改用户
  45. usermod -d /home/test -G test2 test
  46. 将test用户的登录目录改成/home/test,并加入test2组,注意这里是大G。
  47. gpasswd -a test test2 将用户test加入到test2组
  48. gpasswd -d test test2 将用户test从test2组中移出
  49. #3,删除用户
  50. userdel test
  51. 将test用户删除
  52. #4,查看用户
  53. a),查看当前登录用户
  54. [root@krlcgcms01 ~]# w
  55. [root@krlcgcms01 ~]# who
  56. b),查看自己的用户名
  57. [root@krlcgcms01 ~]# whoami
  58. c),查看单个用户信息
  59. [root@krlcgcms01 ~]# finger apacheuser
  60. [root@krlcgcms01 ~]# id apacheuser
  61. d),查看用户登录记录
  62. [root@krlcgcms01 ~]# last 查看登录成功的用户记录
  63. [root@krlcgcms01 ~]# lastb 查看登录不成功的用户记录
  64. e),查看所有用户
  65. [root@krlcgcms01 ~]# cut -d : -f 1 /etc/passwd
  66. [root@krlcgcms01 ~]# cat /etc/passwd |awk -F \: '{print $1}'
复制代码
2.6 安装mariadb

  1. cd /usr/local/mariadb/
  2. ./scripts/mysql
  3. _install_db --basedir=/usr/local/mariadb --datadir=/usr/local/data/mariadb --skip-name-resolve --user=mariadb
复制代码
 安装成功

 查看数据目录

2.7 创建配置文件 /etc/my.cnf

  1. cd /etc/
  2. #展示my.cnf文件,没有不展示
  3. ls -ltr my.cnf
  4. #有的话,备份删除
  5. mv my.cnf my.cnf.backup
  6. #创建新的文件
  7. vi my.cnf
复制代码
my.cnf详细配置(网上有很多,找一个就行,但是注意目录的修改)
  1. [client]
  2. port    = 3306
  3. socket  = /tmp/mariadb.sock
  4. [mysql
  5. d]
  6. port    = 3306
  7. socket  = /tmp/mariadb.sock
  8. user    = mariadb
  9. basedir = /usr/local/mariadb
  10. datadir = /usr/local/data/mariadb
  11. log_error = /usr/local/data/mariadb/mariadb.err
  12. pid-file  = /usr/local/data/mariadb/mariadb.pid
  13. # 禁用DNS解析,使用IP访问的情况下加快访速度。
  14. skip_name_resolve
  15. skip-external-locking
  16. #skip-networking
  17. # 关闭认证,取消注释,可重置 root 密码
  18. # skip-grant-tables
  19. # 这个参数用来缓存MyISAM存储引擎的索引参数。MySQL5.5默认为InnoDB存储引擎,所以这个参数可以设置小点,64MB即可。
  20. key_buffer_size = 64M
  21. # 每个连接传输数据大小.最大1G,须是1024的倍数,一般设为最大的BLOB的值。
  22. # 允许最大接收数据包的大小,防止服务器发送过大的数据包。可以设置为16MB或者更大,但设置的太大也可能有危险。
  23. max_allowed_packet = 4M
  24. # MySQL每打开一个表,都会读入一些数据到table_open_cache缓存中,当MySQL在这个缓存中找不到相应信息时,才会去磁盘上读取。
  25. # 默认值64,假定系统有200个并发连接,则需将此参数设置为200*N(N为每个连接所需的文件描述符数目);
  26. # 当把table_open_cache设置为很大时,如果系统处理不了那么多文件描述符,那么就会出现客户端失效,连接不上。
  27. table_open_cache = 256
  28. # 排序缓冲被用来处理类似ORDER BY以及GROUP BY队列所引起的排序。
  29. # 在表进行order by和group by排序操作时,由于排序的字段没有索引,会出现Using filesort,为了提高性能,可用此参数增加每个线程分配的缓冲区大小。
  30. # 默认为256KB,这个参数不要设置过大,一般在128~256KB即可。另外,一般出现Using filesort的时候,要通过增加索引来解决。
  31. sort_buffer_size = 1M
  32. # 不带索引的全表扫描.使用的buffer的最小值
  33. join_buffer_size = 16M
  34. # 包消息缓冲区初始化为net_buffer_length字节,但需要时可以增长到max_allowed_packet字节。
  35. net_buffer_length = 8K
  36. # 该参数用于表的顺序扫描,表示每个线程分配的缓冲区大小。
  37. # 比如在进行全表扫描时,MySQL会按照数据的存储顺序依次读取数据块,每次读取的数据块首先会暂存在read_buffer_size中
  38. # 当buffer空间被写满或者全部数据读取结束后,再将buffer中的数据返回给上层调用者,以提高效率。
  39. # 默认为128K,这个参数不要设置过大,一般在128~256之间。
  40. read_buffer_size = 1M
  41. # 该参数用于表的随机读取,表示每个线程分配的缓冲区大小。
  42. # 比如,按照一个非索引字段做order by排序操作时,就会利用这个缓冲区来暂存读取的数据。
  43. # 默认为256KB,这个参数不要设置过大,一般在128~512KB。
  44. read_rnd_buffer_size = 512K
  45. # 当对MyISAM表执行repair table或创建索引时,用以缓存排序索引;设置太小时可能会遇到” myisam_sort_buffer_size is too small”
  46. myisam_sort_buffer_size = 16M
  47. # 线程池,线程缓存。用来缓存空闲的线程,以至于不被销毁,如果线程缓存在的空闲线程,需要重新建立新连接,则会优先调用线程池中的缓存,很快就能响应连接请求。
  48. # 每建立一个连接,都需要一个线程与之匹配。
  49. thread_cache_size = 32
  50. # 查询缓冲大小
  51. # 缓存select语句和结果集大小的参数。
  52. # 查询缓存会存储一个select查询的文本与被传送到客户端的相应结果。
  53. # 如果之后接收到一个相同的查询,服务器会从查询缓存中检索结果,而不是再次分析和执行这个同样的查询。
  54. # 如果你的环境中写操作很少,读操作频繁,那么打开query_cache_type=1,会对性能有明显提升。
  55. # 如果写操作频繁,则应该关闭它(query_cache_type=0)。
  56. query_cache_size = 32M
  57. # 指定单个查询能够使用的缓冲区大小,缺省为1M
  58. query_cache_limit = 4M
  59. # 临时HEAP数据表的最大长度(默认设置是32M); 超过这个长度的临时数据表将被转换为MyISAM数据表并存入一个临时文件。
  60. tmp_table_size = 64M
  61. # 设定默认的事务隔离级别
  62. transaction_isolation = REPEATABLE-READ
  63. # 线程使用的堆大小. 此值限制内存中能处理的存储过程的递归深度和SQL语句复杂性,此容量的内存在每次连接时被预留.
  64. thread_stack = 512K
  65. # 指定一个请求的最大连接时间
  66. wait_timeout = 10
  67. # 是否显示默认时间戳。
  68. explicit_defaults_for_timestamp = true
  69. # 该参数用来设置最大连接数,告诉你当前你的服务器允许多少并发连接。
  70. # 默认为100,一般设置为512-1000即可。请记住,太多的连接会导致内存的使用量过高并且会锁住你的 MySQL 服务器。
  71. # 一般小网站需要 100-200 的连接数,而较大可能需要 500-800 甚至更多。这里的值很大程度上取决于你 MySQL/MariaDB 的使用情况。
  72. max_connections = 500
  73. # 每个客户端连接最大的错误允许数量,当超过该次数,MYSQL服务器将禁止此主机的连接请求,直到MYSQL服务器重启或通过flush hosts命令清空此主机的相关信息
  74. # 如果有时网络抽风,或者应用配置错误,或者其他原因导致客户端短时间内不断的尝试连接,客户端可能会被列入黑名单,然后将无法连接,直到再次刷新主机缓存。
  75. # 这个选项默认值太小了,可以考虑设的足够大(如果你的服务器配置够强大的话)。
  76. max_connect_errors = 100
  77. # mysql
  78. 打开最大文件数
  79. open_files_limit = 65535
  80. # 是操作系统在监听队列中所能保持的连接数
  81. back_log = 300
  82. # 开启二进制日志功能,若不指定路径则默认和数据存放在同一目录,生产环境强烈建议将MySQL日志和数据分开存放。
  83. log-bin=mysql
  84. -bin
  85. # 指定默认的二进制日志格式。
  86. binlog_format=mixed
  87. # 给服务器分配一个独一无二的ID编号; n的取值范围是1~2的32次方启用二进制日志功能。在复制数据同步的时候会用到,Helloweba后面会有文章介绍。
  88. server-id   = 1
  89. # 启用二进制日志后,保留日志的天数。服务器会自动清理指定天数前的日志文件,如果不设置则会导致服务器空间耗尽。一般设置为7~14天。
  90. expire_logs_days = 10
  91. # 用 InnoDB 作为默认引擎
  92. # 新数据表的默认存储引擎(默认设置是MyISAM)。这项设置还可以通过–default-table-type选项来设置。
  93. default_storage_engine = InnoDB
  94. # 打开独立表空间
  95. # InnoDB 提供了更灵活的方式,它把每个数据库的信息保存在一个 .ibd 数据文件中。每个 .idb 文件代表它自己的表空间。
  96. # 通过这样的方式可以更快地完成类似 “TRUNCATE” 的数据库操作,当删除或截断一个数据库表时,你也可以回收未使用的空间。
  97. # 这样配置的另一个好处是你可以将某些数据库表放在一个单独的存储设备。这可以大大提升你磁盘的 I/O 负载。
  98. innodb_file_per_table = 1
  99. # InnoDB主目录,所有与InnoDB数据表有关的目录或文件路径都相对于这个路径。在默认的情况下,这个主目录就是MySQL的数据目录。
  100. innodb_data_home_dir = /usr/local/data/mariadb
  101. # 用来容纳InnoDB为数据表的表空间: 可能涉及一个以上的文件; 每一个表空间文件的最大长度都必须以字节(B)、兆字节(MB)或千兆字节(GB)为单位给出;
  102. # 表空间文件的名字必须以分号隔开; 最后一个表空间文件还可以带一个autoextend属性和一个最大长度(max:n)
  103. innodb_data_file_path = ibdata1:10M:autoextend
  104. # 用来存放InnoDB日志文件的目录路径(如ib_logfile0、ib_logfile1等)。在默认的情况下,InnoDB驱动程序将使用 MySQL数据目录作为自己保存日志文件的位置。
  105. innodb_log_group_home_dir = /usr/local/data/mariadb
  106. # InnoDB使用一个缓冲池来保存索引和原始数据, 可设置这个变量到服务器物理内存大小的80%
  107. # 这个参数是InnoDB存储引擎的核心参数,默认为128KB,这个参数要设置为物理内存的60%~70%。
  108. innodb_buffer_pool_size = 2048M
  109. # 在InnoDb核心内的允许线程数量,建议的设置是CPU数量加上磁盘数量的两倍
  110. innodb_thread_concurrency = 16
  111. # 在日志组中每个日志文件的大小
  112. # 事务日志文件写操作缓存区的最大长度(默认设置是1MB)。
  113. innodb_log_file_size = 64M
  114. # 用来缓冲日志数据的缓冲区的大小
  115. # 事务日志所使用的缓存区。InnoDB在写事务日志的时候,为了提高性能,先将信息写入Innodb Log Buffer中,
  116. # 当满足innodb_flush_log_trx_commit参数所设置的相应条件(或者日志缓冲区写满)时,再将日志写到文件(或者同步到磁盘)中。
  117. # 可以通过innodb_log_buffer_size参数设置其可以使用的最大内存空间。
  118. # 默认是8MB,一般为16~64MB即可。
  119. innodb_log_buffer_size = 8M
  120. # 在日志组中的文件总数
  121. innodb_log_files_in_group = 3
  122. # 这个选项决定着什么时候把日志信息写入日志文件以及什么时候把这些文件物理地写(术语称为”同步”)到硬盘上。
  123. # 设置值0的意思是每隔一秒写一次日 志并进行 同步,这可以减少硬盘写操作次数,但可能造成数据丢失;
  124. # 设置值1(设置设置)的意思是在每执行完一条COMMIT命令就写一次日志并进行同步,这可以防止数据丢失,但硬盘写操作可能会很频繁;
  125. # 设置值2是一般折衷的办法,即每执行完一条COMMIT命令写一次日志,每隔一秒进行一次同步。
  126. innodb_flush_log_at_trx_commit = 1
  127. # SQL语句在被回滚前,InnoDB事务等待InnoDB行锁的时间
  128. # 如果某个事务在等待n秒(s)后还没有获得所需要的资源,就使用ROLLBACK命令放弃这个事务。
  129. # 这项设置对于发现和处理未能被InnoDB数据表驱动 程序识别出来的死锁条件有着重要的意义。这个选项的默认设置是50s。
  130. innodb_lock_wait_timeout = 50
  131. # 慢查询时长
  132. long_query_time = 2
  133. # 将没有使用索引的查询也记录下来
  134. log-queries-not-using-indexes
  135. # 指定服务端默认字符集
  136. character-set-server=utf8mb4
  137. [mysql
  138. dump]
  139. quick
  140. max_allowed_packet = 16M
  141. [mysql
  142. ]
  143. # 指定客户端默认字符集
  144. default-character-set=utf8mb4
  145. # 不适用自动补全
  146. no-auto-rehash
  147. [myisamchk]
  148. key_buffer_size = 64M
  149. sort_buffer_size = 1M
  150. read_buffer = 2M
  151. write_buffer = 2M
  152. [mysql
  153. hotcopy]
  154. interactive-timeout
复制代码
2.8 新增mariadb.service配置文件

  1. cd /usr/lib/systemd/system
  2. vi mariadb.service
复制代码
  1. # It's not recommended to modify this file in-place, because it will be
  2. # overwritten during package upgrades.  If you want to customize, the
  3. # best way is to create a file "/etc/systemd/system/mariadb.service",
  4. # containing
  5. #        .include /usr/lib/systemd/system/mariadb.service
  6. #        ...make your changes here...
  7. # or create a file "/etc/systemd/system/mariadb.service.d/foo.conf",
  8. # which doesn't need to include ".include" call and which will be parsed
  9. # after the file mariadb.service itself is parsed.
  10. #
  11. # For more info about custom unit files, see systemd.unit(5) or
  12. # https://mariadb.com/kb/en/mariadb/systemd/
  13. #
  14. # Copyright notice:
  15. #
  16. # This file is free software; you can redistribute it and/or modify it
  17. # under the terms of the GNU Lesser General Public License as published by
  18. # the Free Software Foundation; either version 2.1 of the License, or
  19. # (at your option) any later version.
  20. [Unit]
  21. Description=MariaDB 11.3.2 database server
  22. Documentation=man:mariadbd(8)
  23. Documentation=https://mariadb.com/kb/en/library/systemd/
  24. After=network.target
  25. [Install]
  26. WantedBy=multi-user.target
  27. [Service]
  28. ##############################################################################
  29. ## Core requirements
  30. ##
  31. Type=notify
  32. # Setting this to true can break replication and the Type=notify settings
  33. # See also bind-address mariadbd option.
  34. PrivateNetwork=false
  35. ##############################################################################
  36. ## Package maintainers
  37. ##
  38. User=mariadb
  39. Group=mariadb
  40. # CAP_IPC_LOCK To allow memlock to be used as non-root user
  41. # CAP_DAC_OVERRIDE To allow auth_pam_tool (which is SUID root) to read /etc/shadow when it's chmod 0
  42. #   does nothing for non-root, not needed if /etc/shadow is u+r
  43. # CAP_AUDIT_WRITE auth_pam_tool needs it on Debian for whatever reason
  44. CapabilityBoundingSet=CAP_IPC_LOCK CAP_DAC_OVERRIDE CAP_AUDIT_WRITE
  45. # PrivateDevices=true implies NoNewPrivileges=true and
  46. # SUID auth_pam_tool suddenly doesn't do setuid anymore
  47. PrivateDevices=false
  48. # Prevent writes to /usr, /boot, and /etc
  49. ProtectSystem=false
  50. # Database dir: '/usr/local/mariadb/data' should be writable even
  51. # ProtectSystem=full prevents it
  52. ReadWritePaths=-/usr/local/data/mariadb
  53. # Doesn't yet work properly with SELinux enabled
  54. # NoNewPrivileges=true
  55. # Prevent accessing /home, /root and /run/user
  56. ProtectHome=false
  57. # Execute pre and post scripts as root, otherwise it does it as User=
  58. PermissionsStartOnly=true
  59. # Perform automatic wsrep recovery. When server is started without wsrep,
  60. # galera_recovery simply returns an empty string. In any case, however,
  61. # the script is not expected to return with a non-zero status.
  62. # It is always safe to unset _WSREP_START_POSITION environment variable.
  63. # Do not panic if galera_recovery script is not available. (MDEV-10538)
  64. ExecStartPre=/bin/sh -c "systemctl unset-environment _WSREP_START_POSITION"
  65. ExecStartPre=/bin/sh -c "[ ! -e /usr/local/mariadb/bin/galera_recovery ] && VAR= || \
  66. VAR=`cd /usr/local/mariadb/bin/..; /usr/local/mariadb/bin/galera_recovery`; [ $? -eq 0 ] \
  67. && systemctl set-environment _WSREP_START_POSITION=$VAR || exit 1"
  68. # Needed to create system tables etc.
  69. # ExecStartPre=/usr/local/mariadb/scripts/mysql
  70. _install_db -u mariadb
  71. # Start main service
  72. # MYSQLD_OPTS here is for users to set in /etc/systemd/system/mariadb.service.d/MY_SPECIAL.conf
  73. # Use the [Service] section and Environment="MYSQLD_OPTS=...".
  74. # This isn't a replacement for my.cnf.
  75. # _WSREP_NEW_CLUSTER is for the exclusive use of the script galera_new_cluster
  76. ExecStart=/usr/local/mariadb/bin/mariadbd $MYSQLD_OPTS $_WSREP_NEW_CLUSTER $_WSREP_START_POSITION
  77. # Unset _WSREP_START_POSITION environment variable.
  78. ExecStartPost=/bin/sh -c "systemctl unset-environment _WSREP_START_POSITION"
  79. KillSignal=SIGTERM
  80. # Don't want to see an automated SIGKILL ever
  81. SendSIGKILL=no
  82. # Restart crashed server only, on-failure would also restart, for example, when
  83. # my.cnf contains unknown option
  84. Restart=on-abort
  85. RestartSec=5s
  86. UMask=007
  87. ##############################################################################
  88. ## USERs can override
  89. ##
  90. ##
  91. ## by creating a file in /etc/systemd/system/mariadb.service.d/MY_SPECIAL.conf
  92. ## and adding/setting the following under [Service] will override this file's
  93. ## settings.
  94. # Useful options not previously available in [mysql
  95. d_safe]
  96. # Kernels like killing mariadbd when out of memory because its big.
  97. # Lets temper that preference a little.
  98. # OOMScoreAdjust=-600
  99. # Explicitly start with high IO priority
  100. # BlockIOWeight=1000
  101. # If you don't use the /tmp directory for SELECT ... OUTFILE and
  102. # LOAD DATA INFILE you can enable PrivateTmp=true for a little more security.
  103. PrivateTmp=false
  104. # Set an explicit Start and Stop timeout of 900 seconds (15 minutes!)
  105. # this is the same value as used in SysV init scripts in the past
  106. # Galera might need a longer timeout, check the KB if you want to change this:
  107. # https://mariadb.com/kb/en/library/systemd/#configuring-the-systemd-service-timeout
  108. TimeoutStartSec=900
  109. TimeoutStopSec=900
  110. # Set the maximium number of tasks (threads) to 99% of what the system can
  111. # handle as set by the kernel, reserve the 1% for a remote ssh connection,
  112. # some monitoring, or that backup cron job. Without the directive this would
  113. # be 15% (see DefaultTasksMax in systemd man pages).
  114. TasksMax=99%
  115. ##
  116. ## Options previously available to be set via [mysql
  117. d_safe]
  118. ## that now needs to be set by systemd config files as mysql
  119. d_safe
  120. ## isn't executed.
  121. ##
  122. # Number of files limit. previously [mysql
  123. d_safe] open-files-limit
  124. LimitNOFILE=32768
  125. # Maximium core size. previously [mysql
  126. d_safe] core-file-size
  127. # LimitCore=
  128. # Nice priority. previously [mysql
  129. d_safe] nice
  130. # Nice=-5
  131. # Timezone. previously [mysql
  132. d_safe] timezone
  133. # Environment="TZ=UTC"
  134. # Library substitutions. previously [mysql
  135. d_safe] malloc-lib with explicit paths
  136. # (in LD_LIBRARY_PATH) and library name (in LD_PRELOAD).
  137. # Environment="LD_LIBRARY_PATH=/path1 /path2" "LD_PRELOAD=
  138. # Flush caches. previously [mysql
  139. d_safe] flush-caches=1
  140. # ExecStartPre=sync
  141. # ExecStartPre=sysctl -q -w vm.drop_caches=3
  142. # numa-interleave=1 equalivant
  143. # Change ExecStart=numactl --interleave=all /usr/local/mariadb/bin/mariadbd......
  144. # crash-script equalivent
  145. # FailureAction=
复制代码
 不修改会报错

报错详情:详细信息看
2.9 启动服务

  1. systemctl daemon-reload
  2. systemctl enable mariadb.service
  3. systemctl start mariadb.service
  4. systemctl status mariadb.service
复制代码
 systemctl enable mariadb.service 实行后,会出现提示.我是已经实行过一次了.

2.10 配置环境变量

  1. vi /etc/profile
复制代码
 添加
  1. export PATH=$PATH:/usr/local/mariadb/bin
复制代码

 配置立刻生效
  1. source /etc/profile
复制代码
3 mysql
测试和配置


3.1 测试毗连(未配置密码)

  1. mysql
复制代码

  1. [root@localhost ~]# mysql
  2. 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
  3.               || 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
数据库


  1. use mysql
  2. ;
复制代码
  1. [root@localhost ~]# mysql
  2. 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
  3. ;Database changedMariaDB [mysql
  4. ]>
复制代码
3.3 为root用户设置密码

  1. MariaDB [(none)]> use mysql
  2. ;Database changedMariaDB [mysql
  3. ]> set password for root@localhost=password('123456');Query OK, 0 rows affected (0.00 sec)MariaDB [mysql
  4. ]> select user,host,password from mysql
  5. .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
  6. ]>
复制代码
3.4 测试账号密码

  1. mysql
  2. -uroot -p
复制代码
3.5 设置外部毗连访问

 利用数据库工具访问失败,因为没有配置外部访问;

 进入数据库
 设置mysql
允许外部毗连访问(授权):
  1. //授权
  2. grant all privileges on *.* to root@'%' identified by '123456' with grant option;
  3. //刷新
  4. flush privileges;
复制代码
 指定ip地址授权(毗连时失败报错1130弹出的地址)
  1. grant all privileges on *.* to root@'ip地址' identified by '密码' with grant option;
  2. flush privileges;
复制代码
  1. [root@localhost ~]# mysql
  2. -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
  3. ;Database changedMariaDB [mysql
  4. ]> 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
  5. ]> grant all privileges on *.* to root@'%' identified by '123456' with grant option;Query OK, 0 rows affected (0.00 sec)MariaDB [mysql
  6. ]> flush privileges;Query OK, 0 rows affected (0.00 sec)MariaDB [mysql
  7. ]>
复制代码
 毗连成功

六、MariaDB主从复制

1 主从赋值前必要注意事项

  1. 1. 主从复制肯定需要一主一从了,两个数据库先装好
  2. 2. 虽然不强制,但是尽量两台数据库的密码相同
  3. 3. 下面就使用A和B数据库来代替,A是主B是从
复制代码
2 开始举行主从同步操作

2.1 修改配置文件

A和B数据库都举行修改,没有的话就添加
  1. # 服务器id,即唯一id,推荐使用ip的最后一节(主从不一样)
  2. server-id = 161
  3. # 该值为整个结构中服务器的总数(主从一样)
  4. auto-increment-increment = 2
  5. # 避免主键冲突,主从服务器需要设置不同的值(主从不一样)
  6. auto-increment-offset = 1
复制代码
2.2 防火墙设置

A:(192.168.200.161)
  1. firewall-cmd --permanent --add-rich-rule 'rule family=ipv4 source address= 192.168.200.162 port port=3306 protocol=tcp accept'
  2. firewall-cmd --reload
复制代码
B:(192.168.200.162)
  1. firewall-cmd --permanent --add-rich-rule 'rule family=ipv4 source address= 192.168.200.161 port port=3306 protocol=tcp accept'
  2. firewall-cmd --reload
复制代码
2.3 创建同步所需的用户

A:(192.168.200.161)
  1. # mysql
  2. -uroot -p123456grant replication slave on *.* to copy1@192.168.200.162 identified by '123456';
复制代码
B:(192.168.200.162)
  1. # mysql
  2. -uroot -p123456grant replication slave on *.* to copy2@192.168.200.161 identified by '123456';
复制代码
2.4 配置同步

A:(192.168.200.161)
  1. MariaDB [(none)]> show master status; 记录下A的File和Position| mysql
  2. -bin.000003 |      562 |              |                  |
复制代码
B:(192.168.200.162)
  1. MariaDB [(none)]> show master status; 记录下B的File和Position| mysql
  2. -bin.000005 |      546 |              |                  |
复制代码
A:(192.168.200.161)
  1. change master to master_host='192.168.200.162',master_user='copy2',master_password='123456',master_log_file='mysql
  2. -bin.000005',master_log_pos=546,master_port=3306;start slave;
复制代码
B:(192.168.200.162)
  1. change master to master_host='192.168.200.161', master_user='copy1',master_password='123456',master_log_file='mysql
  2. -bin.000003',master_log_pos=562 ,master_port=3306;start slave;
复制代码
最后查看是否成功:
  1. show slave status\G
复制代码
看到这样就是成功了

3 查抄报错(出现问题时利用)

  1. MariaDB [(none)]> stop slave;
  2. MariaDB [(none)]> reset slave;
  3. MariaDB [(none)]> flush logs;
  4. MariaDB [(none)]> show master status;
  5. 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企服之家,中国第一个企服评测及商务社交产业平台。




欢迎光临 ToB企服应用市场:ToB评测及商务社交产业平台 (https://dis.qidao123.com/) Powered by Discuz! X3.4