#!/bin/bash
chkconfig--addsshd
chkconfigsshdon
yum-yinstallvimmanwget
#需关闭虚拟交换机的DHCP功能
#需要开放网络
#本机网段192.168.2.xIP20
#客户机硬盘大小100GB
#借用了同班同学的MysqL一键安装版本
#安装完成后客户机手动确认重启line194可修改为自动重启
#缺少判断MysqL是否成功下载并提示的判断:
# 1.本地FTP共享文件夹是否有MysqL*.tar.gz――――no→2.wget是否成功下载――――no→3.提示用户,并退出脚本
#缺少将本机IP参数化并带入到kiskstart各个服务中的智能化判断
#需要在光驱中插入6.8的光盘
#ks工具并不需要安装,只要ks文件编好就可以,安装Ks要安装图形界面太浪费时间与内存与硬盘
#dhcp
yum-yinstalldhcp
create_dhcp_conf()
{
cat>/etc/dhcp/dhcpd.conf<<EOF
#dhcpd.conf
#sampleconfigurationfileforISCdhcpd
log-facilitylocal7;
#internalsubnet
subnet192.168.2.0netmask255.255.255.0
{
range192.168.2.100192.168.2.200;
optionrouters192.168.2.2;
default-lease-time600;
next-server192.168.2.20;
filename"pxelinux.0";
}
EOF
}
create_dhcp_conf
servicedhcpdrestart
chkconfig--adddhcpd
chkconfigdhcpdon
#vsftp,fordownloadMysqLfromservertoclient
wget-N--no-check-certificatehttps://cdn.MysqL.com//Downloads/MysqL-5.7/MysqL-5.7.17-linux-glibc2.5-x86_64.tar.gz-P/var/ftp/
yum-yinstallvsftpd
chkconfig--addvsftpd
chkconfigvsftpdon
#tftp
yum-yinstalltftp-servertftp
create_tftpserver_conf()
{
cat>/etc/xinetd.d/tftp<<EOF
servicetftp
{
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=1002
flags=IPv4
}
EOF
}
create_tftpserver_conf
chkconfig--addxinetd
chkconfigxinetdon
servicexinetdreload
servicexinetdrestart
#iptablesselinux
/etc/init.d/iptablesstop
chkconfig--deliptables
setenforce0
sed-i"s/enforcing/permissive/g"/etc/selinux/config
#kickstart
#yum-yinstallsystem-config-kickstart
#yum-ygroupinstall"Desktop"
#yum-ygroupinstall"XWindowSystem"
#yum-ygroupinstall"chinesesupport"
#nfs
mkdir/ks
mkdir-p/iso/6.8
yum-yinstallnfs-utils
cat>/etc/exports<<EOF
/ks192.168.2.0/24(ro)
/iso192.168.2.0/24(ro)
EOF
chkconfig--addnfs
chkconfignfson
chkconfig--addrpcbind
chkconfigrpcbindon
servicerpcbindrestart
servicenfsrestart
#启动文件
aliascp='cp-i'
unalias_for_copy()
{
unaliascp
}
unalias_for_copy
yum-yinstallsyslinux
#复制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
defaultks
prompt1
timeout6
displayboot.msg
menubackgroundsplash.jpg
menutitleWelcometoCentOS6.8!
menucolorborder0#ffffffff#00000000
menucolorsel7#ffffffff#ff000000
menucolortitle0#ffffffff#00000000
menucolortabmsg0#ffffffff#00000000
menucolorunsel0#ffffffff#00000000
menucolorhotsel0#ff000000#ffffffff
menucolorhotkey7#ffffffff#ff000000
menucolorscrollbar0#ffffffff#00000000
labellinux
menulabel^Installorupgradeanexistingsystem
menudefault
kernelvmlinuz
appendinitrd=initrd.img
labelks
kernelvmlinuz
appendks=nfs:192.168.2.20:/ks/c68m57.cfginitrd=initrd.img
labelvesa
menulabelInstallsystemwith^basicvideodriver
kernelvmlinuz
appendinitrd=initrd.imgnomodeset
labelrescue
menulabel^Rescueinstalledsystem
kernelvmlinuz
appendinitrd=initrd.imgrescue
labellocal
menulabelBootfrom^localdrive
localboot0xffff
labelmemtest86
menulabel^Memorytest
kernelmemtest
append-
EOF
aliascp='cp-i'
#创建kickstart配置文件
cat>/ks/c68m57.cfg<<EOF
#platform=x86,AMD64,或IntelEM64T
#version=DEVEL
#Firewallconfiguration
firewall--disabled
#InstallOSinsteadofupgrade
install
#UseNFSinstallationmedia
nfs--server=192.168.2.20--dir=/iso/6.8
#Rootpassword
#若采用加密密码的方式,每次密码加密后的字符串是随机的,则设置的密码无法重复使用
rootpw--plaintextsa123456
#Systemauthorizationinformation
auth--useshadow--passalgo=sha512
#Usegraphicalinstall
graphical
#Systemkeyboard
keyboardus
#Systemlanguage
langzh_CN
#SELinuxconfiguration
selinux--permissive
#DonotconfiguretheXWindowSystem
skipx
#Installationlogginglevel
logging--level=info
#Rebootafterinstallation
#reboot
#Systemtimezone
timezoneAsia/Shanghai
#Networkinformation
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
#Systembootloaderconfiguration
bootloader--location=mbr
#Partitionclearinginformation
clearpart--all--initlabel
#Diskpartitioninginformation
partswap--fstype="swap"--size=4096
part/boot--fstype="ext4"--size=300
part/--fstype="ext4"--size=30270
part/data--fstype="xfs"--grow--size=1
%post
yum-yinstallvimopensshman
chkconfig--addsshd
chkconfigsshdon
cat>>/etc/crontab<<EEE
0001**rootntpdate-stime.nist.gov
EEE
chown-RMysqL: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="\\u@\\h:\\p[\\d]>"
#pager="less-i-n-S"
#tee=/data/MysqL/3306/query.log
no-auto-rehashntpdate-stime.nist.gov
#paragraphforMysqL
wget-Nftp://192.168.2.20/MysqL/MysqL-5.7.14-linux-glibc2.5-x86_64_x.tar.gz-P/usr/local/src/
groupaddMysqL
useradd-d/usr/local/MysqL-s/sbin/nologin-gMysqL-M-nMysqL
cd/usr/local/src/
tar-zxfMysqL-5.7.14-linux-glibc2.5-x86_64_x.tar.gz-C/usr/local
echo"解压完成"
cd../
ln-sMysqL-5.7.14-linux-glibc2.5-x86_64MysqL
echo"创建软连接"
chown-RMysqL: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
#characterset
character-set-server=utf8
open_files_limit=65535
max_connections=500
max_connect_errors=100000
lower_case_table_names=1
#symireplication
#rpl_semi_sync_master_enabled=1
#rpl_semi_sync_master_timeout=1000#1second
#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
#relaylog
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"
#startupfunction
function_start_MysqL()
{
if[!-e"\$MysqL_sock"];then
printf"StartingMysqL...\n"
\${CmdPath}/MysqLd--defaults-file=/data/MysqL/\${MysqL_port}/my.cnf2>&1>/dev/null&
else
printf"MysqLisrunning...\n"
exit
fi
}
function_stop_MysqL()
{
if[!-e"\$MysqL_sock"];then
printf"StopingMysqL...\n"
exit
else
printf"MysqLisstopped...\n"
\${CmdPath}/MysqLadmin-u\${MysqL_user}-p\${MysqL_pwd}-S\$MysqL_sockshutdown
fi
}
function_restart_MysqL()
{
printf"RestartingMysqL...\n"
function_stop_MysqL
sleep2
function_start_MysqL
}
case\$1in
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'exportPATH=/usr/local/MysqL/bin:$PATH'>>/etc/profile
source/etc/profile
echo"变量配置完成"
cat/data/MysqL/3306/data/error.log|grep"root@localhost"|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/MysqLdstart"
echo"关闭命令/data/MysqL/3306/MysqLdstop"
echo"脚本编写人叶梁坚QQ88263188"
#paragraphendofMysqL
0001**rootntpdate-stime.nist.gov
EEE
ntpdate-stime.nist.gov
%end
EOF
原文链接:https://www.f2er.com/centos/378061.html