通过以下练习可以掌握 OceanBase 集群的手动部署技能,理解进程的相关目录、集群初始化、OBProxy和 OB 集群关系等。
服务器规划
IP | 角色 | 用途 | 服务器规格 |
---|
192.168.79.200 | OBD、OBPROXY、OBCLIENT | 中控机自动化部署软件、访问反向代理、命令行客户端 | 8C4G CentOS7.9 | 192.168.79.201 | observer | OceanBase数据库zone1 | 8C12G CentOS7.9 | 192.168.79.202 | observer | OceanBase数据库zone2 | 8C12G CentOS7.9 | 192.168.79.203 | observer | OceanBase数据库zone3 | 8C12G CentOS7.9 |
1、服务器环境准备
1.1 hosts配置
cat >> /etc/hosts << EOF
192.168.79.200 obproxy
192.168.79.201 observer01
192.168.79.202 observer02
192.168.79.203 observer03
EOF
1.2 内核参数修改
cat >> /etc/sysctl.conf << EOF
net.core.somaxconn = 2048
net.core.netdev_max_backlog = 10000
net.core.rmem_default = 16777216
net.core.wmem_default = 16777216
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.ipv4.ip_local_port_range = 3500 65535
net.ipv4.ip_forward = 0
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
net.ipv4.tcp_syncookies = 0
net.ipv4.tcp_rmem = 4096 87380 16777216
net.ipv4.tcp_wmem = 4096 65536 16777216
net.ipv4.tcp_max_syn_backlog = 16384
net.ipv4.tcp_fin_timeout = 15
net.ipv4.tcp_max_syn_backlog = 16384
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_slow_start_after_idle=0
vm.swappiness = 0
vm.min_free_kbytes = 2097152
vm.max_map_count=655360
fs.aio-max-nr=1048576
EOF
sysctl -p
1.3 修改会话变量设置
cat >> /etc/security/limits.conf << EOF
* soft nofile 655360
* hard nofile 655360
* soft nproc 655360
* hard nproc 655360
* soft core unlimited
* hard core unlimited
* soft stack unlimited
* hard stack unlimited
EOF
ulimit -a
1.4 关闭防火墙和 SELinux
systemctl disable firewalld
systemctl stop firewalld
systemctl status firewalld
1.5 关闭 SELinux
getenforce
cat /etc/selinux/config
sed -i '/^SELINUX=.*/ s//SELINUX=disabled/' /etc/selinux/config
cat /etc/selinux/config
setenforce 0
1.6 配置时间同步服务
timedatectl status
timedatectl set-timezone "Asia/ShangHai"
timedatectl set-time '2020-09-12 09:30:00'
chronyc -a makestep
yum -y install chrony
systemctl start chronyd
systemctl status chronyd
vi /etc/chrony.conf
server 192.168.79.200
driftfile /var/lib/chrony/drift
makestep 1.0 3
rtcsync
allow 192.168.79.0/24
local stratum 10
logdir /var/log/chrony
--常用命令
chronyc activity
chronyc sources
chronyc sources -v
chronyc tracking
ping -T tsandaddr 192.168.79.200 -c 2
1.7 创建安装用户
useradd admin
passwd admin
echo 'admin:admin' | chpasswd
在 CentOS 上面给 admin 用户增加 sodu 权限有以下两个方法:
把用户加到 用户组 wheel里。
把用户加到 /etc/sudoers 文件里。
yum install -y sudo
admin 加到用户组 wheel 里。
usermod admin -G wheel
id admin
admin 添加到 /etc/sudoers 文件中
cat /etc/sudoers |grep wheel
%wheel ALL=(ALL) ALL
vi /etc/sudoers
admin ALL=(ALL) ALL
验证方法是否生效,您切换到 admin 用户下,执行命令:sudo date 。输入密码后查看返回结果。
1.8 配置 SSH 免密登录(可选)
--我使用rac的脚本sshUserSetup.sh
/soft/sshUserSetup.sh -user admin -hosts "observer01 observer02 observer03 obproxy" -advanced -exverify -confirm
1.9 磁盘目录划分
pvcreate /dev/sdd /dev/sde
vgcreate vg_data /dev/sdd
vgcreate vg_log /dev/sde
lvcreate -n lv_data -L 200000M vg_data
lvcreate -n lv_log -L 200000M vg_log
mkfs.xfs /dev/vg_data/lv_data
mkfs.xfs /dev/vg_log/lv_log
echo "/dev/vg_data/lv_data /data xfs defaults 0 0" >> /etc/fstab
echo "/dev/vg_log/lv_log /redo xfs defaults 0 0" >> /etc/fstab
cat /etc/fstab
mkdir /data
mkdir /redo
chown admin:admin /data
chown admin:admin /redo
2、安装部署OceanBase
2.1安装 OceanBase 软件包
所有server节点安装OceanBase软件包
su - admin
sudo rpm -ivh /soft/oceanbase-ce-*.rpm
or:
sudo rpm -ivh /soft/oceanbase-ce-libs-3.1.2-10000392021123010.el7.x86_64.rpm
sudo rpm -ivh /soft/oceanbase-ce-3.1.2-10000392021123010.el7.x86_64.rpm
tree oceanbase
echo 'export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:~/oceanbase/lib' >> ~/.bash_profile
source ~/.bash_profile
以节点observer01为例,其他节点操作一样:
2.2 初始化数据目录(所有server节点)
su - root
chown -R admin:admin /home/admin/oceanbase
ls -ld /home/admin/oceanbase
su - admin
mkdir -p ~/oceanbase/store/myob /data/myob/{sstable,etc3} /redo/myob/{clog,ilog,slog,etc2}
for f in {clog,ilog,slog,etc2}; do ln -s /redo/myob/$f ~/oceanbase/store/myob/$f ; done
for f in {sstable,etc3}; do ln -s /data/myob/$f ~/oceanbase/store/myob/$f; done
tree ~/oceanbase/store/ /data/ /redo/
以节点observer01为例,其他节点操作一样:
2.3 启动OBSERVER进程
--201
su - admin
cd ~/oceanbase/store && ~/oceanbase/bin/observer -i ens33 -p 2881 -P 2882 -z zone1 -d ~/oceanbase/store/myob -r '192.168.79.201:2882:2881;192.168.79.202:2882:2881;192.168.79.203:2882:2881' -c 20220120 -n myob -o "memory_limit=8G,cache_wash_threshold=1G,__min_full_resource_pool_memory=268435456,system_memory=3G,memory_chunk_cache_size=128M,cpu_count=8,net_thread_count=4,datafile_size=5G,stack_size=1536K,enable_separate_sys_clog=0,enable_merge_by_turn=False,enable_syslog_wf=False,enable_syslog_recycle=True,max_syslog_file_count=4,config_additional_dir=/data/myob/etc3;/data/myob/etc2" -d ~/oceanbase/store/myob -l ERROR
--203
su - admin
cd ~/oceanbase/store && ~/oceanbase/bin/observer -i ens33 -p 2881 -P 2882 -z zone2 -d ~/oceanbase/store/myob -r '192.168.79.201:2882:2881;192.168.79.202:2882:2881;192.168.79.203:2882:2881' -c 20220120 -n myob -o "memory_limit=8G,cache_wash_threshold=1G,__min_full_resource_pool_memory=268435456,system_memory=3G,memory_chunk_cache_size=128M,cpu_count=8,net_thread_count=4,datafile_size=5G,stack_size=1536K,enable_separate_sys_clog=0,enable_merge_by_turn=False,enable_syslog_wf=False,enable_syslog_recycle=True,max_syslog_file_count=4,config_additional_dir=/data/myob/etc3;/data/myob/etc2" -d ~/oceanbase/store/myob -l ERROR
--203
su - admin
cd ~/oceanbase/store && ~/oceanbase/bin/observer -i ens33 -p 2881 -P 2882 -z zone3 -d ~/oceanbase/store/myob -r '192.168.79.201:2882:2881;192.168.79.202:2882:2881;192.168.79.203:2882:2881' -c 20220120 -n myob -o "memory_limit=8G,cache_wash_threshold=1G,__min_full_resource_pool_memory=268435456,system_memory=3G,memory_chunk_cache_size=128M,cpu_count=8,net_thread_count=4,datafile_size=5G,stack_size=1536K,enable_separate_sys_clog=0,enable_merge_by_turn=False,enable_syslog_wf=False,enable_syslog_recycle=True,max_syslog_file_count=4,config_additional_dir=/data/myob/etc3;/data/myob/etc2" -d ~/oceanbase/store/myob -l ERROR
IPS="192.168.79.201 192.168.79.202 192.168.79.203"
for ob in $IPS;do echo $ob; ssh $ob "sudo netstat -ntlp|grep ob"; done
for ob in $IPS;do echo $ob; ssh $ob "ps -ef|grep ob |grep -v grep"; done
2.4 集群初始化(bootstrap)
OceanBase集群三个节点都正常启动,并且监听正常时,可连接到任一节点(通过 2881 端口直连),进行自举(bootstrap 集群初始化)操作。
mysql -h 192.168.79.201 -u root -P 2881 -p -c -A
set session ob_query_timeout=1000000000; alter system bootstrap ZONE 'zone1' SERVER '192.168.79.201:2882',ZONE 'zone2' SERVER '192.168.79.202:2882',ZONE 'zone3' SERVER '192.168.79.203:2882';
exit
mysql -h 192.168.79.201 -u root@sys -P 2881 -p -c -A
show databases;
2.5 设置相关密码
默认集群管理员(root@sys)的密码为空,这里需要设置一个密码。
alter user root identified by 'Adm1234' ;
默认 OBPROXY 连接 OceanBase 集群时使用用户 proxyro 。该用户不存在,需要手动创建。
create user proxyro identified by 'Proxyro1234';
grant select on oceanbase.* to proxyro;
2.6 安装 OBPROXY 软件包
--200
su - admin
sudo rpm -ivh /soft/obproxy-3.2.0-1.el7.x86_64.rpm
tree ~/obproxy-3.2.0/
2.7 启动 OBPROXY 进程
cd ~/obproxy-3.2.0/ && bin/obproxy -r "192.168.79.201:2881;192.168.79.202:2881;192.168.79.203:2881" -p 2883 -o "enable_strict_kernel_release=false,enable_cluster_checkout=false,enable_metadb_used=false" -c myob
netstat -ntlp | grep obproxy
ps -ef|grep obproxy |grep -v grep
mysql -h 192.168.79.200 -u root@proxysys -P 2883 -p
show proxyconfig like '%sys_password%';
alter proxyconfig set obproxy_sys_password='Proxysys1234';
show proxyconfig like '%sys_password%';
show proxyconfig like '%sys_password%';
alter proxyconfig set observer_sys_password='Proxyro1234';
show proxyconfig like '%sys_password%';
通过 OBPROXY 连接 OceanBase 集群进行检查确认
mysql -h192.168.79.200 -uroot@sys
select * from oceanbase.__all_server;
show full processlist;
select a.zone,concat(a.svr_ip,':',a.svr_port) observer, cpu_total, (cpu_total-cpu_assigned) cpu_free, round(mem_total/1024/1024/1024) mem_total_gb, round((mem_total-mem_assigned)/1024/1024/1024) mem_free_gb, usec_to_time(b.last_offline_time) last_offline_time, usec_to_time(b.start_service_time) start_service_time, b.status, usec_to_time(b.stop_time) stop_time, b.build_version from __all_virtual_server_stat a join __all_server b on (a.svr_ip=b.svr_ip and a.svr_port=b.svr_port) order by a.zone, a.svr_ip;
select t1.name resource_pool_name, t2.`name` unit_config_name, t2.max_cpu, t2.min_cpu, t2.max_memory/1024/1024/1024 max_mem_gb, t2.min_memory/1024/1024/1024 min_mem_gb, t3.unit_id, t3.zone, concat(t3.svr_ip,':',t3.`svr_port`) observer,t4.tenant_id, t4.tenant_name from __all_resource_pool t1 join __all_unit_config t2 on (t1.unit_config_id=t2.unit_config_id) join __all_unit t3 on (t1.`resource_pool_id` = t3.`resource_pool_id`) left join __all_tenant t4 on (t1.tenant_id=t4.tenant_id) order by t1.`resource_pool_id`,t2.`unit_config_id`,t3.unit_id;
2.8 登录ob数据库并创建租户
mysql -h192.168.79.200 -uroot@sys
CREATE resource unit S2C1G max_cpu=2, min_cpu=2, max_memory='1G', min_memory='1G', max_iops=10000, min_iops=1000, max_session_num=1000000, max_disk_size='1024G';
CREATE resource pool my_pool unit = 'S2C1G', unit_num = 1;
create tenant myoadb resource_pool_list=('my_pool'), primary_zone='RANDOM',comment 'mysql tenant/instance', charset='utf8' set ob_tcp_invited_nodes='%', ob_compatibility_mode='mysql';
ERROR 4624 (HY000): machine resource 'zone1' is not enough to hold a new unit
调整小系统租户资源,再进行创建
alter resource unit sys_unit_config max_cpu=1,min_cpu=1;
2.9 登录myoadb tenant并创建数据库及表等
mysql -uroot@myoadb -p -h192.168.79.200 -P2883
mysql -h192.168.79.200 -uroot@myoadb
show databases;
create database oadb;
use oadb;
create table obtabtest01 (id int(10),name varchar(100));
show tables;
insert into obtabtest01 values(1,'张三');
insert into obtabtest01 values(1,'李四');
insert into obtabtest01 values(1,'王五');
commit;
select * from obtabtest01;
相关连接: https://open.oceanbase.com/answer/detail?id=13700696
|