阿里oceanbase数据库安装步骤-linux

阿里oceanbase数据库有兼容mysql、oracle模式选择,有社区版和企业版,可以配置单机运行,也可以配置为cluster群集灵活增减电脑。

看着还是不错的啊。

安装:

  https://www.oceanbase.com/docs/common-oceanbase-database-cn-1000000000639587

  配置群集:https://www.oceanbase.com/docs/common-oceanbase-database-cn-1000000000640298

  我用的单机部署,比较简单:下载,解压缩 ,几个命令就完成了:   

下载地址:  https://www.oceanbase.com/softwarecenter  ,然后参考资料:

https://www.oceanbase.com/docs/common-oceanbase-database-cn-1000000000639587

 

步骤一:下载并安装 all-in-one 安装包

  1. 下载 all-in-one 安装包,并将其上传到机器任一目录下。

    • 企业版:请联系技术支持获取 all-in-one 安装包。

    • 社区版:请从 OceanBase 软件下载中心 下载 all-in-one 安装包,建议下载最新版本。

    •  

  2. 在安装包所在目录下执行如下命令解压安装包并安装。

  3. 运行命令:
tar -xzf oceanbase-all-in-one-*.tar.gz
cd oceanbase-all-in-one/bin/
./install.sh
source ~/.oceanbase-all-in-one/bin/env.sh

        如果要单独安装rpm包,可以下载后单独安装,在oceanbase-all-in-one压缩包解压缩开文件夹里也有。

        如果用了ubuntu之类不支持rpm的,可以安装alien: 

apt-get install alien

  如果安装alien提示版本交叉引用低版本错误,可以运行这个,会给出几个选择,降级版本之类,最终能安装上alien和rpm:

aptitude install alien

  

  4.启动:

obd demo

        然后设置用户可以访问权限,要不别的电脑连不进来:

grant all privileges on *.* to root@'%';

  

  5.设置自动启动:

        如果想手工启动,可以运行这个:obd cluster start demo或者obd cluster stop demo,查看信息:obd cluster display demo。查看帮助:obd cluster --help

root@haihong-PC:/etc/init.d# obd cluster start demo
Get local repositories ok
Search plugins ok
Load cluster param plugin ok
Open ssh connection ok
Check before start observer ok
[WARN] OBD-1011: (127.0.0.1) The recommended value of fs.aio-max-nr is 1048576 (Current value: 65536)
[WARN] (127.0.0.1) failed to get open files
[WARN] (127.0.0.1) failed to get max user processes
[WARN] (127.0.0.1) failed to get core file size
[WARN] (127.0.0.1) failed to get stack size
[WARN] OBD-1017: (127.0.0.1) The value of the "vm.max_map_count" must be within [327600, 1310720] (Current value: 65530, Recommended value: 655360)

Check before start obagent ok
Check before start obproxy ok
Check before start prometheus ok
Check before start grafana ok
Start observer ok
observer program health check ok
obshell program health check ok
Connect to observer 127.0.0.1:2881 ok
Start obagent ok
obagent program health check ok
Connect to Obagent ok
Start obproxy ok
obproxy program health check ok
Connect to obproxy ok
Initialize obproxy-ce ok
Start promethues ok
prometheus program health check ok
Connect to Prometheus ok
Initialize prometheus ok
Start grafana ok
grafana program health check ok
Connect to grafana ok
Initialize grafana ok
Wait for observer init ok
+---------------------------------------------+
|                   observer                  |
+-----------+---------+------+-------+--------+
| ip        | version | port | zone  | status |
+-----------+---------+------+-------+--------+
| 127.0.0.1 | 4.3.0.1 | 2881 | zone1 | ACTIVE |
+-----------+---------+------+-------+--------+
obclient -h127.0.0.1 -P2881 -uroot -Doceanbase -A        注意这一行,obclient是连接oceanbase的命令行工具

+------------------------------------------------------------------+
|                             obagent                              |
+---------------+--------------------+--------------------+--------+
| ip            | mgragent_http_port | monagent_http_port | status |
+---------------+--------------------+--------------------+--------+
| 192.168.88.69 | 8089               | 8088               | active |
+---------------+--------------------+--------------------+--------+
+---------------------------------------------+
|                   obproxy                   |
+-----------+------+-----------------+--------+
| ip        | port | prometheus_port | status |
+-----------+------+-----------------+--------+
| 127.0.0.1 | 2883 | 2884            | active |
+-----------+------+-----------------+--------+
obclient -h127.0.0.1 -P2883 -uroot -Doceanbase -A         

+------------------------------------------------------+
|                      prometheus                      |
+---------------------------+------+----------+--------+
| url                       | user | password | status |
+---------------------------+------+----------+--------+
| http://192.168.88.69:9090 |      |          | active |
+---------------------------+------+----------+--------+
+---------------------------------------------------------------------+
|                               grafana                               |这个服务可以用,默认密码在下面写着。是oceanbase的运行流量监控。
+---------------------------------------+-------+------------+--------+
| url                                   | user  | password   | status |
+---------------------------------------+-------+------------+--------+
| http://192.168.88.69:3000/d/oceanbase | admin | ybBlPYLo7c | active |注意这里的用户名和密码
+---------------------------------------+-------+------------+--------+
demo running
Trace ID: 35a77ea8-ffc5-11ee-b55e-74d4359c7e4c
If you want to view detailed obd logs, please run: obd display-trace 35a77ea8-ffc5-11ee-b55e-74d4359c7e4c
root@haihong-PC:/etc/init.d# 

           这就算是安装完了。

          如果想配置群集,可以打开web配置:

root@haihong-PC:/etc/init.d# obd web
start OBD WEB in 0.0.0.0:8680
please open http://192.168.88.69:8680

           打开这个网址出来配置cluster的页面。

 

 

 

 

下一步,配置oceanbase数据库自动启动:

         1、放在用户登录后的启动里~/.profile ,这种方式命令行登录后可以正常启动oceanbase,但是图形界面不行。

vi ~/.profile

   或者vi /home/haihong/.profile,在文件末尾加上一行:

obd cluster start demo

            这样在命令行终端登录时会启动的很正常。但是图形界面加载不了。

 

            2、深度linux图形界面启动后即可加载的用法:

                2.1、创建一个sh文件:

vi /home/haihong/Downloads/obdrun.sh

                文件内容:

#!/bin/bash

/home/haihong/.oceanbase-all-in-one/obd/usr/bin/obd cluster start demo

                 然后+x运行权限:

chmod +x /home/haihong/Downloads/obdrun.sh

                 2.2、加到crontab -e里:

                        crontab相当于windows的定时任务,支持重启时加载。注意,每个用户都可以运行这个命令,相当于各自启动的东西不一样。运行:

crontab -e

                      在文件最后加上一行,在reboot时调用上面的文件:

@reboot /home/haihong/Downloads/obdrun.sh

 

 

            曾经考虑把这行命令放到linux的自动启动里,没搞定。捎带提一下linux启动的3种常用模式,

            参考:https://www.cnblogs.com/comprehensive/p/12096448.html

   3、新建 /usr/share/applications/oceanbase.desktop 快捷方式,然后设置成自动启动:

pluma /usr/share/applications/oceanbase.desktop

              文件内容从QQ.desktop文件复制过来改的,主要是下面红色这行:

[Desktop Entry]
Encoding=UTF-8
Name=oceanbase
Comment=start-ocean-base
Exec=/home/haihong/.oceanbase-all-in-one/obd/usr/bin/obd cluster start demo
Terminal=false
Type=Application
Categories=Application;Network;Tencent Software;
StartupNotify=true
Name[zh_CN]=oceanbase
GenericName[zh_CN]=
Comment[zh_CN]=start-ocean-base

           打开设置-》应用-》开机启动,添加上这个oceanbase.desktop文件。

              完成。

 

             4、放到rc.local文件里。

#!/bin/bash

#启动网站:
#/home/dotnet-sdk/dotnet /home/haihong/Downloads/学习EF/学习EF.dll
#启动数据库 obd cluster start demo exit 0

      发现效果不好,ctrl+f5切换别的终端时出错,速度特别慢。

             5、放到/etc/profile.d/文件夹里

             6、放到/etc/init.d/文件夹里。

                vim ocean.sh创建文件,然后别忘了chmod +x ocean.sh或者chmod 777 ocean.sh

#!/bin/bash

### BEGIN INIT INFO
# Provides: ocean
# Required-Start: 
# Required-Stop: 
# Default-Start: 2 3 4 5
# Default-Stop: 1
# Description: oceanbase 
### END INIT INFO

case "$1" in
    start)
        echo hello, ocean base is startting
         obd cluster start demo
        ;;
    stop)
         echo ocean base is stopping...
         obd cluster stop demo
        pkill -f "sleep 5000"
        ;;
esac

      执行chkconfig --add ocean.sh时总是报错:

root@haihong-PC:/etc/init.d# chkconfig --add ocean.sh
insserv: FATAL: service mountkernfs has to exists for service udev
insserv: FATAL: service checkroot has to exists for service cryptdisks
insserv: FATAL: service urandom has to exists for service networking
insserv: FATAL: service mountdevsubfs has to exists for service lvm2
insserv: exiting now!
/sbin/insserv failed, exit code 1
ocean.sh                  0:off  1:off  2:off  3:off  4:off  5:off  6:off

            哪位高手有办法解决,请留言指教。

            上述3个办法都不理想,于是尝试了阿里官方文档提供的办法,配置为服务:

           7、自己做一个服务:参考:https://ask.oceanbase.com/t/topic/35605342/2

vi /etc/systemd/system/oceanbase.service

              文件内容如下:

[Unit]
Description=oceanbase
After=network.target
[Service]
Type=forking
User=root
ExecStart=/home/haihong/.oceanbase-all-in-one/obd/usr/bin/obd cluster start demo
ExecStop=/home/haihong/.oceanbase-all-in-one/obd/usr/bin/obd cluster stop demo
ExecReload=/home/haihong/.oceanbase-all-in-one/obd/usr/bin/obd cluster restart demo
LimitNOFILE=165535
LimitNPROC=165535
[Install]
WantedBy=multi-user.target

                上面的WantedBy可以用 WantedBy=graphical.target,after也可以用After=graphical.target。

                 然后设置服务自动启动:

systemctl enable oceanbase

                  这种方式可以调出来obd运行,但是运行中报错import connect faile。然后有个什么exit-code错误。 

         8、再就是可以安装配置为服务(阿里官方提供,此方法效果也很不稳定):

  https://open.oceanbase.com/quicksearch?q=%E5%BC%80%E6%9C%BA%E8%87%AA%E5%8A%A8%E5%90%AF%E5%8A%A8

  https://www.oceanbase.com/docs/common-oceanbase-database-cn-1000000000684621

         有时间研究一下怎么自己做linux服务。

        主要是下载运行了命令:

sudo bash -c "$(curl -s https://obbusiness-private.oss-cn-shanghai.aliyuncs.com/download-center/opensource/obshell/service_installer.sh)"

  执行时会提示输入路径,在文件中搜[bin/obshell],搜到后输入:/data/root/oceanbase-ce  ,他会拼接后缀上/bin/obshell,也就是运行obshell命令的路径。

     完成后提示服务oceanbase配置完毕,设置成自动启动就行了。

 如果不能上网,就把他那个文件下载下来,存成sh文件执行。

启动服务和配置为自动启动:

root@haihong-PC:/etc# systemctl start observer
root@haihong-PC:/etc# systemctl enable observer

 

 

        

 

 

启动起来后,用navicat查看效果:

 

 新建了两个表测试一下。

 

    用netcore新建了个项目连一下:

          appsettings.json里设置连接:

{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Warning"
    }
  },
  "AllowedHosts": "*",
  //"urls": "http://*:88",
  "ConnectionStrings": {
    "default": "Provider=SQLOLEDB.1;Data Source=.;Initial Catalog=fengjun;User ID=sa;Password=666666;persist security info=True;trustservercertificate=True;MultipleActiveResultSets=True;App=EntityFramework;",
    "oceanbase": "Server=192.168.88.69;Port=2881;Database=test;Uid=root;Pwd=;",
    "fengjun": "Provider=SQLOLEDB.1;Data Source=.;Initial Catalog=erp6;User ID=sa;Password=666666;persist security info=True;trustservercertificate=True;MultipleActiveResultSets=True;App=EntityFramework;",
    "oracle": "Provider=OraOLEDB.Oracle.1;User ID=用户名;Password=密码;Data Source=(DESCRIPTION = (ADDRESS_LIST= (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.88.3)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = MyShuJuKuFuWu)))",
    "mysql": "Server=localhost;Port=3306;Database=manageplat;Uid=root;Pwd=666666;"
  }


}

 

新建EntityFramework实体类:

public class Company
{
    [Key]
    public string sID { get; set; } = "";
    public string sName { get; set; } = "";

}

在index.html.cs页面中加入代码尝试增加、查询:

public void OnGet()
{
    using (OceanBaseContext dbEntity =new OceanBaseContext())
    {
        //新增一行数据
        var row=new Company();
        row.sID = DateTime.Now.ToString("yyyyMMdd_HHmmss");
        row.sName = "客户" + dbEntity.company.Count();
        dbEntity.company.Add(row);
        dbEntity.SaveChanges();
        //
        companies = dbEntity.company.ToList();
    }
}

然后html中:

<table style="border:dotted">
    <tr>
        <td>编号</td>
        <td>名称</td>
    </tr>
    @foreach (var itm in Model.companies)
    {
        <tr>
            <td>@itm.sID</td>
            <td>@itm.sName</td>
        </tr>
    }
</table>

跑起来看看效果:

 

 

奇怪的权限问题,先备注着:图形界面haihong用户登录后发现没启动起来,但是命令行启动起来了:

1、方法1:别切换到root,就用haihong执行创建服务的命令:

sudo bash -c "$(curl -s https://obbusiness-private.oss-cn-shanghai.aliyuncs.com/download-center/opensource/obshell/service_installer.sh)"

2、方法2:用root后,授权/root/.oceanbase-all-in-one给haihong:

chmod 777 .oceanbase-all-in-one/ -R

如有必要,授权/data/root/oceanbase-ce: 

chmod 777 /data/root/oceanbase-ce -R

 

 

深度linux常用的配置命令:

新安装完 之后,启用root和密码:

    右键桌面->终端:sudo passwd   然后输入新的root的密码。

    切换为root:su

删除:rm,循环递归删除:rm -r

授权执行:chmod +x 文件夹或者文件

全部授权:chmod 777 文件或者文件

查看当前运行的进程:ps -ef     可以加过滤,比如查看包含ob的当前运行的进程: ps -ef | grep ob

服务启动:service ssh start   或者 service ssh stop ,看状态错误日志:service ssh status

设置服务自动启动或者取消自动启动:

#自动启动
systemctl enable observer
#取消自动启动
systemctl disable observer
#会显示下面结果:
Removed /etc/systemd/system/multi-user.target.wants/observer.service.

 查看文件隐含带属性的:ls -a  查看带权限的:ls -l  ,可以混写:ls -la

 ssh连不过来的修改:参考网址:https://blog.csdn.net/qq_42768347/article/details/108851552

           修改文件:/etc/ssh/sshd_config  ,修改其中PermitRootLogin后的prohibit-password改为yes,如:PermitRootLogin yes

安装几个好用的文本编辑器: 

          apt-get install nano      这个支付复制粘贴,不像vi连基本的复制粘贴都麻烦的不行。 

          apt-get install geany  这个界面很漂亮,比如:geany /etc/ssh/sshd_config 如下图:

genome官方编辑器:gedit: apt-install gedit,界面很好:

 

 

 

前面的几个截图:

运行监控:http://192.168.88.69:3000/d/oceanbase/

 

posted @ 2024-04-21 17:20  海宏软件  阅读(1138)  评论(0编辑  收藏  举报