通过kickstart 执行mysql、clickhouse数据导入
通过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 -ychroot /mnt/sysimage systemctl stop dnf-makecache.timerchroot /mnt/sysimage systemctl disable dnf-makecache.timerchroot /mnt/sysimage systemctl stop firewalldchroot /mnt/sysimage systemctl disable firewalldchroot /mnt/sysimage systemctl stop packagekit.servicechroot /mnt/sysimage systemctl disable packagekit.servicechroot /mnt/sysimage systemctl mask packagekit.servicechroot /mnt/sysimage crontab -r拷贝根目录下的软件安装脚本并赋予执行权限供参考cp /run/install/repo/initinstall_vm.sh /mnt/sysimage/tmp/initinstall_vm.shchmod x /mnt/sysimage/tmp/initinstall_vm.sh这部分可以改成自己需要的部分将数据库安装放到这里chroot进入新系统完整自动安装业务软件供参考#chroot /mnt/sysimage bash /tmp/initinstall_vm.sh | tee -a /root/post_output.txt /dev/tty3chroot /mnt/sysimage /bin/bash ‘EOF’bash /tmp/initinstall_vm.sh /dev/tty3 21mount --bind / /mnt/sysimagesystemctl start clickhouse-server.service 21 | tee -a /root/post_output.txt /dev/tty3sleep 10全路径启动mysql/opt/mysql/bin/mysqld --basedir/opt/mysql --datadir/opt/mysql/data --plugin-dir/opt/mysql/lib/plugin --usermysql --daemonize --log-error/opt/mysql/mysqld.log --pid-file/opt/mysql/data/localhost.localdomain.pid --socket/opt/mysql/mysql.sock --port3306 sleep 10打印进程与端口信息echo “检查mysql进程” 21 | tee -a /root/post_output.txt /dev/tty3ps -ef|grep mysql 21 | tee -a /root/post_output.txt /dev/tty3echo “检查clickhouse进程” 21 | tee -a /root/post_output.txt /dev/tty3ps -ef|grep clickhouse 21 | tee -a /root/post_output.txt /dev/tty3echo “打印监听端口列表” 21 | tee -a /root/post_output.txt /dev/tty3netstat -anop|grep LISTEN 21 | tee -a /root/post_output.txt /dev/tty3echo “检查clickhouse 9000端口” 21 | tee -a /root/post_output.txt /dev/tty3netstat -tlnp | grep 9000 21 | tee -a /root/post_output.txt /dev/tty3echo “end init mysql config” 21 | tee -a /root/post_output.txt /dev/tty3echo “开始执行mysql结构数据导入” 21 | 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 21 | tee -a /root/post_output.txt /dev/tty3echo “开始执行mysql初始化数据导入” 21 | 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 21 | tee -a /root/post_output.txt /dev/tty3clickhouse-client -h 127.0.0.1 --query “drop database if exists opt” 21 | tee -a /root/post_output.txt /dev/tty3clickhouse-client -h 127.0.0.1 --query “CREATE DATABASE IF NOT EXISTS opt” 21 | tee -a /root/post_output.txt /dev/tty3sleep 60clickhouse-client -h 127.0.0.1 -d opt–multiquery ./databaseInit/clickhouse/ch_struct.sql 21 | tee -a /root/post_output.txt /dev/tty3clickhouse-client -h 127.0.0.1 --database“opt” --query“insert into opt.t_threat_intelligence FORMAT CSVWithNames” ./databaseInit/threat/threat.csv 21 | tee -a /root/post_output.txt /dev/tty3%end