kboss/docs/deploy/database_server.md
2025-07-16 14:27:17 +08:00

130 lines
2.3 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 数据库服务器部署
数据库服务器部署在192.168.0.69和192.168.0.70上,每台主机需安装如下软件包
```
Mariadb
Ipvsadm
Keepalived
```
## 安装mariadb-server
双机均需要
用root登录
安装和配置数据库
* 安装
```
apt update
apt install mariadb-server
mysql_secure_installaction
```
设置数据库的root用户的密码为Root123
* 停服务
```
systemctl stop mariadb
```
* 将mysql数据库的数据目录复制到/d目录下
```
cp -a /var/lib/mysql /d
```
* 修改或添加 vi /etc/my.cnf, 内容如下
```
[client]
port = 3306
socket = /tmp/maria.sock
[mysqld]
port = 3306
socket = /tmp/maria.sock
skip-external-locking
key_buffer_size = 256M
max_allowed_packet = 1M
table_open_cache = 256
sort_buffer_size = 1M
read_buffer_size = 1M
read_rnd_buffer_size = 4M
myisam_sort_buffer_size = 64M
thread_cache_size = 8
query_cache_size= 16M
thread_concurrency = 4
datadir=/d/mysql
server-id=2
log-bin=mysql-bin
binlog_format=ROW
log-slave-updates
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
[myisamchk]
key_buffer_size = 128M
sort_buffer_size = 128M
read_buffer = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout
```
server-id在两台机器上分别设置为1或2
* 重启mariadb
```
systemctl start mariadb
```
## 安装ipvsadm
```
apt install ipvsadm
```
## 安装keepalived
* 安装
```
apt install keepalived
```
* 配置
在/etc/keepalived目录下添加或修改keepalived.conf
```
! Configuration File for keepalived
global_defs {
notification_email {
root@localhost
ymq@localhost
}
notification_email_from ymq@localhost
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 90
priority 100
advert_int 1
nopreempt
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.0.68
}
}
virtual_server 192.168.1.68 3306 {
delay_loop 6
lb_algo wrr
lb_kind dr
nat_mask 255.255.255.0
persistence_timeout 50
protocol TCP
real_server 192.168.1.70 3306 {
weight 1
notify_down /etc/keepalived/mari.sh #当maridb停止时执行的脚本
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}
```