在空白主机上一键安装kickstart服务,分发centos5.8和mysql5.7.16
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在空白主机上一键安装kickstart服务,分发centos5.8和mysql5.7.16相关的知识,希望对你有一定的参考价值。
#!/bin/bash chkconfig --add sshd chkconfig sshd on yum -y install vim man wget #需关闭虚拟交换机的DHCP功能 #需要开放网络 #本机网段192.168.2.x IP20 #客户机硬盘大小100GB #借用了同班同学的mysql一键安装版本 #安装完成后客户机手动确认重启 line194可修改为自动重启 #缺少判断mysql是否成功下载并提示的判断: # 1.本地FTP共享文件夹是否有mysql*.tar.gz ————no→2.wget是否成功下载 ————no→3.提示用户,并退出脚本 #缺少将本机IP参数化并带入到kiskstart各个服务中的智能化判断 #需要在光驱中插入6.8的光盘 #ks工具并不需要安装,只要ks文件编好就可以,安装Ks要安装图形界面太浪费时间与内存与硬盘 #dhcp yum -y install dhcp create_dhcp_conf() { cat > /etc/dhcp/dhcpd.conf <<EOF #dhcpd.conf #sample configuration file for ISC dhcpd log-facility local7; #internal subnet subnet 192.168.2.0 netmask 255.255.255.0 { range 192.168.2.100 192.168.2.200; option routers 192.168.2.2; default-lease-time 600; next-server 192.168.2.20; filename "pxelinux.0"; } EOF } create_dhcp_conf service dhcpd restart chkconfig --add dhcpd chkconfig dhcpd on #vsftp,for download mysql from server to client wget -N --no-check-certificate https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz -P /var/ftp/ yum -y install vsftpd chkconfig --add vsftpd chkconfig vsftpd on #tftp yum -y install tftp-server tftp create_tftpserver_conf() { cat > /etc/xinetd.d/tftp <<EOF service tftp { socket_type =dgram protocol =udp wait =yes user =root server =/usr/sbin/in.tftpd server_args = -s /var/lib/tftpboot disable =no per_source =11 cps =100 2 flags =IPv4 } EOF } create_tftpserver_conf chkconfig --add xinetd chkconfig xinetd on service xinetd reload service xinetd restart #iptables selinux /etc/init.d/iptables stop chkconfig --del iptables setenforce 0 sed -i "s/enforcing/permissive/g" /etc/selinux/config #kickstart #yum -y install system-config-kickstart #yum -y groupinstall "Desktop" #yum -y groupinstall "X Window System" #yum -y groupinstall "chinese support" #nfs mkdir /ks mkdir -p /iso/6.8 yum -y install nfs-utils cat > /etc/exports <<EOF /ks 192.168.2.0/24(ro) /iso 192.168.2.0/24(ro) EOF chkconfig --add nfs chkconfig nfs on chkconfig --add rpcbind chkconfig rpcbind on service rpcbind restart service nfs restart #启动文件 alias cp=‘cp -i‘ unalias_for_copy() { unalias cp } unalias_for_copy yum -y install syslinux #复制pxelinux.0 文件至/var/lib/tftpboot/ 文件夹中 #syslinux是一个功能强大的引导加载程序,而且兼容各种介质。更加确切地说:SYSLINUX是一个小型的Linux操作系统,它的目的是简化首次安装Linux的时间,并建立修护或其它特殊用途的启动盘。 cp -f /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/ umount /media mount /dev/cdrom /media mkdir -p /iso/6.8/ cp -rf /media/* /iso/6.8/ cp -rf /iso/6.8/isolinux/{initrd.img,vmlinuz} /var/lib/tftpboot/ cp /iso/6.8/isolinux/*.msg /var/lib/tftpboot/ mkdir -p /var/lib/tftpboot/pxelinux.cfg cp -rf /iso/6.8/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default cat > /var/lib/tftpboot/pxelinux.cfg/default <<EOF default ks prompt 1 timeout 6 display boot.msg menu background splash.jpg menu title Welcome to CentOS 6.8! menu color border 0 #ffffffff #00000000 menu color sel 7 #ffffffff #ff000000 menu color title 0 #ffffffff #00000000 menu color tabmsg 0 #ffffffff #00000000 menu color unsel 0 #ffffffff #00000000 menu color hotsel 0 #ff000000 #ffffffff menu color hotkey 7 #ffffffff #ff000000 menu color scrollbar 0 #ffffffff #00000000 label linux menu label ^Install or upgrade an existing system menu default kernel vmlinuz append initrd=initrd.img label ks kernel vmlinuz append ks=nfs:192.168.2.20:/ks/c68m57.cfg initrd=initrd.img label vesa menu label Install system with ^basic video driver kernel vmlinuz append initrd=initrd.img nomodeset label rescue menu label ^Rescue installed system kernel vmlinuz append initrd=initrd.img rescue label local menu label Boot from ^local drive localboot 0xffff label memtest86 menu label ^Memory test kernel memtest append - EOF alias cp=‘cp -i‘ #创建kickstart配置文件 cat > /ks/c68m57.cfg <<EOF #platform=x86, AMD64, 或 Intel EM64T #version=DEVEL # Firewall configuration firewall --disabled # Install OS instead of upgrade install # Use NFS installation media nfs --server=192.168.2.20 --dir=/iso/6.8 # Root password #若采用加密密码的方式,每次密码加密后的字符串是随机的,则设置的密码无法重复使用 rootpw --plaintext sa123456 # System authorization information auth --useshadow --passalgo=sha512 # Use graphical install graphical # System keyboard keyboard us # System language lang zh_CN # SELinux configuration selinux --permissive # Do not configure the X Window System skipx # Installation logging level logging --level=info # Reboot after installation #reboot # System timezone timezone Asia/Shanghai # Network information network --bootproto=static --device=eth0 --gateway=192.168.2.2 --ip=192.168.2.88 --nameserver=192.168.2.2 --netmask=255.255.255.0 --onboot=on # System bootloader configuration bootloader --location=mbr # Partition clearing information clearpart --all --initlabel # Disk partitioning information part swap --fstype="swap" --size=4096 part /boot --fstype="ext4" --size=300 part / --fstype="ext4" --size=30270 part /data --fstype="xfs" --grow --size=1 %post yum -y install vim openssh man chkconfig --add sshd chkconfig sshd on cat>>/etc/crontab<<EEE 00 0 1 * * root ntpdate -s time.nist.gov EEE chown -R mysql:mysql /data/mysql echo "创建目录与授权完成" cd /data/mysql/3306 echo "创建my.cnf" cat >> my.cnf << EOP #my.cnf [client] port = 3306 socket = /data/mysql/3306/tmp/mysql3306.sock [mysql] prompt="\\[email protected]\\h:\\p [\\d]>" #pager="less -i -n -S" #tee=/data/mysql/3306/query.log no-auto-rehashntpdate -s time.nist.gov #paragraph for mysql wget -N ftp://192.168.2.20/mysql/mysql-5.7.14-linux-glibc2.5-x86_64_x.tar.gz -P /usr/local/src/ groupadd mysql useradd -d /usr/local/mysql -s /sbin/nologin -g mysql -M -n mysql cd /usr/local/src/ tar -zxf mysql-5.7.14-linux-glibc2.5-x86_64_x.tar.gz -C /usr/local echo "解压完成" cd ../ ln -s mysql-5.7.14-linux-glibc2.5-x86_64 mysql echo "创建软连接" chown -R mysql:mysql /usr/local/mysql mkdir -p /data/mysql/3306/{data,logs,tmp} [mysqld] #misc user = mysql basedir = /usr/local/mysql datadir = /data/mysql/3306/data port = 3306 socket = /data/mysql/3306/tmp/mysql3306.sock event_scheduler = 0 tmpdir = /data/mysql/3306/tmp #timeout interactive_timeout = 3600 wait_timeout = 3600 #character set character-set-server = utf8 open_files_limit = 65535 max_connections = 500 max_connect_errors = 100000 lower_case_table_names =1 #symi replication #rpl_semi_sync_master_enabled=1 #rpl_semi_sync_master_timeout=1000 # 1 second #rpl_semi_sync_slave_enabled=1 #logs log-output=file slow_query_log = 1 slow_query_log_file = slow.log log-error = error.log log_warnings = 2 pid-file = mysql.pid long_query_time = 1 #log-slow-admin-statements = 1 #log-queries-not-using-indexes = 1 log-slow-slave-statements = 1 #binlog #binlog_format = STATEMENT binlog_format = row server-id = 13306 log-bin = /data/mysql/3306/logs/mysql-bin binlog_cache_size = 4M max_binlog_size = 256M max_binlog_cache_size = 1M sync_binlog = 0 expire_logs_days = 10 #procedure log_bin_trust_function_creators=1 # gtid-mode = on enforce-gtid-consistency=1 #relay log skip_slave_start = 1 max_relay_log_size = 128M relay_log_purge = 1 relay_log_recovery = 1 relay-log=relay-bin relay-log-index=relay-bin.index log_slave_updates #slave-skip-errors=1032,1053,1062 #skip-grant-tables #buffers & cache table_open_cache = 2048 table_definition_cache = 2048 table_open_cache = 2048 max_heap_table_size = 96M sort_buffer_size = 128K join_buffer_size = 128K thread_cache_size = 200 query_cache_size = 0 query_cache_type = 0 query_cache_limit = 256K query_cache_min_res_unit = 512 thread_stack = 192K tmp_table_size = 96M key_buffer_size = 8M read_buffer_size = 2M read_rnd_buffer_size = 16M bulk_insert_buffer_size = 32M #myisam myisam_sort_buffer_size = 128M myisam_max_sort_file_size = 1G myisam_repair_threads = 1 #innodb innodb_buffer_pool_size = 1G innodb_buffer_pool_instances = 1 innodb_data_file_path = ibdata1:1024M:autoextend innodb_flush_log_at_trx_commit = 2 innodb_log_buffer_size = 8M innodb_log_file_size = 100M innodb_log_files_in_group = 3 innodb_max_dirty_pages_pct = 50 innodb_file_per_table = 1 innodb_rollback_on_timeout innodb_status_file = 1 innodb_io_capacity = 200 transaction_isolation = READ-COMMITTED innodb_flush_method = O_DIRECT EOP echo "创建启动文件" cat >> mysqld << EEP #!/bin/bash mysql_port=3306 #端口 mysql_user="root" #用户 mysql_pwd="" #密码 CmdPath="/usr/local/mysql/bin" mysql_sock="/data/mysql/\${mysql_port}/tmp/mysql\${mysql_port}.sock" #startup function function_start_mysql() { if [ ! -e "\$mysql_sock" ];then printf "Starting MySQL...\n" \${CmdPath}/mysqld --defaults-file=/data/mysql/\${mysql_port}/my.cnf 2>&1 > /dev/null & else printf "MySQL is running...\n" exit fi } function_stop_mysql() { if [ ! -e "\$mysql_sock" ];then printf "Stoping MySQL...\n" exit else printf "MySQL is stopped...\n" \${CmdPath}/mysqladmin -u\${mysql_user} -p\${mysql_pwd} -S \$mysql_sock shutdown fi } function_restart_mysql() { printf "Restarting MySQL...\n" function_stop_mysql sleep 2 function_start_mysql } case \$1 in start) function_start_mysql ;; stop) function_stop_mysql ;; restart) function_restart_mysql ;; *) printf "Usage: /data/mysql/\${mysql_port}/mysqld {start|stop|restart} \n" esac EEP echo "完成" /usr/local/mysql/bin/mysqld --defaults-file=/data/mysql/3306/my.cnf --basedir=/usr/local/mysql --datadir=/data/mysql/3306/data --user=mysql --initialize echo "mysql初始化完成" echo ‘export PATH=/usr/local/mysql/bin:$PATH‘ >> /etc/profile source /etc/profile echo "变量配置完成" cat /data/mysql/3306/data/error.log |grep "[email protected]"|awk -F " " ‘{print $11}‘ >/data/mysql/3306/password.txt echo "root随机密码完成cat /data/mysql/3306/password.txt" chmod +x /data/mysql/3306/mysqld echo "启动命令/data/mysql/3306/mysqld start" echo "关闭命令/data/mysql/3306/mysqld stop" echo "脚本编写人叶梁坚 QQ88263188 " #paragraph end of mysql 00 0 1 * * root ntpdate -s time.nist.gov EEE ntpdate -s time.nist.gov %end EOF
本文出自 “FF的网管日记” 博客,请务必保留此出处http://l0vesql.blog.51cto.com/4159433/1913606
以上是关于在空白主机上一键安装kickstart服务,分发centos5.8和mysql5.7.16的主要内容,如果未能解决你的问题,请参考以下文章
CentOS 7 PXE+Kickstart+TFTP+VSFTP+BIOS+UEFI