通过kickstart 执行mysql、clickhouse数据导入
核心后置:拷贝业务资源 + 直接执行业务安装脚本(安装阶段完成软件部署,无需开机自启)
创建一组post,将转移、执行数据文件都放在这个里面。
%post --nochroot --log=/mnt/sysimage/var/log/auto_install_software.log
#!/bin/bash
复制全套业务安装资源到新系统/home目录
/run/install/repo代表ISO目录的根
/mnt/sysimage代表安装后系统的根
含义:把 放到ISO根目录下的install 转移到 安装好的系统的/下
cp -rf /run/install/repo/install /mnt/sysimage/home/
系统基础优化:卸载多余图形组件、关闭防火墙与包更新定时器,供参考
chroot /mnt/sysimage dnf remove gnome-desktop3.x86_64 -y
chroot /mnt/sysimage systemctl stop dnf-makecache.timer
chroot /mnt/sysimage systemctl disable dnf-makecache.timer
chroot /mnt/sysimage systemctl stop firewalld
chroot /mnt/sysimage systemctl disable firewalld
chroot /mnt/sysimage systemctl stop packagekit.service
chroot /mnt/sysimage systemctl disable packagekit.service
chroot /mnt/sysimage systemctl mask packagekit.service
chroot /mnt/sysimage crontab -r
拷贝根目录下的软件安装脚本并赋予执行权限,供参考
cp /run/install/repo/initinstall_vm.sh /mnt/sysimage/tmp/initinstall_vm.sh
chmod +x /mnt/sysimage/tmp/initinstall_vm.sh
这部分可以改成自己需要的部分,将数据库安装放到这里
chroot进入新系统,完整自动安装业务软件,供参考
#chroot /mnt/sysimage bash /tmp/initinstall_vm.sh | tee -a /root/post_output.txt /dev/tty3
chroot /mnt/sysimage /bin/bash <<‘EOF’
bash /tmp/initinstall_vm.sh > /dev/tty3 2>&1
mount --bind / /mnt/sysimage
systemctl start clickhouse-server.service 2>&1 | tee -a /root/post_output.txt /dev/tty3
sleep 10
全路径启动mysql
/opt/mysql/bin/mysqld --basedir=/opt/mysql --datadir=/opt/mysql/data --plugin-dir=/opt/mysql/lib/plugin --user=mysql --daemonize --log-error=/opt/mysql/mysqld.log --pid-file=/opt/mysql/data/localhost.localdomain.pid --socket=/opt/mysql/mysql.sock --port=3306 &
sleep 10
打印进程与端口信息
echo “>>>检查mysql进程” 2>&1 | tee -a /root/post_output.txt /dev/tty3
ps -ef|grep mysql 2>&1 | tee -a /root/post_output.txt /dev/tty3
echo “>>>检查clickhouse进程” 2>&1 | tee -a /root/post_output.txt /dev/tty3
ps -ef|grep clickhouse 2>&1 | tee -a /root/post_output.txt /dev/tty3
echo “>>>打印监听端口列表” 2>&1 | tee -a /root/post_output.txt /dev/tty3
netstat -anop|grep LISTEN 2>&1 | tee -a /root/post_output.txt /dev/tty3
echo “>>>检查clickhouse 9000端口” 2>&1 | tee -a /root/post_output.txt /dev/tty3
netstat -tlnp | grep 9000 2>&1 | tee -a /root/post_output.txt /dev/tty3
echo “end init mysql config” 2>&1 | tee -a /root/post_output.txt /dev/tty3
echo “>>>开始执行mysql结构数据导入” 2>&1 | tee -a /root/post_output.txt /dev/tty3
/opt/mysql/bin/mysql -h127.0.0.1 -P3306 -uopt -popt -s -N -f < /home/install/databaseInit/mysql/opt_struct.sql 2>&1 | tee -a /root/post_output.txt /dev/tty3
echo “>>>开始执行mysql初始化数据导入” 2>&1 | tee -a /root/post_output.txt /dev/tty3
/opt/mysql/bin/mysql -h127.0.0.1 -P3306 -uopt -popt -Dopt -s -N -f < /home/install/databaseInit/mysql/opt_initdata.sql 2>&1 | tee -a /root/post_output.txt /dev/tty3
clickhouse-client -h 127.0.0.1 --query “drop database if exists opt” 2>&1 | tee -a /root/post_output.txt /dev/tty3
clickhouse-client -h 127.0.0.1 --query “CREATE DATABASE IF NOT EXISTS opt” 2>&1 | tee -a /root/post_output.txt /dev/tty3
sleep 60
clickhouse-client -h 127.0.0.1 -d opt–multiquery < ./databaseInit/clickhouse/ch_struct.sql 2>&1 | tee -a /root/post_output.txt /dev/tty3
clickhouse-client -h 127.0.0.1 --database=“opt” --query=“insert into opt.t_threat_intelligence FORMAT CSVWithNames” < ./databaseInit/threat/threat.csv 2>&1 | tee -a /root/post_output.txt /dev/tty3
%end