首页 > 其他分享 >YashanDB一键安装脚本分享

YashanDB一键安装脚本分享

时间:2024-11-08 10:16:24浏览次数:8  
标签:YashanDB NC 一键 openssl echo etc OPENSSL 分享 SIZE

前言

前段时间,yashanDB发布了YashanDB Personal 23.3版本,立马准备安装试试,想着安装后续可能还会有其他版本,本着一劳永逸的想法,写了这个一键安装脚本。后续还有优化空间,这里简单分享记录下脚本安装过程。

环境准备

1. 官网下载最新的个人版安装包: 点击获取YashanDB Personal 23.3版本 2. 一台安装CentOS7的Linux操作系统; 3. 提前下载好openssl 1.1.1以上的包【YashanDB环境要求】, 点此获取openssl; 4. 一键安装脚本:YashanDBInstall

安装演示

1.登录服务器并检查服务器版本以及openssl版本
[root@localhost ~]# cat /etc/centos-release
CentOS Linux release 7.8.2003 (Core)
[root@localhost ~]# openssl version
OpenSSL 1.0.2k-fips  26 Jan 2017
[root@localhost ~]#

2.上传安装包以及安装脚本到服务器并给脚本授权

3.执行脚本一键安装

验证测试

![](/i/ll/?i=img_convert/38f7b37299cea8630a8a5173b52a8215.png)

安装没有问题,脚本可行

回顾总结

1.缺陷:目前仅能支持CentOS一种Linux系统;

2.缺陷:目前仅能安装YashanDB Personal 23.3,此前版本暂不支持(未验证);

3.缺陷:未实现安装日志记录;

后期展望

1.实现YashanDB Personal 23.3之前的版本适配;

2.逐步实现其他常用Linux系统的适配;

3.增加日志记录功能;

4.集成主备部署,集群部署等;

附脚本内容

#!/bin/bash

# 定义颜色
GREEN='\033[0;32m'
BLUE='\033[0;36m'
RED='\033[0;31m'
NC='\033[0m' # No Color

# 打印横幅
echo -e "\n\n\n"
echo -e "**************************************************************************"
echo -e "*                                                                        *"
echo -e "*                     YashanDB Installation Script                       *"
echo -e "*                                                                        *"
echo -e "**************************************************************************"
echo -e "\n\n\n"

# 打印提示性文字
echo -e "Welcome to the YashanDB installation script."
echo -e "This script will guide you through the installation process of YashanDB."
echo -e "This script is currently only installed on CentOS 7 system, and other systems are being adapted."
echo -e "Press Enter to continue..."
read -r


# 定义版本号
VERSION="0.0.2-beta"

OPENSSL_PACKAGE_PATH=""
# 定义默认的传入的参数
USERNAME="yashan"
PASSWORD="yashan"
PORT=1688

OS_IPADDR=$(ip route get 1.1.1.1 | awk '{print $7}')

# 定义执行yashan命令
function run_as_yashan() {
  local command="$1"
  # 检查是否提供了命令
  if [ -z "$command" ]; then
    echo "No command provided"
    return 1
  fi
  # 尝试以 $oracle_user 身份执行命令
  if ! su - $USERNAME -c "$command"; then
    echo "Failed to execute command as $USERNAME"
    return 1
  fi
}

# 定义函数以判断内核类型并关闭透明大页,考虑UEFI和BIOS引导
disable_transparent_huge_pages() {
    os_type=$([ -d /sys/firmware/efi ] && echo "UEFI" || echo "BIOS")
    kernel_type=$(cat /sys${os_type}/kernel/mm/transparent_hugepage/enabled 2>/dev/null || cat /sys/kernel/mm/redhat_transparent_hugepage/enabled)
    if [[ $kernel_type == *"always madvise [never]"* ]]; then
        log "Transparent Huge Pages are already disabled."
    elif [[ $kernel_type == *"always [madvise] never"* ]]; then
        log "Disabling Transparent Huge Pages for Red Hat Enterprise Linux kernel..."
        echo never > /sys${os_type}/kernel/mm/redhat_transparent_hugepage/enabled
    else
        log "Disabling Transparent Huge Pages for other kernels..."
        echo never > /sys${os_type}/kernel/mm/transparent_hugepage/enabled
    fi
}

# 定义函数以计算并配置大页内存
enable_large_pages() {
    # 估算YashanDB所需内存总量UserSize,这里使用默认值进行计算 单位:M
    DATA_BUFFER_SIZE=32
    REDO_BUFFER_SIZE=8
    VM_BUFFER_SIZE=16
    SHARE_POOL_SIZE=64
    LARGE_POOL_SIZE=8
    DBWR_BUFFER_SIZE=4
    WORK_AREA_POOL_SIZE=16
    AUDIT_QUEUE_SIZE=16

    UserSize=$((DATA_BUFFER_SIZE + REDO_BUFFER_SIZE + VM_BUFFER_SIZE + SHARE_POOL_SIZE + LARGE_POOL_SIZE + DBWR_BUFFER_SIZE + WORK_AREA_POOL_SIZE + AUDIT_QUEUE_SIZE)) * 1024
    # 假设没有使用MMS表空间,因此MMSSize为0
    MMSSize=0
    # 增加额外的64M缓冲区
    BufferSize=64 * 1024
    # 计算总的大页内存需求
    LargePageSize=$((UserSize + MMSSize + BufferSize))
    # 转换为KB并乘以1.2(20%的额外空间)
    LargePageSizeKB=$((LargePageSize * 1024 * 1.2))
    # 大页尺寸,通常为2MB
    HugePageSize=2048
    # 计算所需的大页数量
    HugePages=$((LargePageSizeKB + HugePageSize / 2 / 1024))
    # 四舍五入到最近的整数
    HugePages=$((HugePages + HugePageSize / 1024 - 1 / HugePageSize / 1024))

    # 配置大页内存数量
    log "Enabling Large Page Memory with ${HugePages} pages..."
    echo "vm.nr_hugepages=$HugePages" | sudo tee -a /etc/sysctl.conf
    echo "vm.nr_overcommit_hugepages=0" | sudo tee -a /etc/sysctl.conf

    # 应用更改
    sudo sysctl -p
}

# 检查脚本所在目录是否为 /soft
SCRIPT_DIR=$(dirname "$(readlink -f "$0")")
if [ "$SCRIPT_DIR" != "/soft" ]; then
    echo -e "${RED}Error: This script must be run from the /soft directory.${NC}"
    exit 1
fi


# 解析传入的参数
while getopts "vho:dh:u:p:port:" opt; do
    case $opt in
        v)
            echo -e "${GREEN}YashanDBInstall version $VERSION${NC}"
            exit 0
            ;;
        o)
            OPENSSL_PACKAGE_PATH="$OPTARG"
            ;;
        dh)
            DIRECTORY_PATH="$OPTARG"
            ;;
        u)
            USERNAME="$OPTARG"
            ;;
        p)
            PASSWORD="$OPTARG"
            ;;
        port)
            PORT="$OPTARG"
            ;;
        h)
            echo -e "${GREEN}Usage: YashanDBInstall [OPTION]...${NC}"
            echo ""
            echo "Options:"
            echo "  -v,  --version        Display the version number of YashanDBInstall."
            echo "  -h,  --help           Display this help message."
            echo "  -o,  --openssl        Specify the openssl package path."
            echo "  -dh, --directory      Setup directory and permission setup."
            echo "                        Usage: YashanDBInstall -dh <directory_path>"
            echo "                        Example: YashanDBInstall -dh /data/yashan"
            echo "  -u,  --username       Specify the new yashandb username."
            echo "  -p,  --password       Specify the new yashandb password."
            echo "  -port, --port         Specify the port for yashandb."
            echo ""
            echo "Example:"
            echo "  YashanDBInstall -u newuser -p newpass -port 1689"
            exit 0
            ;;			
        *)
            echo -e "${RED}Invalid option - $OPT ${NC}Use -h for help."
            exit 1
            ;;
    esac
done

# 如果指定了 openssl package path,则进行版本检测和升级
if [ -n "$OPENSSL_PACKAGE_PATH" ]; then
    if [ ! -f "$OPENSSL_PACKAGE_PATH" ]; then
        echo -e "${RED}$OPENSSL_PACKAGE_PATH not found. Please upload the OpenSSL package to /soft/.${NC}"
        exit 1
    fi
    INSTALLER_PACKAGE=$(basename "$OPENSSL_PACKAGE_PATH")
    cp "$OPENSSL_PACKAGE_PATH" /soft/
fi

# 检查 openssl 版本是否小于1.1.1并需要升级
OPENSSL_VERSION=$(openssl version | awk '{print $2}')
REQUIRED_OPENSSL_VERSION="1.1.1"
if [[ "$(printf '%s\n' "$REQUIRED_OPENSSL_VERSION" "$OPENSSL_VERSION" | sort -V | head -n1)" == "$OPENSSL_VERSION" ]]; then
    echo -e "${BLUE}Warning: System OpenSSL version is less than $REQUIRED_OPENSSL_VERSION.${NC}"
    echo -e "${BLUE}System needs to upgrade OpenSSL to >= $REQUIRED_OPENSSL_VERSION.${NC}"
else
    echo -e "${GREEN}Current OpenSSL version is sufficient.${NC}"
    exit 0
fi

# 挂载操作系统镜像并配置软件源(假设操作系统镜像在 /dev/sr0)
echo -e "${BLUE}Mounting OS image and configuring software sources...${NC}"
sudo mount /dev/sr0 /mnt
mkdir -p /etc/yum.repos.d/bak
#sudo cp /mnt/etc/yum.repos.d/* /etc/yum.repos.d/
mv /etc/yum.repos.d/* /etc/yum.repos.d/bak
## 一键配置软件源,默认 ISO 安装镜像挂载在 /mnt 目录下
cat<<-EOF>/etc/yum.repos.d/local.repo
[server]
name=server
baseurl=file:///mnt
enabled=1
gpgcheck=0
EOF
echo -e "${GREEN}Software sources configured successfully.${NC}"

# 安装 gcc
echo -e "${BLUE}Installing GCC...${NC}"
sudo yum install -y gcc > /dev/null 2>&1
if [ $? -ne 0 ]; then
    echo -e "${RED}GCC installation failed.${NC}"
    exit 1
fi
echo -e "${GREEN}GCC installed successfully.${NC}"

# 备份系统自带的 openssl
echo -e "${BLUE}Backing up system OpenSSL...${NC}"
# 查找openssl的位置
OPENSSL_BIN=$(find /usr -name openssl | grep '/bin/openssl')
OPENSSL_LIB=$(find /usr -name openssl | grep '/lib64/openssl')

# 检查是否找到openssl
if [ -z "$OPENSSL_BIN" ] || [ -z "$OPENSSL_LIB" ]; then
    echo "未找到openssl相关文件。"
    exit 1
fi

# 移动openssl二进制文件和库文件
mv $OPENSSL_BIN ${OPENSSL_BIN}_old
mv $OPENSSL_LIB ${OPENSSL_LIB}_old
echo -e "${GREEN}Backup completed. {NC}"

# 解压并安装 openssl
echo -e "${BLUE}Extracting and installing OpenSSL...${NC}"
tar -zxf "/soft/$INSTALLER_PACKAGE" -C /soft > /dev/null 2>&1
EXTRACTED_DIR=$(tar -tf "/soft/$INSTALLER_PACKAGE" | head -n 1 | cut -d'/' -f1)
cd /soft/$EXTRACTED_DIR || exit 1
./config --prefix=/usr/local/openssl > /dev/null 2>&1
# 编译openssl
make > /dev/null 2>&1
if [ $? -ne 0 ]; then
    echo -e "${RED}OpenSSL Compilation failed.${NC}"
    exit 1
fi
make install > /dev/null 2>&1
if [ $? -ne 0 ]; then
    echo -e "${RED}OpenSSL installation failed.${NC}"
    exit 1
fi
# 重新链接openssl
ln -s /usr/local/openssl/bin/openssl /usr/bin/openssl
ln -s /usr/local/openssl/include/openssl/ /usr/include/openssl
echo "/usr/local/openssl/lib/" >> /etc/ld.so.conf
ldconfig -v > /dev/null 2>&1
if [ $? -ne 0 ]; then
    echo -e "${RED}OpenSSL Connect failed.${NC}"
    exit 1
fi

echo -e "${GREEN}OpenSSL installed successfully.${NC}"

# 判断 openssl 是否安装成功,输出 openssl 版本信息
NEW_OPENSSL_VERSION=$(/usr/local/openssl/bin/openssl version | awk '{print $2}')
echo -e "${GREEN}New OpenSSL version: $NEW_OPENSSL_VERSION${NC}"


#操作系统参数配置
echo "  - soft core unlimited" >> /etc/security/limits.conf
echo "  - hard core unlimited" >> /etc/security/limits.conf
#关闭交换分区
sysctl -w vm.swappiness=0
echo "vm.swappiness=0">> /etc/sysctl.conf
#调整自动分配本地端口范围
sysctl -w net.ipv4.ip_local_port_range='32768 60999' 
echo "net.ipv4.ip_local_port_range=32768 60999" >> /etc/sysctl.conf
#调整进程的VMA上限
sysctl -w vm.max_map_count=2000000
echo "vm.max_map_count=2000000" >> /etc/sysctl.conf
#配置sudo免密
chmod +w /etc/sudoers
echo "$USERNAME ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
chmod -w /etc/sudoers
#调整资源限制值
ulimit -n 1048576
ulimit -u 1048576
ulimit -m unlimited
ulimit -s 8192

echo "
 * soft nofile 1048576
 * hard nofile 1048576
 * soft nproc 1048576
 * hard nproc 1048576
 * soft rss unlimited
 * hard rss unlimited
 * soft stack 8192
 * hard stack 8192
" >> /etc/security/limits.conf

#关闭透明大页以及开启大内存页
#disable_transparent_huge_pages
#enable_large_pages


# 根据传入的参数创建用户、设置密码和端口号,并配置权限
sudo useradd -d /home/$USERNAME -m $USERNAME 
#sudo passwd $USERNAME <<< "$PASSWORD" 
echo "$USERNAME:$PASSWORD" | chpasswd
if [ $? -ne 0 ]; then
	echo -e "${RED}Error: Failed to set password for user $USERNAME.${NC}"
    exit 1
fi
groupadd YASDBA 
usermod -a -G YASDBA $USERNAME
mkdir -p /data/$USERNAME
chmod -R 777 /data/$USERNAME


YASHANDBINSTALLER="yashandb-personal-23.3.1.100-linux-x86_64.tar.gz"
#yashandb数据库安装
echo -e "${BLUE}Extracting and installing YashanDB...${NC}"

run_as_yashan "cd"
run_as_yashan "mkdir -p install"

cp -r /soft/$YASHANDBINSTALLER /home/$USERNAME/install

install_command=$(cat <<EOF
cd

cd ~/install

tar -zxf $YASHANDBINSTALLER
YS_EXTRACTED_DIR=\$(tar -tf "~/install/$YASHANDBINSTALLER" | head -n 1 | cut -d'/' -f1)
cd ~/install/\$YS_EXTRACTED_DIR || exit 1

cd ~/install

./bin/yasboot package se gen --cluster yashandb -u $USERNAME -p $PASSWORD --ip $OS_IPADDR --port 22 --install-path /data/$USERNAME/yasdb_home  --data-path /data/$USERNAME/yasdb_data --begin-port $PORT
echo -e "${GREEN} Package SE Gen Completed ${NC}"

./bin/yasboot package install -t hosts.toml -i $YASHANDBINSTALLER
echo -e "${GREEN} Package Install Completed ${NC}"

./bin/yasboot cluster deploy -t yashandb.toml
echo -e "${GREEN} Cluster Deploy Completed ${NC}"

cd /data/$USERNAME/yasdb_home/yashandb/23.3.1.100/conf
cat yashandb.bashrc >> ~/.bashrc
source ~/.bashrc
echo -e "${GREEN} Source Bashrc Completed ${NC}"

yasboot cluster password set -n $PASSWORD -c yashandb
echo -e "${GREEN} Password Set Completed ${NC}"

yasboot cluster status -c yashandb
echo -e "${GREEN} Cluster Status Checked ${NC}"
echo -e ""
echo -e ""
echo -e "${GREEN} YashanDB Installed Successfully, Please remember the account password$. {NC}"
echo -e "${GREEN} USERNAME:$USERNAME,PASSWORD:$PASSWORD. ${NC}"
echo -e ""

yasql sys/\$PASSWORD
echo -e "${GREEN} YASQL Command Executed ${NC}"
EOF
)
run_as_yashan "$install_command"

参考文档

链接: [link]( https://doc.yashandb.com/yashandb/23.3/zh/安装和升级/安装部署/00安装部署.html)

标签:YashanDB,NC,一键,openssl,echo,etc,OPENSSL,分享,SIZE
From: https://blog.csdn.net/m0_37873601/article/details/143480924

相关文章

  • Spring JPA集成YashanDB教程分享
    引言关于SpringJPASpringJPA(JavaPersistenceAPI)是JavaEE中关于持久化(即对象持久化到数据库)的标准规范,它为Java应用提供了一种与数据库交互的面向对象的方法。SpringDataJPA是Spring对JPA的实现,它极大地简化了数据持久化的操作。以下是SpringJPA的重要性和用途重......
  • 知识分享:Air780E软件之UDP应用示例
    一、UDP概述UDP(用户数据报协议,UserDatagramProtocol)是一种无连接的、不可靠的传输层协议,主要用于实现网络中的快速通讯。以下是UDP通讯的主要特点:1.1无连接通讯:UDP在发送数据之前不需要建立连接,这大大减少了通讯的延迟。发送方只需将数据包封装成UDP报文,并附上目的地址......
  • 数据结构-关键技术分享
    书:pan.baidu.com/s/1tIHXj9HmIYojAHqje09DTA?pwd=jqso数据结构与算法基础:介绍数据结构与算法的基本概念、重要性和应用场景,为读者打下坚实的基础。数据项与数据对象:详细解释数据项作为数据不可分割的最小单位,以及数据对象作为性质相同的数据元素的集合的概念。逻辑结构与物理......
  • 干货分享3:0.01元的付费引流方式,还是挺牛逼的!
    在淘宝看到一个很牛逼的产品,它的牛逼不是产品牛逼,而是价格牛逼…卖的也是一份虚拟资料。就是一份关于各种骗术的资料整理,没想到吧,这玩意还有这么多人会下单购买,我想更多的原因还是在于好奇心和价格便宜。0.01元卖了5000多份,合算下来是50元,虽然赚的不多,但也给我们打开一种思......
  • 【记录分享】多任务黑客攻击仿真模拟器
     在电影和电视剧中,黑客攻击的场景往往充满了紧张、快速的打字声和不断滚动的命令行界面。为了让这种体验更具沉浸感,我们可以通过编程模拟出一个真实的黑客攻击过程。本篇文章将介绍如何使用Python和Tkinter库设计一个多任务黑客攻击仿真模拟程序,包含攻击模拟、网络带宽......
  • hive基础知识分享(二)
    写在前面今天继续学习hive部分的知识。以下是您提供的内容转成的Markdown格式:Hive相关知识hive中不同的count区别selectclazz,count(distinctid)ascnt,count(*)ascnt,count(1)ascnt_1,count(id)ascnt_idfromstudentsgroupby......
  • Materials Studio 2023安装教程(仅作分享参考)
    一、软件下载软件名称:MaterialsStudio2023软件语言:英文软件大小:2.03G系统要求:Windows10或更高, 64位操作系统硬件要求:CPU@2+GHz,RAM@4G或更高下载通道①迅雷云盘丨下载链接:迅雷云盘下载通道②百度网盘丨下载链接:百度网盘请输入提取码提取码:6789二、软件介绍Material......
  • 分享一个替代ping的小工具Hping3
    在网络故障排查中,ping命令是最基础也是最常用的工具,然而,它的功能相对简单,局限性明显。对于复杂的网络环境,使用更强大的工具显得尤为重要。在这方面,Hping3无疑是一个出色的选择。本文将详细介绍Hping3的功能、应用场景以及与Ping的对比,帮助网络工程师更有效地排查网络问题。Hping......
  • 【测开面试篇一】全网最全测试开发岗位面试真题集分享
    前言        各位测试人,大家好,最近不是在网上投简历,就是在面试的路上。也接到了不少电话面试以及F2F面试,花时间给大家整理一下互联网大厂测试开发岗位的面试知识点和一些遇到的真题,各位看官请笑纳。        本人整理的面试知识点以及面试真题涵盖了互联网大......
  • 使用C++和QT开发应用程序入门以及开发实例分享
    目录1、搭建开发环境(VS2010和QT4.8.2)2、创建一个QT窗口3、在QT窗口中添加子窗口4、QT界面布局5、QT信号(SIGNAL)和槽(SLOT)6、最后C++软件异常排查从入门到精通系列教程(专栏文章列表,欢迎订阅,持续更新...)https://blog.csdn.net/chenlycly/article/details/125529931C/C++实......