脚本自动化安装崖山数据库

已在CentOS7.9-mini版上测试通过

由于第一部分设置参数后需要重启电脑,建议分成两个脚本,先执行第一部分,重启后,再执行第二部分。

#第一部分脚本

_LOG_FILE=./yashan_db_install.log

#设置主机名
hostnamectl set-hostname yashandb
cat /etc/hostname >> $_LOG_FILE

#设置/etc/hosts文件
echo "$( ip a |grep "[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*" |grep -v 127 |awk '{print $2}' | awk -F/ '{print $1}' ) yashandb" >> /etc/hosts
cat /etc/hosts >> $_LOG_FILE

#关闭交换分区
sysctl -w vm.swappiness=0
echo "vm.swappiness = 0">> /etc/sysctl.conf
sysctl -a | grep swappiness >> $_LOG_FILE
    
#调整自动分配本地端口范围
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
sysctl -a|grep vm.max_map_count >> $_LOG_FILE

#调整资源限制值
echo "
* soft nofile 65536
* hard nofile 65536
* soft nproc  65536
* hard nproc  65536
* soft rss    unlimited
* hard rss    unlimited
* soft stack  8192
* hard stack  8192
" >> /etc/security/limits.conf
cat /etc/security/limits.conf | tail -15 >> $_LOG_FILE

#关闭透明大页
echo '
echo never > /sys/kernel/mm/transparent_hugepage/defrag
echo never > /sys/kernel/mm/transparent_hugepage/enabled
' >> /etc/rc.d/rc.local
cat /etc/rc.d/rc.local | tail -5 >> $_LOG_FILE
chmod 755 /etc/rc.d/rc.local
ls -l /etc/rc.d/rc.local >> $_LOG_FILE

#关闭防火墙、Selinux
systemctl disable firewalld.service
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
cat /etc/selinux/config |grep -w "^SELINUX" >> $_LOG_FILE
init 6

#第二部分脚本

_LOG_FILE=./yashan_db_install.log
#安装基础软件
mkdir /etc/yum.repos.d/bak
mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/bak
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
yum install -y gcc make wget net-tools perl
wget https://github.com/openssl/openssl/releases/download/OpenSSL_1_1_1l/openssl-1.1.1l.tar.gz
tar -zxf  openssl-1.1.1l.tar.gz
mkdir -p /usr/local/openssl
cd openssl-1.1.1l
./config --prefix=/usr/local/openssl no-zlib
make -j 4 && make install
mv /usr/bin/openssl /usr/bin/openssl.bak
mv /usr/include/openssl /usr/include/openssl.bak
ln -s /usr/local/openssl/bin/openssl /usr/bin/openssl
ln -s /usr/local/openssl/include/openssl /usr/include/openssl
ln -s /usr/local/openssl/lib/libssl.so.1.1  /usr/lib64/libssl.so.1.1
ln -s /usr/local/openssl/lib/libcrypto.so.1.1  /usr/lib64/libcrypto.so.1.1
echo "/usr/local/openssl/lib" >> /etc/ld.so.conf
ldconfig -v
openssl version

#配置sudo免密
echo "yashan  ALL=(ALL)NOPASSWD:ALL" >>                 /etc/sudoers
tail /etc/sudoers >> $_LOG_FILE

#创建用户及用户组
groupadd YASDBA
useradd -d /home/yashan -m yashan -G YASDBA
echo "hellodba" | passwd --stdin yashan
mkdir -p /YashanDB
chmod -R 777 /YashanDB

#下载yashandb-23.2.4.100-linux-x86_64.tar.gz软件
su - yashan -c 'mkdir install'
su - yashan -c 'cd install'
su - yashan -c 'wget https://linked.yashandb.com/upload1010/yashandb-23.2.4.100-linux-x86_64.tar.gz'
su - yashan -c 'tar -zxf yashandb-23.2.4.100-linux-x86_64.tar.gz'

#安装数据库
su - yashan -c "./bin/yasboot package se gen --cluster yashandb --recommend-param \
    -u yashan -p hellodba --ip $( ip a |grep "[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*" |grep -v 127 |awk '{print $2}' | awk -F/ '{print $1}' ) --port 22 \
    --install-path /YashanDB/yashan/yasdb_home  --data-path /YashanDB/yashan/yasdb_data \
    --begin-port 1688"

su - yashan -c './bin/yasboot package install -t hosts.toml -i  yashandb-23.2.4.100-linux-x86_64.tar.gz'

su - yashan -c './bin/yasboot cluster deploy -t yashandb.toml'

su - yashan -c 'echo "export YASDB_DATA=/YashanDB/yashan/yasdb_data/db-1-1/" >>~/.bashrc'
su - yashan -c 'yasboot cluster status -c yashandb -d'

#设置开机自启动
echo "
su - yashan -c 'yasboot process yasom start -c yashandb'
su - yashan -c 'yasboot process yasagent start -c yashandb'
su - yashan -c 'yasboot cluster start -c yashandb'
su - yashan -c 'yasboot monit start --cluster yashandb'
" >> /etc/rc.local
tail /etc/rc.local >> $_LOG_FILE

#重启测试
init 6

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值