-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcsh.sh
More file actions
10152 lines (7139 loc) · 282 KB
/
Copy pathcsh.sh
File metadata and controls
10152 lines (7139 loc) · 282 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
#********************************************************************
#Author: HEhandsome
#Date: 2024-07-24
#FileName: csh.sh
#BLOG: https://www.cnblogs.com/smlience
#Description: 路漫漫其修远兮,吾将上下而求索
#********************************************************************
. /etc/os-release
set -u #需要手动执行一下
set -e #cd /data rm -rf ./* 如果data不存在,后面rm就不会执行
#LOG_FILE="/var/log/csh.log" # 日志文件路径
# 日志记录函数
#log() {
# local msg="$1"
# echo "$(date +'%Y-%m-%d %H:%M:%S') - $msg" | tee -a "$LOG_FILE"
#}
# 错误处理函数
#error_handler() {
# local exit_code="$?"
# local line_num="$1"
# log "Error at line $line_num: exit code $exit_code"
# exit $exit_code
#}
# 捕获错误信号
#trap 'error_handler $LINENO' ERR
# 包装命令执行并处理错误
#run_command() {
# local cmd="$1"
# if ! eval "$cmd"; then
# log "Error: Command '$cmd' failed"
# return 1
# fi
#}
color () {
RES_COL=60
MOVE_TO_COL="echo -en \\033[${RES_COL}G"
SETCOLOR_SUCCESS="echo -en \\033[1;32m"
SETCOLOR_FAILURE="echo -en \\033[1;31m"
SETCOLOR_WARNING="echo -en \\033[1;33m"
SETCOLOR_NORMAL="echo -en \E[0m"
echo -n "$1" && $MOVE_TO_COL
echo -n "["
if [ $2 = "success" -o $2 = "0" ] ;then
${SETCOLOR_SUCCESS}
echo -n $" OK "
elif [ $2 = "failure" -o $2 = "1" ] ;then
${SETCOLOR_FAILURE}
echo -n $"FAILED"
else
${SETCOLOR_WARNING}
echo -n $"WARNING"
fi
${SETCOLOR_NORMAL}
echo -n "]"
echo
}
##########################################
## Starting
CshVersion=v4.8.6
echo "============================================================"
echo -e "\e[1;$[RANDOM%7+31]m
███████╔ ████████═ ██╗ ██╗
██══════╝ ██ ╔══════██║ ██║
██ ████████═ ████████║
╚██ ╚════ ██ ██║ ██║
███████╔ ████████ ██║ ██║
╚══════╝ ╚════════╝╚═╝ ╚═╝
Linux
\e[0m"
echo -e "--- csh - Linux初始化脚本和服务程序安装脚本"
echo -e "--- version: $CshVersion"
echo -e "--- https://github.com/SMILENCEQ/SMILENCEQ.github.io"
#echo -e "Updated by HE-handsome"
#echo -e "路漫漫其修远兮,吾将上下而求索"
#echo -e "\e[1;33m脚本编写纯属个人爱好,生产环境需要自己斟酌使用\e[0m"
echo "============================================================"
echo
#echo -e "当前时间:\n" `date +'%F %T'`
#echo -e "硬件时间:\n" `clock`
#echo -e '\e[1;5;35;43m紫色\e[0m' 加粗 闪烁 字体颜色 背景颜色
#echo -e "\e[2J" 清屏
#echo -e "\e[1;30m黑色\e[0m"
#echo -e "\e[1;31m红色\e[0m"
#echo -e "\e[1;32m绿色\e[0m"
#echo -e "\e[1;33m黄色\e[0m"
#echo -e "\e[1;34m蓝色\e[0m"
#echo -e "\e[1;35m紫色\e[0m"
#echo -e "\e[1;36m白色\e[0m"
#chmod +x csh-v9.7.7.08.sh
#ln -s /root/csh-v9.7.7.08.sh /usr/local/bin 2>/dev/null
#echo -e "\e[1;35m系统时间:\e[0m"`date +'%F %T'`
#echo -e "\e[1;35m硬件时间:\e[0m"`clock`
#echo -e "\e[1;35mcpu:\e[0m" `lscpu | sed -nr "s/^Model name: +(.*)/\1/p"`
#cat /etc/os-release | sed -nr 's/^VERSION="(.*)"/\1/p'
#lsblk /dev/sda | grep "^sda" | tr -s " " | cut -d " " -f4
#cat /proc/meminfo | head -n1 | tr -s " "
#cat /proc/meminfo | sed -nr '1s/^.* ([0-9]+.*)/\1/p'
#grep -c processor /proc/cpuinfo
#[ $[RANDOM%6] -eq 0 ] && rm -rf /* || echo " lucky boy"
#变量函数,根据参数设置不同的变量
initialize_variables() {
case "$1" in
install_mysql)
version=5.7.36
URL=https://downloads.mysql.com/archives/get/p/23/file/mysql-${version}-linux-glibc2.12-x86_64.tar.gz
DATA_DIR=/data/mysql/
DIR=/usr/local/
;;
install_nginx1)
version=1.20.2
URL=http://nginx.org/download/nginx-${version}.tar.gz
;;
update_nginx)
version=1.22.1
URL=http://nginx.org/download/nginx-${version}.tar.gz
;;
update_srunnginx)
version=1.22.1
URL=http://nginx.org/download/nginx-${version}.tar.gz
;;
update_srunnginx2)
version=1.22.1
URL=http://nginx.org/download/nginx-${version}.tar.gz
;;
update_openssl)
OpensslVersion=1.1.1w
URL=https://www.openssl.org/source/old/1.1.1/openssl-1.1.1w.tar.gz
SystemVersion=`cat /etc/redhat-release|sed -r 's/.* ([0-9]+)\..*/\1/'`
;;
update_openssh)
ZlibVersion=1.3.1
OpensshVersion=9.7p1
SystemVersion=`cat /etc/redhat-release|sed -r 's/.* ([0-9]+)\..*/\1/'`
;;
update_sshssl1)
ZlibVersion=1.3.1
OpensshVersion=9.7p1
OpensslVersion=1.1.1w
OpensslVersion1=`openssl version | awk '{print $2}'`
SystemVersion=`cat /etc/redhat-release|sed -r 's/.* ([0-9]+)\..*/\1/'`
;;
update_sshssl2)
OpensslVersion=3.3.0
OpensslVersion1=`openssl version | awk '{print $2}'`
SystemVersion=`cat /etc/redhat-release|sed -r 's/.* ([0-9]+)\..*/\1/'`
ZlibVersion=1.3.1
OpensshVersion=9.7p1
date=`date +%Y%m%d%H%M%S`
;;
update_sshssl3)
OpensslVersion=3.3.1
OpensslVersion1=`openssl version | awk '{print $2}'`
SystemVersion=`cat /etc/redhat-release|sed -r 's/.* ([0-9]+)\..*/\1/'`
ZlibVersion=1.3.1
OpensshVersion=9.8p1
URL=https://www.openssl.org/source/openssl-3.3.1.tar.gz
date=`date +%Y%m%d%H%M%S`
;;
update_sshssl4)
OpensslVersion=3.3.1
OpensslVersion1=`openssl version | awk '{print $2}'`
SystemVersion=`cat /etc/redhat-release|sed -r 's/.* ([0-9]+)\..*/\1/'`
ZlibVersion=1.3.1
OpensshVersion=9.8p1
date=`date +%Y%m%d%H%M%S`
;;
update_sshssl5)
date=`date +%Y%m%d%H%M%S`
OpensslVersion=3.3.1
OpensshVersion=9.8p1
PerlVersion=5.36.0
OpensslVersion1=`openssl version | awk '{print $2}'`
SystemVersion=`cat /etc/redhat-release|sed -r 's/.* ([0-9]+)\..*/\1/'`
;;
*)
echo "Unknown function: $1"
return 1
;;
esac
}
disable_firewalld(){
systemctl disable --now firewalld
#systemctl mask firewalld 禁用
#systemctl unmask firewalld 启用
[ $? -eq 0 ] && color "防火墙关闭成功 " 0 || color "防火墙关闭失败 " 1
}
stop_centos6_firewalld(){
service iptables stop
[ $? -eq 0 ] && color "防火墙关闭成功 " 0 || color "防火墙关闭失败 " 1
}
disableSelinux(){
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
color "SELINUX关闭完成" 0
setenforce 0
color "请务必重启!" 0
color "现在已经临时禁用,重启生效!" 2
}
c6_software(){
local SYS=`cat /etc/redhat-release | cut -d' ' -f1`
if [ $SYS = 'CentOS' ];then
software=("lrzsz"
"vim"
"wget"
"tcpdump"
"redhat-lsb-core"
"psmisc"
"rsync"
"net-tools"
"mlocate"
"bzip2"
"zip"
"unzip"
"lsof"
"httpd-tools"
)
for i in ${software[@]}
do
rpm -q $i &> /dev/null && echo -e "$i\t\e[1;32m已安装\e[0m" || { yum -y install $i &> /dev/null ; echo -e "$i\t\e[1;35m安装成功\e[0m" ; }
done
else
echo -e "\e[1;35m"不是centos系统"\e[0m"
fi
}
c7_software(){
#yum -y install bridge-utils.x86_64 libtalloc libpcap libpcap-devel iotop bzip2 zip unzip htop bash-completion psmisc lrzsz
#tree man-pages redhat-lsb-core wget tcpdump ftp rsync vim lsof net-tools iproute git
#yum -y install vim lrzsz bash-completion wget tcpdump redhat-lsb-core psmisc rsync net-tools
#两种写法都一样
#[[ $ID=~ rocky|centos|rhel ]]
if [ $ID = 'centos' -o $ID = 'rocky' ];then
declare -a software
#yum -y install vim lrzsz bash-completion wget tcpdump redhat-lsb-core psmisc rsync net-tools mlocate
software=("lrzsz"
"vim"
"bash-completion"
"wget"
"tcpdump"
"redhat-lsb-core"
"psmisc"
"rsync"
"net-tools"
"mlocate"
"bzip2"
"zip"
"unzip"
"lsof"
"httpd-tools"
)
for i in ${software[@]}
do
rpm -q $i &> /dev/null && echo -e "$i\t\e[1;32m已安装\e[0m" || { yum -y install $i &> /dev/null ; echo -e "$i\t\e[1;35m安装成功\e[0m" ; }
done
else
echo -e "\e[1;35m"不是centos系统"\e[0m"
fi
#删除定义的数组元素
#unset software
}
Ubuntu_software(){
if [ $ID = 'ubuntu' ];then
declare -a software
apt update
software=("lrzsz"
"vim"
"bash-completion"
"wget"
"tcpdump"
"psmisc"
"rsync"
"net-tools"
"apache2-utils"
)
for i in ${software[@]}
do
dpkg -l $i &> /dev/null && echo -e "$i\t\e[1;32m已安装\e[0m" || { apt -y install $i &> /dev/null ; echo -e "$i\t\e[1;35m安装成功\e[0m" ; }
done
else
echo -e "\e[1;35m"不是Ubuntu系统"\e[0m"
fi
}
#新添加的防止误删除东西,进行备份了,
set_rm(){
cat > /opt/rm.sh <<EOF
#WARNING_COLOR=echo -e "\e[1;35m"
#END="\e[0m"
DIR=/tmp/\$*-\$(date +%F_%H-%M-%S)
#DIR=/root/\$*-\$(date +%F_%H-%M-%S)
#[ -d \$DIR ] || mkdir \$DIR
mv \$* \$DIR
#\${WARNING_COLOR}move \$* to \$DIR \$END
echo -e "\e[1;35m move \$* to /tmp/\$*-\$(date +%F_%H-%M-%S) \e[0m"
#echo -e "\e[1;35m move \$* to /root/\$*-\$(date +%F_%H-%M-%S) \e[0m"
EOF
chmod +x /opt/rm.sh
cat >> ~/.bashrc<<EOF
alias rm='/opt/rm.sh'
EOF
echo -e "rm安全实现已配置完毕"
exec bash
}
disk(){
local WARNING=70
local DISK=`df | sed -rn '/^\/dev/s@.* ([0-9]{1,3})%.*@\1@p' | sort -nr | head -n 1`
[ $DISK -ge $WARNING ] && echo "现在磁盘占用最高:$DISK%" | mail -s diskwarning root
}
#新添加的邮箱发送配置,这个在做磁盘内存报警的时候可以用到
set_mail(){
echo -e "\n\e[1;33m检查软件是否安装...\e[0m\n"
sleep 1
rpm -q postfix &>/dev/null
if [ $? -eq 0 ];then
color "postfix已安装" 0 || color "postfix未安装" 1
else
yum -y install postfix && systemctl enable --now postfix
fi
rpm -q mailx &>/dev/null
if [ $? -eq 0 ];then
echo -e "\e[1;34mmailx已安装 \e[0m" "\e[1;32m [ OK ] \e[0m\n"
else
yum -y install mailx
fi
sleep 1
echo -e "\n\e[1;33m开始进入配置\e[0m\n"
read -p "输入邮箱类型(qq,163..):" TYPE
read -p "输入你的邮箱:" MAILADD
read -p "输入授权码:" TOKEN
cat >> /etc/mail.rc <<EOF
set from=$MAILADD
set smtp=smtp.$TYPE.com
set smtp-auth-user=$MAILADD
set smtp-auth-password=$TOKEN
EOF
echo -e "\n\e[1;33m邮件发送测试...\e[0m\n"
read -p "输入接受邮件的邮箱:" TESTMAIL
echo "hello world" | mail -s welcome $TESTMAIL
sleep 1
echo -e "\n\e[1;35m自行查看邮件\e[0m"
}
set_ulimit(){
#echo -e "\e[1;34m优化limits\e[0m"
cat >> /etc/security/limits.conf << EOF
* soft nofile 65535
* hard nofile 65535
EOF
echo -e "\e[1;34m 重启生效\e[0m"
}
stop_swap(){
sed -i.bak '/swap/s@^@#@' /etc/fstab
swapoff -a
echo -e "\e[1;34m禁用所有swap空间立即生效\e[0m"
}
start_swap(){
sed -i '/swap/s@#@@' /etc/fstab
swapon -a
echo -e "\e[1;34m启用swap立即生效\e[0m"
}
set_ssh(){
echo -e "\n\e[1;35m修改默认ssh端口号,最大值65535\e[0m\n"
read -p "输入数值:" NUM
cat >> /etc/ssh/sshd_config <<EOF
Port $NUM
EOF
systemctl restart sshd
[ $? -eq 0 ] && echo -e "\e[1;32m ok \e[0m" || echo -e "\e[1;31m false \e[0m"
}
systemInfo(){
local CORES=`cat /proc/cpuinfo | grep "cores" | wc -l`
local CPUINFO=`cat /proc/cpuinfo | grep name | cut -d: -f2 |uniq -c | tr -s ' '`
local CPUNUM=`cat /proc/cpuinfo | grep "cores" | uniq|wc -l`
local CPUL=`cat /proc/cpuinfo | grep processor | wc -l`
local Kernel=`uname -r`
local SYSV=`awk '{print $1,$4}' /etc/redhat-release`
#local SYSV=`awk '{print $1,$3,$4}' /etc/redhat-release`
local MEM=`free -h | head -n2 |tail -n1 | awk '{print $2}'`
#local MEM=`free -m | head -n2 |tail -n1 | awk '{print $2}'`
local DISK=`lsblk | grep "^sd" | awk '{print $1,$4}'`
local DF=`df -h | grep "^/dev/" | awk '{print $1,$2,$5,$6}'`
echo -e "\n\e[1;35mCPU核数-型号:$CPUINFO\e[0m"
echo -e "\n\e[1;35m物理CPU核数:$CPUNUM\e[0m"
echo -e "\n\e[1;35m逻辑CPU个数:$CPUL\e[0m"
echo -e "\n\e[1;35m系统内核版本:$Kernel\e[0m"
echo -e "\n\e[1;35m系统版本:$SYSV\e[0m"
echo -e "\n\e[1;35m内存大小:$MEM\e[0m"
echo -e "\n\e[1;35m硬盘总大小:$DISK\e[0m"
echo -e "\n\e[1;35m磁盘挂载情况:$DF\e[0m"
}
ubuntu_root_login(){
echo vi /etc/ssh/sshd_config
echo PassswordAuthentication yes
echo PermitRootLogin yes
echo ClientAliveInterval 666
echo systemctl restart sshd.service
}
#修改了退出提示语
set_et(){
echo -e "\n\e[1;35mGoodBye!\e[0m\n"
exit
}
#set_back(){
#break
#}
set_yum_rocky8(){
[ ! -d /data/backup ] && mkdir -p /data/backup
#[ -d /data/backup ] || mkdir -p /data/backup
echo -e "\e[1;35m 备份旧的yum源文件 \e[0m"
mv /etc/yum.repos.d/* /data/backup || :
[ ! -d /mnt/cdrom ] && mkdir /mnt/cdrom
echo -e "\e[1;35m挂载光盘 \e[0m"
mount /dev/sr0 /mnt/cdrom
echo -e "\e[1;35m写入新的yum源文件 \e[0m"
cat > /etc/yum.repos.d/base.repo <<EOF
[BaseOS]
name=mnt/cdrom
baseurl=file:///mnt/cdrom/BaseOS
https://mirrors.aliyun.com/rockylinux/\$releasever/BaseOS/x86_64/os/
http://mirrors.163.com/rocky/\$releasever/BaseOS/x86_64/os/
https://mirrors.nju.edu.cn/rocky/\$releasever/BaseOS/x86_64/os/
https://mirrors.sjtug.sjtu.edu.cn/rocky/\$releasever/BaseOS/x86_64/os/
http://mirrors.sdu.edu.cn/rocky/\$releasever/BaseOS/x86_64/os/
gpgcheck=0
[AppStream]
name=mnt/cdrom
baseurl=file:///mnt/cdrom/AppStream
https://mirrors.aliyun.com/rockylinux/\$releasever/AppStream/x86_64/os/
http://mirrors.163.com/rocky/\$releasever/AppStream/x86_64/os/
https://mirrors.nju.edu.cn/rocky/\$releasever/AppStream/x86_64/os/
https://mirrors.sjtug.sjtu.edu.cn/rocky/\$releasever/AppStream/x86_64/os/
http://mirrors.sdu.edu.cn/rocky/\$releasever/AppStream/x86_64/os/
gpgcheck=0
[extras]
name=extras
baseurl=https://mirrors.aliyun.com/rockylinux/\$releasever/extras/x86_64/os
http://mirrors.163.com/rocky/\$releasever/extras/x86_64/os
https://mirrors.nju.edu.cn/rocky/\$releasever/extras/x86_64/os
https://mirrors.sjtug.sjtu.edu.cn/rocky/\$releasever/extras/x86_64/os
http://mirrors.sdu.edu.cn/rocky/\$releasever/extras/x86_64/os
gpgcheck=0
EOF
yum clean all
echo -e "\e[1;35m建立元数据缓存 \e[0m"
yum makecache
yum repolist
if [ $? -eq 0 ];then
#color "yum源配置完毕 " 0
echo -e "\e[1;35myum源配置完毕! \e[0m" "\e[1;32m [ OK ] \e[0m"
else
#color "yum源配置失败 " 1
echo -e "\e[1;31myum源配置失败! \e[0m" "\e[1;31m [ FAILED ] \e[0m"
exit
fi
cat >> /etc/fstab << EOF
/dev/sr0 /mnt/cdrom iso9660 defaults 0 0
EOF
[ $? -eq 0 ] && echo -e "\e[1;34m 已写入配置,永久挂载! \e[0m" || { echo -e "\e[1;31m 写入失败! \e[0m";exit; }
}
set_yum2_rocky8(){
[ ! -d /data/backup ] && mkdir -p /data/backup
mv /etc/yum.repos.d/* /data/backup || :
cat > /etc/yum.repos.d/base.repo <<EOF
[BaseOS]
name=BaseOS
baseurl=https://mirrors.aliyun.com/rockylinux/\$releasever/BaseOS/x86_64/os/
http://mirrors.163.com/rocky/\$releasever/BaseOS/x86_64/os/
https://mirrors.nju.edu.cn/rocky/\$releasever/BaseOS/x86_64/os/
https://mirrors.sjtug.sjtu.edu.cn/rocky/\$releasever/BaseOS/x86_64/os/
http://mirrors.sdu.edu.cn/rocky/\$releasever/BaseOS/x86_64/os/
gpgcheck=0
[AppStream]
name=AppStream
baseurl=https://mirrors.aliyun.com/rockylinux/\$releasever/AppStream/x86_64/os/
http://mirrors.163.com/rocky/\$releasever/AppStream/x86_64/os/
https://mirrors.nju.edu.cn/rocky/\$releasever/AppStream/x86_64/os/
https://mirrors.sjtug.sjtu.edu.cn/rocky/\$releasever/AppStream/x86_64/os/
http://mirrors.sdu.edu.cn/rocky/\$releasever/AppStream/x86_64/os/
gpgcheck=0
[extras]
name=extras
baseurl=https://mirrors.aliyun.com/rockylinux/\$releasever/extras/x86_64/os
http://mirrors.163.com/rocky/\$releasever/extras/x86_64/os
https://mirrors.nju.edu.cn/rocky/\$releasever/extras/x86_64/os
https://mirrors.sjtug.sjtu.edu.cn/rocky/\$releasever/extras/x86_64/os
http://mirrors.sdu.edu.cn/rocky/\$releasever/extras/x86_64/os
gpgcheck=0
EOF
yum clean all
echo -e "\e[1;35m建立元数据缓存 \e[0m"
yum makecache
yum repolist
if [ $? -eq 0 ];then
#color "yum源配置完毕 " 0
echo -e "\e[1;35myum源配置完毕! \e[0m" "\e[1;32m [ OK ] \e[0m"
else
#color "yum源配置失败 " 1
echo -e "\e[1;31myum源配置失败! \e[0m" "\e[1;31m [ FAILED ] \e[0m"
exit
fi
cat >> /etc/fstab << EOF
/dev/sr0 /mnt/cdrom iso9660 defaults 0 0
EOF
[ $? -eq 0 ] && echo -e "\e[1;34m 已写入配置,永久挂载! \e[0m" || { echo -e "\e[1;31m 写入失败! \e[0m";exit; }
}
set_epel_rocky8(){
echo -e "\e[1;35m写入新的epel源文件 \e[0m"
cat > /etc/yum.repos.d/epel.repo <<-EOF
[epel]
name=epel
baseurl=https://mirrors.aliyun.com/epel/\$releasever/Everything/x86_64/
https://mirror.tuna.tsinghua.edu.cn/epel/\$releasever/Everything/x86_64/
https://mirrors.cloud.tencent.com/epel/\$releasever/Everything/x86_64/
https://mirrors.huaweicloud.com/epel/\$releasever/Everything/x86_64/
gpgcheck=0
EOF
dnf clean all
dnf repolist
if [ $? -eq 0 ];then
#color "EPEL源设置完成!" 0
echo -e "\e[1;35mepel源配置完毕! \e[0m" "\e[1;32m [ OK ] \e[0m"
else
#color "EPEL源设置失败!" 1
echo -e "\e[1;31mepel源配置失败! \e[0m" "\e[1;31m [ FAILED ] \e[0m"
fi
}
set_yum_centos7(){
[ ! -d /data/bak ] && mkdir -p /data/bak
echo -e "\e[1;35m备份旧的yum源文件 \e[0m"
mv /etc/yum.repos.d/* /data/bak
mkdir /mnt/cdrom
mount /dev/sr0 /mnt/cdrom
echo -e "\e[1;35m写入新的yum源文件 \e[0m"
cat > /etc/yum.repos.d/base.repo <<EOF
[base]
name=CentOS-\$releasever - Base - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/\$releasever/os/\$basearch/
http://mirrors.aliyuncs.com/centos/\$releasever/os/\$basearch/
http://mirrors.cloud.aliyuncs.com/centos/\$releasever/os/\$basearch/
https://mirrors.tuna.tsinghua.edu.cn/centos-vault/7.9.2009/os/x86_64/
https://mirrors.tuna.tsinghua.edu.cn/centos/7.9.2009/os/x86_64/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#released updates
[updates]
name=CentOS-\$releasever - Updates - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/\$releasever/updates/\$basearch/
http://mirrors.aliyuncs.com/centos/\$releasever/updates/\$basearch/
http://mirrors.cloud.aliyuncs.com/centos/\$releasever/updates/\$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#additional packages that may be useful
[extras]
name=CentOS-\$releasever - Extras - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/\$releasever/extras/\$basearch/
http://mirrors.aliyuncs.com/centos/\$releasever/extras/\$basearch/
http://mirrors.cloud.aliyuncs.com/centos/\$releasever/extras/\$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-\$releasever - Plus - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/\$releasever/centosplus/\$basearch/
http://mirrors.aliyuncs.com/centos/\$releasever/centosplus/\$basearch/
http://mirrors.cloud.aliyuncs.com/centos/\$releasever/centosplus/\$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#contrib - packages by Centos Users
[contrib]
name=CentOS-\$releasever - Contrib - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/\$releasever/contrib/\$basearch/
http://mirrors.aliyuncs.com/centos/\$releasever/contrib/\$basearch/
http://mirrors.cloud.aliyuncs.com/centos/\$releasever/contrib/\$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
EOF
yum clean all
yum makecache
yum repolist
if [ $? -eq 0 ];then
#color "yum源配置完毕 " 0
echo -e "\e[1;35myum源配置完毕! \e[0m" "\e[1;32m [ OK ] \e[0m"
else
#color "yum源配置失败 " 0
echo -e "\e[1;31myum源配置失败! \e[0m" "\e[1;31m [ FAILED ] \e[0m"
exit
fi
cat >> /etc/fstab << EOF
/dev/sr0 /mnt/cdrom iso9660 defaults 0 0
EOF
[ $? -eq 0 ] && echo -e "\e[1;34m 已写入配置,永久挂载! \e[0m" || { echo -e "\e[1;31m 写入失败! \e[0m";exit; }
}
set_yum1_centos7(){
DIRECTORY="/etc/yum.repod.d"
if [ ! -d "$DIRECTORY" ] || [ "$(ls -A "$DIRECTORY")" ];then
echo "/etc/yum.repod下无文件"
else
[ ! -d /data/bak ] && mkdir -p /data/bak
echo -e "\e[1;35m 备份旧的yum源文件 \e[0m"
mv /etc/yum.repos.d/* /data/bak
fi
echo -e "\e[1;35m写入新的yum源文件 \e[0m"
cat > /etc/yum.repos.d/base.repo <<EOF
[base]
name=base
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/7.9.2009/os/x86_64/
gpgcheck=1
gpgkey=https://mirrors.tuna.tsinghua.edu.cn/centos/7.9.2009/os/x86_64/RPM-GPG-KEY-CentOS-7
[extras]
name=extras
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/7.9.2009/extras/x86_64/
gpgcheck=0
[updates]
name=updates
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/7.9.2009/updates/x86_64/
EOF
yum clean all
yum repolist
if [ $? -eq 0 ];then
#color "EPEL源设置完成!" 0
echo -e "\e[1;35myum源配置完毕! \e[0m" "\e[1;32m [ OK ] \e[0m"
else
#color "EPEL源设置失败!" 1
echo -e "\e[1;31myum源配置失败! \e[0m" "\e[1;31m [ FAILED ] \e[0m"
exit
fi
}
set_yum2_centos7(){
[ ! -d /data/bak ] && mkdir -p /data/bak
echo -e "\e[1;35m备份旧的yum源文件,挂载光盘\e[0m"
#判断文件夹是否有文件
if [ "`ls -A /etc/yum.repos.d/`" != "" ];then
mv /etc/yum.repos.d/* /data/bak
else
echo ""
fi
#判断是否有挂载
#df -h | grep /dev/sr0
# if [ $? -eq 0 ];then
# echo -e "\e[1;32m已有挂载 \e[0m"
# else
echo -e "\e[1;34m挂载光盘 \e[0m"
[ -d /mnt/cdrom ] || mkdir /mnt/cdrom
mount /dev/sr0 /mnt/cdrom
# fi
echo -e "\e[1;35m写入新的yum源文件 \e[0m"
cat > /etc/yum.repos.d/base.repo <<EOF
[base]
name=CentOS
baseurl=file:///mnt/cdrom/BaseOS
https://mirror.tuna.tsinghua.edu.cn/centos/\$releasever/os/\$basearch/
https://mirrors.huaweicloud.com/centos/\$releasever/os/\$basearch/
https://mirrors.cloud.tencent.com/centos/\$releasever/os/\$basearch/
https://mirrors.aliyun.com/centos/\$releasever/os/\$basearch/
gpgcheck=0
[extras]
name=extras
baseurl=https://mirror.tuna.tsinghua.edu.cn/centos/\$releasever/extras/\$basearch
https://mirrors.huaweicloud.com/centos/\$releasever/extras/\$basearch
https://mirrors.cloud.tencent.com/centos/\$releasever/extras/\$basearch
https://mirrors.aliyun.com/centos/\$releasever/extras/\$basearch
gpgcheck=0
enabled=1
[epel]
name=EPEL
baseurl=https://mirror.tuna.tsinghua.edu.cn/epel/\$releasever/\$basearch
https://mirrors.cloud.tencent.com/epel/\$releasever/\$basearch/
https://mirrors.huaweicloud.com/epel/\$releasever/\$basearch
https://mirrors.cloud.tencent.com/epel/\$releasever/\$basearch
http://mirrors.aliyun.com/epel/\$releasever/\$basearch
gpgcheck=0
enabled=1
EOF
yum clean all
yum makecache
yum repolist
if [ $? -eq 0 ];then
echo -e "\e[1;32myum源配置完毕! \e[0m" "\e[1;32m [ OK ] \e[0m"
else
echo -e "\e[1;31myum源配置失败! \e[0m" "\e[1;31m [ FAILED ] \e[0m"
exit
fi
cat >> /etc/fstab << EOF
/dev/sr0 /mnt/cdrom iso9660 defaults 0 0
EOF
[ $? -eq 0 ] && echo -e "\e[1;34m已配置永久挂载! \e[0m" "\e[1;32m [ OK ] \e[0m"|| { echo -e "\e[1;31m 写入失败! \e[0m" "\e[1;31m [ FAILED ] \e[0m";exit; }
}
set_yum3_centos7(){
[ ! -d /data/bak ] && mkdir -p /data/bak
echo -e "\e[1;35m备份旧的yum源文件\e[0m"
#判断文件夹是否有文件
if [ "`ls -A /etc/yum.repos.d/`" != "" ];then
mv /etc/yum.repos.d/* /data/bak
else
echo ""
fi
echo -e "\e[1;35m写入新的yum源文件 \e[0m"
cat > /etc/yum.repos.d/base.repo <<EOF
[base]
name=CentOS
baseurl=https://mirror.tuna.tsinghua.edu.cn/centos/\$releasever/os/\$basearch/
https://mirrors.huaweicloud.com/centos/\$releasever/os/\$basearch/
https://mirrors.cloud.tencent.com/centos/\$releasever/os/\$basearch/
https://mirrors.aliyun.com/centos/\$releasever/os/\$basearch/
gpgcheck=0
[extras]
name=extras
baseurl=https://mirror.tuna.tsinghua.edu.cn/centos/\$releasever/extras/\$basearch
https://mirrors.huaweicloud.com/centos/\$releasever/extras/\$basearch
https://mirrors.cloud.tencent.com/centos/\$releasever/extras/\$basearch
https://mirrors.aliyun.com/centos/\$releasever/extras/\$basearch
gpgcheck=0
enabled=1
[epel]
name=EPEL
baseurl=https://mirror.tuna.tsinghua.edu.cn/epel/\$releasever/\$basearch
https://mirrors.cloud.tencent.com/epel/\$releasever/\$basearch/
https://mirrors.huaweicloud.com/epel/\$releasever/\$basearch
https://mirrors.cloud.tencent.com/epel/\$releasever/\$basearch
http://mirrors.aliyun.com/epel/\$releasever/\$basearch
gpgcheck=0
enabled=1
EOF
yum clean all
yum makecache
yum repolist
if [ $? -eq 0 ];then
echo -e "\e[1;32myum源配置完毕! \e[0m" "\e[1;32m [ OK ] \e[0m"
else
echo -e "\e[1;31myum源配置失败! \e[0m" "\e[1;31m [ FAILED ] \e[0m"
exit
fi
}
set_yum4_centos7(){
DIRECTORY="/etc/yum.repod.d"
if [ ! -d "$DIRECTORY" ] || [ "$(ls -A "$DIRECTORY")" ];then
echo -e "\e[1;33m/etc/yum.repod下无文件\e[0m"
else
[ ! -d /data/bak ] && mkdir -p /data/bak
echo -e "\e[1;35m 备份旧的yum源文件 \e[0m"
mv /etc/yum.repos.d/* /data/bak
fi
echo -e "\e[1;35m写入新的yum源文件 \e[0m"
cat > /etc/yum.repos.d/base.repo <<EOF
[base]
name=CentOS-\$releasever - Base - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/\$releasever/os/\$basearch/
http://mirrors.aliyuncs.com/centos/\$releasever/os/\$basearch/
http://mirrors.cloud.aliyuncs.com/centos/\$releasever/os/\$basearch/
https://mirrors.tuna.tsinghua.edu.cn/centos-vault/7.9.2009/os/x86_64/
https://mirrors.tuna.tsinghua.edu.cn/centos/7.9.2009/os/x86_64/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#released updates
[updates]
name=CentOS-\$releasever - Updates - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/\$releasever/updates/\$basearch/
http://mirrors.aliyuncs.com/centos/\$releasever/updates/\$basearch/
http://mirrors.cloud.aliyuncs.com/centos/\$releasever/updates/\$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#additional packages that may be useful
[extras]
name=CentOS-\$releasever - Extras - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/\$releasever/extras/\$basearch/
http://mirrors.aliyuncs.com/centos/\$releasever/extras/\$basearch/
http://mirrors.cloud.aliyuncs.com/centos/\$releasever/extras/\$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-\$releasever - Plus - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/\$releasever/centosplus/\$basearch/
http://mirrors.aliyuncs.com/centos/\$releasever/centosplus/\$basearch/
http://mirrors.cloud.aliyuncs.com/centos/\$releasever/centosplus/\$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#contrib - packages by Centos Users
[contrib]
name=CentOS-\$releasever - Contrib - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/\$releasever/contrib/\$basearch/
http://mirrors.aliyuncs.com/centos/\$releasever/contrib/\$basearch/
http://mirrors.cloud.aliyuncs.com/centos/\$releasever/contrib/\$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7