前言
前段时间,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"