-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcentos-init.sh
771 lines (700 loc) · 26.2 KB
/
centos-init.sh
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
#!/bin/bash
# curl https://movefeng.com/centos-init.sh | bash
# 可选参数: base kernel python php nodejs cmd_game jdk jenkins mysql57 mysql8 mongodb docker golang
# 比如
# curl https://movefeng.com/centos-init.sh | bash -s base
# curl https://movefeng.com/centos-init.sh | bash -s python php nodejs cmd_game jdk mysql8 mongodb docker
function system_config() {
# 修改主机名
#hostnamectl set-hostname aaa
# 禁用selinux
sed -i 's/SELINUX=.*/SELINUX=permissive/g' /etc/selinux/config
setenforce 0
# 修改开机引导等待时间
sed -i 's/GRUB_TIMEOUT=.*/GRUB_TIMEOUT=2/g' /etc/default/grub
grub2-mkconfig -o /boot/grub2/grub.cfg
# 请根据具体情况来决定是否关闭防火墙
systemctl stop firewalld
systemctl disable firewalld
}
function config_mirror_and_update() {
MIRROR="https://mirrors.aliyun.com"
#更换yum源
cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
#curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
sed -i "s@#baseurl@baseurl@g" /etc/yum.repos.d/CentOS-Base.repo
sed -i "s@mirrorlist=http@#mirrorlist=http@g" /etc/yum.repos.d/CentOS-Base.repo
sed -i "s@baseurl=.*/centos@baseurl=$MIRROR/centos@g" /etc/yum.repos.d/CentOS-Base.repo
yum makecache
#同步时间
yum install -y ntpdate
ntpdate time.windows.com
#配置EPEL源
#EPEL (Extra Packages for Enterprise Linux) 是由 Fedora Special Interest Group 为企业 Linux 创建、维护和管理的一个高质量附加包集合,适用于但不仅限于 Red Hat Enterprise Linux (RHEL), CentOS, Scientific Linux (SL), Oracle Linux (OL)
yum install -y epel-release
cp /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo.backup
cp /etc/yum.repos.d/epel-testing.repo /etc/yum.repos.d/epel-testing.repo.backup
# curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
sed -i "s@#baseurl@baseurl@g" /etc/yum.repos.d/epel.repo
sed -i "s@metalink@#metalink@g" /etc/yum.repos.d/epel.repo
sed -i "s@baseurl.*=.*/epel@baseurl=$MIRROR/epel@g" /etc/yum.repos.d/epel.repo
#配置ius源 https://ius.io/ #IUS只为RHEL和CentOS这两个发行版提供较新版本的rpm包。如果在os或epel找不到某个软件的新版rpm,软件官方又只提供源代码包的时候,可以来ius源中找,几乎都能找到。比如,python3.6(包括对应版本的pip,epel源里有python3.6但没有对应版本的pip),php7.2,redis5等等
# https://mirrors.aliyun.com https://mirrors.tuna.tsinghua.edu.cn
IUS_MIRROR=https://mirrors.aliyun.com/ius
yum install -y https://centos7.iuscommunity.org/ius-release.rpm
sed -i "s@baseurl.*=.*/7@baseurl=$IUS_MIRROR/7@g" /etc/yum.repos.d/ius.repo
yum makecache
yum update -y
#一些实用工具,这些大部分在EPEL源里
yum install bash-completion git2u wget hdparm tree zip unzip vim emacs nano yum-utils unar screen lrzsz supervisor iotop iftop jnettop apachetop atop htop ncdu nmap pv net-tools sl lynx links crudini the_silver_searcher tig cloc nload w3m axel tmux mc glances multitail redis5 lftp vsftpd iptraf nethogs goacess socat -y
cat >> ~/.bashrc <<- "EOF"
alias top='top -c'
alias historygrep='history|grep $1'
alias port='netstat -apn|grep $1'
alias iftop='iftop -B -i $1'
EOF
# 本地端口扫描脚本
cat > /usr/local/bin/scanPort <<- "EOF"
if [[ -z $* ]]; then
echo "命令格式:
scanPort 8080 -> 检查8080端口是否被占用
scanPort 8080 8090 -> 检查8080到8090范围的端口是否被占用"
else
if [[ $# -gt 1 ]]; then
for ((i = $1; i <= $2; i++)); do
netstat -apn | grep "${i}"
done
else
netstat -apn | grep "$1"
fi
fi
EOF
chmod 755 /usr/local/bin/scanPort
source ~/.bashrc
# vim配置
cat >> ~/.vimrc <<- "EOF"
syntax on " 开启语法高亮,从vim7升级到vim8,语法高亮失效时加上
" 记住上次编辑和浏览位置, yum源安装的vim7默认有这个功能,但自己编译的vim8默认没有这个功能
if has("autocmd")
au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
endif
" tab设置为4个空格
set ts=4
set expandtab
set pastetoggle=<F9>
set fo-=r " 关闭自动注释
set paste
set backspace=2
EOF
}
# 更新内核为主分支ml(mainline)版本
function update_kernel() {
rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm
sed -i "s/mirrorlist=http/#mirrorlist=http/g" /etc/yum.repos.d/elrepo.repo
crudini --set /etc/yum.repos.d/elrepo.repo elrepo baseurl "https://mirrors.tuna.tsinghua.edu.cn/elrepo/elrepo/el7/\$basearch"
crudini --set /etc/yum.repos.d/elrepo.repo elrepo-testing baseurl "https://mirrors.tuna.tsinghua.edu.cn/elrepo/testing/el7/\$basearch"
crudini --set /etc/yum.repos.d/elrepo.repo elrepo-kernel baseurl "https://mirrors.tuna.tsinghua.edu.cn/elrepo/kernel/el7/\$basearch/"
crudini --set /etc/yum.repos.d/elrepo.repo elrepo-extras baseurl "https://mirrors.tuna.tsinghua.edu.cn/elrepo/extras/el7/\$basearch/"
yum-config-manager --enable elrepo-kernel
yum install kernel-ml-devel kernel-ml -y
KERNEL_VERSION=$(yum list kernel-ml | grep kernel.*@elrepo-kernel | awk -F ' ' '{print $2}')
GRUB_ITEM=$(awk -F\' '$1=="menuentry " {print $2}' /etc/grub2.cfg | grep "CentOS Linux (${KERNEL_VERSION}) 7 (Core)")
echo "${KERNEL_VERSION}"
echo "${GRUB_ITEM}"
grub2-set-default "${GRUB_ITEM}"
echo '请重启后执行uname -r查看是否生效'
}
function change_mirror(){
echo "
1.阿里云
2.华为云
3.清华大学开源镜像站
4.中国科技大学开源镜像站
5.腾讯云
"
read -a MIRROR -p "请输入数字:"
case ${MIRROR} in
1)
MIRROR="https://mirrors.aliyun.com"
;;
2)
MIRROR="https://mirrors.huaweicloud.com"
;;
3)
MIRROR="https://mirrors.tuna.tsinghua.edu.cn"
;;
4)
MIRROR="https://mirrors.ustc.edu.cn"
;;
5)
MIRROR="https://mirrors.cloud.tencent.com"
;;
*)
echo "输入错误"
;;
esac
if [[ -s /etc/yum.repos.d/CentOS-Base.repo ]];then
sed -i "s@#baseurl@baseurl@g" /etc/yum.repos.d/CentOS-Base.repo
sed -i "s@mirrorlist=http@#mirrorlist=http@g" /etc/yum.repos.d/CentOS-Base.repo
sed -i "s@baseurl=.*/centos@baseurl=$MIRROR/centos@g" /etc/yum.repos.d/CentOS-Base.repo
echo "Base源配置成功"
fi
if [[ -s /etc/yum.repos.d/epel.repo ]];then
sed -i "s@#baseurl@baseurl@g" /etc/yum.repos.d/epel.repo
sed -i "s@metalink@#metalink@g" /etc/yum.repos.d/epel.repo
sed -i "s@baseurl=.*/epel@baseurl=$MIRROR/epel@g" /etc/yum.repos.d/epel.repo
echo "epel源配置成功"
else
echo "epel源不存在,即将安装 epel-release ..."
yum install -y epel-release
sed -i "s@baseurl=.*/epel@baseurl=$MIRROR/epel@g" /etc/yum.repos.d/epel.repo
sed -i "s@#baseurl@baseurl@g" /etc/yum.repos.d/epel.repo
sed -i "s@metalink@#metalink@g" /etc/yum.repos.d/epel.repo
fi
if [[ -s /etc/yum.repos.d/ius.repo ]];then
sed -i "s@baseurl.*=.*/7@baseurl=$MIRROR/ius/7@g" /etc/yum.repos.d/ius.repo
echo "ius源配置成功"
else
echo "ius源不存在,即将安装 ius-release ..."
yum install -y https://centos7.iuscommunity.org/ius-release.rpm
sed -i "s@baseurl.*=.*/7@baseurl=$MIRROR/ius/7@g" /etc/yum.repos.d/ius.repo
fi
}
function install_python() {
# python3.6,包括对应版本的pip,从CentOS 7.7开始,base源内置python3.6版本,无需再从ius源安装
yum install python3-pip -y
# 使用国内pypi源
# 备选:https://pypi.douban.com/simple/ https://pypi.tuna.tsinghua.edu.cn/simple/ https://mirrors.aliyun.com/pypi/simple/
# 手动创建配置文件的方式
# mkdir -p ~/.pip
# cat > ~/.pip/pip.conf <<- "EOF"
# [global]
# index-url = https://mirrors.aliyun.com/pypi/simple/
# [install]
# trusted-host=mirrors.aliyun.com
# EOF
pip3 install -i https://mirrors.aliyun.com/pypi/simple/ pip -U
source /etc/profile
# 使用pip命令的方式配置
pip3 config set global.index-url https://mirrors.aliyun.com/pypi/simple/
pip3 install --upgrade pip
# 一些基于python的实用或者有意思的工具
pip3 install virtualenv cheat mycli icdiff you-get lolcat youtube-dl speedtest-cli supervisor gixy cowsay docker-compose
# pip 命令自动补全
pip3 completion --bash >> /etc/profile
source /etc/profile
}
function install_golang() {
# golang 稳定版
golang_version=$(curl https://golang.google.cn/dl/ | tr -d '\n'| grep -oP 'Stable.*' | grep -oP 'go[0-9|a-z|.]*linux-amd64.tar.gz' | sort -rV | xargs | awk -F ' ' '{print $1}')
echo ${golang_version}
cd /usr
wget https://dl.google.com/go/${golang_version}
tar -zxf ${golang_version}
echo "export PATH=\$PATH:/usr/go/bin" >> /etc/profile
source /etc/profile
go version
}
function install_php() {
yum install php72u* nginx httpd -y
systemctl start php-fpm.service
systemctl enable php-fpm.service
}
function install_nodejs_and_config() {
#配置nodejs的yum源,安装 nodejs (epel源里有nodejs,但版本比较老),使用清华大学的源
yum install https://mirrors.tuna.tsinghua.edu.cn/nodesource/rpm_12.x/el/7/x86_64/nodesource-release-el7-1.noarch.rpm -y
cat > /etc/yum.repos.d/nodesource-el7.repo <<- "EOF"
[nodesource]
name=Node.js Packages for Enterprise Linux 7 - $basearch
baseurl=https://mirrors.tuna.tsinghua.edu.cn/nodesource/rpm_12.x/el/7/$basearch
enabled=1
gpgcheck=0
[nodesource-source]
name=Node.js for Enterprise Linux 7 - $basearch - Source
baseurl=https://mirrors.tuna.tsinghua.edu.cn/nodesource/rpm_12.x/el/7/SRPMS
enabled=0
gpgcheck=1
EOF
yum makecache
yum install nodejs -y
# 更换国内npm源
npm config set registry https://registry.npm.taobao.org/
npm config set sass_binary_site https://npm.taobao.org/mirrors/node-sass/
npm config set electron_mirror https://npm.taobao.org/mirrors/electron/
npm config set phantomjs_cdnurl https://npm.taobao.org/mirrors/phantomjs/
npm config set chromedriver_cdnurl http://npm.taobao.org/mirrors/chromedriver/
# 备选:npm config set registry https://mirrors.huaweicloud.com/repository/npm/
# npm config set registry https://registry.npm.taobao.org/
npm cache clean -f
# npm 命令 tab 补全配置
npm completion >> /etc/bash_completion.d/npm
# 一些基于nodejs的实用或者有意思的工具
npm install n npm get-port-cli hasha-cli http-server live-server prettier -g
# 使用n管理node版本,使用淘宝镜像源
export NODE_MIRROR=https://npm.taobao.org/mirrors/node/
echo "export NODE_MIRROR=https://npm.taobao.org/mirrors/node/" >> /etc/profile
source /etc/profile
n latest
# n stable
# 安装yarn
curl --silent --location https://dl.yarnpkg.com/rpm/yarn.repo | sudo tee /etc/yum.repos.d/yarn.repo
yum install yarn -y
}
#命令行小游戏
function install_cmd_game() {
cd ~
# 2048
curl https://raw.githubusercontent.com/mydzor/bash2048/master/bash2048.sh -o 2048.sh && chmod 755 2048.sh
# 扫雷
curl https://raw.githubusercontent.com/feherke/Bash-script/master/minesweeper/minesweeper.sh -o minesweeper.sh && chmod 755 minesweeper.sh
# 俄罗斯方块
git clone https://github.com/uuner/sedtris.git
chmod 755 sedtris/*
# ./sedtris/sedtris.sh
}
#安装jdk和tomcat
function install_tomcat_and_maven() {
#安装openjdk
# jdk 11
yum install java-11-openjdk-devel.x86_64 -y
# jdk 1.8
# yum install java-1.8.0-openjdk-devel.x86_64 -y
ln -s /usr/lib/jvm/java-11/bin/java /bin/java11
#或者 oraclejdk
# wget https://mirrors.huaweicloud.com/java/jdk/8u202-b08/jdk-8u202-linux-x64.tar.gz
# tar -zxvf jdk-8u202-linux-x64.tar.gz -C /usr/
# cat >> /etc/profile <<- "EOF"
# export JAVA_HOME=/usr/jdk1.8.0_202
# export PATH=$JAVA_HOME/bin:$PATH
# export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
# EOF
# source /etc/profile
#安装tomcat9
#https://tomcat.apache.org/download-90.cgi 注:请随时关注官网的最新版本,新版本发布后旧版本的链接会失效!
cd /usr
TOMCAT_VERSION=$(lftp https://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-9/ -e "cls;bye" | awk -F '/' '{print $1}' | awk -F 'v' '{print $2}' | xargs | awk -F ' ' '{print $2}')
if [[ -z ${TOMCAT_VERSION} ]]; then
TOMCAT_VERSION=$(lftp https://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-9/ -e "cls;bye" | awk -F '/' '{print $1}' | awk -F 'v' '{print $2}' | xargs | awk -F ' ' '{print $1}')
fi
wget https://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-9/v${TOMCAT_VERSION}/bin/apache-tomcat-${TOMCAT_VERSION}.tar.gz
tar -zxf apache-tomcat-${TOMCAT_VERSION}.tar.gz
cat > /usr/lib/systemd/system/tomcat.service <<- "EOF"
[Unit]
Description=Tomcat-9.0.17
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
Environment='CATALINA_OPTS=-Xms128M -Xmx512M -server -XX:+UseParallelGC'
WorkingDirectory=/usr/apache-tomcat-9.0.17
ExecStart=/usr/apache-tomcat-9.0.17/bin/startup.sh
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
EOF
sed -i "s:Description=Tomcat-.*:Description=Tomcat-${TOMCAT_VERSION}:g" /usr/lib/systemd/system/tomcat.service
sed -i "s:WorkingDirectory=/usr/apache-tomcat-.*:WorkingDirectory=/usr/apache-tomcat-${TOMCAT_VERSION}:g" /usr/lib/systemd/system/tomcat.service
sed -i "s:ExecStart=/usr/apache-tomcat-.*:ExecStart=/usr/apache-tomcat-${TOMCAT_VERSION}/bin/startup.sh:g" /usr/lib/systemd/system/tomcat.service
systemctl daemon-reload
systemctl start tomcat
#安装maven
MAVEN_VERSION=$(lftp https://mirrors.tuna.tsinghua.edu.cn/apache/maven/maven-3/ -e "cls;bye" | sort -rV | xargs | awk -F ' ' '{print $1}' | awk -F '/' '{print $1}')
wget https://mirrors.tuna.tsinghua.edu.cn/apache/maven/maven-3/${MAVEN_VERSION}/binaries/apache-maven-${MAVEN_VERSION}-bin.tar.gz
tar -zxvf apache-maven-${MAVEN_VERSION}-bin.tar.gz
cat >> /etc/profile <<- "EOF"
export M2_HOME=/usr/apache-maven-3.6
export PATH=$M2_HOME/bin:$PATH
EOF
sed -i "s:M2_HOME=.*:M2_HOME=/usr/apache-maven-${MAVEN_VERSION}:g" /etc/profile
source /etc/profile
mvn
mkdir -p ~/.m2
# 创建maven配置文件,并配置阿里云的maven源
cat > ~/.m2/settings.xml <<- "EOF"
<?xml version="1.0" encoding="UTF-8"?>
<settings
xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<pluginGroups></pluginGroups>
<proxies></proxies>
<servers></servers>
<mirrors>
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
<profiles></profiles>
</settings>
EOF
}
# 安装Jenkins
function install_jenkins() {
jenkins=$(lftp https://mirrors.huaweicloud.com/jenkins/redhat-stable/ -e "cls;bye"|sort -rV|xargs | awk -F ' ' '{print $1}')
yum install https://mirrors.huaweicloud.com/jenkins/redhat-stable/$jenkins -y
}
# 安装elasticsearch
function install_elasticsearch() {
echo "" > /etc/yum.repos.d/elasticsearch.repo
cat >> /etc/yum.repos.d/elasticsearch.repo <<- EOF
[elasticsearch]
name=elasticsearch
baseurl=https://mirrors.tuna.tsinghua.edu.cn/elasticstack/yum/elastic-7.x/
enabled=1
gpgcheck=0
EOF
yum makecache
yum install elasticsearch -y
}
#安装mysql5.7 http://mirrors.tuna.tsinghua.edu.cn/mysql,使用清华大学的源
function install_mysql57_and_config() {
cat > /etc/yum.repos.d/mysql-community.repo <<- "EOF"
[mysql-connectors-community]
name=MySQL Connectors Community
baseurl=http://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-connectors-community-el7
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[mysql-tools-community]
name=MySQL Tools Community
baseurl=http://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-tools-community-el7
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql57-community-el7
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[mysql80-community]
name=MySQL 8.0 Community Server
baseurl=http://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql80-community-el7
enabled=0
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
EOF
yum install mysql-community-server -y
#mysql配置
if [[ "${MYSQL_PASSWORD}" == "" ]];then
#root用户密码
MYSQL_PASSWORD=1111
fi
systemctl start mysqld
systemctl enable mysqld
passlog=$(grep 'temporary password' /var/log/mysqld.log)
pass=${passlog:${#passlog}-12:${#passlog}}
mysql -uroot -p"${pass}" -e"alter user root@localhost identified by 'QQQqqq111...' " --connect-expired-password
pass=QQQqqq111...
mysql -uroot -p"${pass}" -e"set global validate_password_policy=0;" --connect-expired-password
# mysql -uroot -p"${pass}" -e"set global validate_password.policy=0;" --connect-expired-password
mysql -uroot -p"${pass}" -e"set global validate_password_length=4;" --connect-expired-password
# mysql -uroot -p"${pass}" -e"set global validate_password.length=4;" --connect-expired-password
mysql -uroot -p"${pass}" -e"set global validate_password_mixed_case_count=0;" --connect-expired-password
# mysql -uroot -p"${pass}" -e"set global validate_password.mixed_case_count=0;" --connect-expired-password
mysql -uroot -p"${pass}" -e"set global validate_password_number_count=0;" --connect-expired-password
# mysql -uroot -p"${pass}" -e"set global validate_password.number_count=0;" --connect-expired-password
echo 'enter your mysql password'
#read password
# mysql -uroot -p"${pass}" -e"set password=password('${MYSQL_PASSWORD}');" --connect-expired-password
mysql -uroot -p"${pass}" -e"alter user 'root'@'localhost' identified with mysql_native_password by '${MYSQL_PASSWORD}';" --connect-expired-password
mysql -uroot -p"${MYSQL_PASSWORD}" -e"update mysql.user set host='%' where user='root';" --connect-expired-password
mysql -uroot -p"${MYSQL_PASSWORD}" -e"flush privileges;" --connect-expired-password
}
#安装mysql8 http://mirrors.tuna.tsinghua.edu.cn/mysql,使用清华大学的源
function install_mysql8_and_config() {
cat > /etc/yum.repos.d/mysql-community.repo <<- "EOF"
[mysql-connectors-community]
name=MySQL Connectors Community
baseurl=http://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-connectors-community-el7
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[mysql-tools-community]
name=MySQL Tools Community
baseurl=http://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-tools-community-el7
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql57-community-el7
enabled=0
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[mysql80-community]
name=MySQL 8.0 Community Server
baseurl=http://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql80-community-el7
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
EOF
yum install mysql-community-server -y
#mysql配置
if [[ "${MYSQL_PASSWORD}" == "" ]];then
#root用户密码
MYSQL_PASSWORD=1111
fi
systemctl start mysqld
systemctl enable mysqld
passlog=$(grep 'temporary password' /var/log/mysqld.log)
pass=${passlog:${#passlog}-12:${#passlog}}
mysql -uroot -p"${pass}" -e"alter user root@localhost identified by 'QQQqqq111...' " --connect-expired-password
pass=QQQqqq111...
mysql -uroot -p"${pass}" -e"set global validate_password.policy=0;" --connect-expired-password
mysql -uroot -p"${pass}" -e"set global validate_password.length=4;" --connect-expired-password
mysql -uroot -p"${pass}" -e"set global validate_password.mixed_case_count=0;" --connect-expired-password
mysql -uroot -p"${pass}" -e"set global validate_password.number_count=0;" --connect-expired-password
#echo 'enter your mysql password'
#read password
# mysql -uroot -p"${pass}" -e"set password=password('${MYSQL_PASSWORD}');" --connect-expired-password
mysql -uroot -p"${pass}" -e"alter user 'root'@'localhost' identified with mysql_native_password by '${MYSQL_PASSWORD}';" --connect-expired-password
mysql -uroot -p"${MYSQL_PASSWORD}" -e"update mysql.user set host='%' where user='root';" --connect-expired-password
mysql -uroot -p"${MYSQL_PASSWORD}" -e"flush privileges;" --connect-expired-password
}
#安装mongodb,使用阿里云的源
function install_mongodb() {
echo "" > /etc/yum.repos.d/mongodb.repo
for version in "3.7" "4.2"; do
cat >> /etc/yum.repos.d/mongodb.repo <<- EOF
[mongodb-org-$version]
name=MongoDB Repository
baseurl=https://mirrors.aliyun.com/mongodb/yum/redhat/7/mongodb-org/$version/x86_64
gpgcheck=0
enabled=1
EOF
done
yum makecache
yum install mongodb-org -y
}
#安装docker
function install_docker() {
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
sed -i "s@https://download.docker.com@https://mirrors.aliyun.com/docker-ce@g" /etc/yum.repos.d/docker-ce.repo
yum install docker-ce -y
systemctl start docker
#配置国内docker加速器
cat > /etc/docker/daemon.json <<- "EOF"
{
"registry-mirrors": ["https://registry.docker-cn.com"]
}
EOF
systemctl restart docker
}
# 如果不指定参数,则执行所有功能模块
if [[ -z $* ]]; then
echo "
脚本执行后会:
修改yum源 (base源和epel源默认为 https://mirrors.huaweicloud.com
其他源是 https://mirrors.tuna.tsinghua.edu.cn
)
安装一些生产环境可能必备的软件:
OpenJDK 1.8
Apache Tomcat 9
MySQL 8(不加参数默认为8)
mongodb-org 4
Redis 5
docker-ce
Python36-pip(python3.6会作为依赖被安装)
PHP 7.2(Apache httpd会作为依赖被安装)
golang 稳定版
配置MySQL
默认开启远程访问,root默认密码为1111
如需修改默认密码,执行之前修改脚本中的MYSQL_PASSWORD变量的值即可
或者执行前先导入MYSQL_PASSWORD变量
export MYSQL_PASSWORD=your_password
将pip源更换成国内源
默认是 http://mirrors.aliyun.com/pypi/simple/
将npm源更换成国内源
默认是 淘宝 NPM 镜像
修改docker镜像源
默认是 https://registry.docker-cn.com
安装一些实用的命令行工具:
通过yum安装的:
bash-completion git wget vim nano yum-utils unar screen lrzsz supervisor iotop iftop jnettop mytop apachetop atop htop ncdu nmap pv net-tools sl lynx links crudini the_silver_searcher tig cloc nload w3m axel tmux mc glances multitail
通过pip安装的:
cheat mycli icdiff you-get lolcat youtube-dl
通过npm安装的:
get-port-cli hasha-cli http-server
安装几个基于命令行的小游戏:
2048
扫雷
俄罗斯方块
参数:
c 切换yum源
all 等于以下所有参数
base 配置yum源以及安装一些基础软件
kernel 更新内核为主分支ml,即5.x 版本
python 安装python3.6 和 pip,以及一些在pypi上发布的软件包
nodejs 安装nodejs,以及一些基于npm发布的软件包
php 安装php7.2,附带安装nginx、apache
java 安装jdk1.8和jdk11,以及tomcat9和maven
jenkins 安装Jenkins
elasticsearch 安装elasticsearch
golang 安装golang
mysql57 安装mysql5.7,默认密码是1111
mysql8 安装mysql8,默认密码是1111
mongodb 安装mongodb
docker 安装docker
"
echo "可选参数 all(执行所有模块) base kernel python php nodejs cmd_game jdk jenkins mysql57 mysql8 mongodb docker"
else
if [[ $# -gt 1 ]]; then
system_config
config_mirror_and_update
for arg in $* ; do
case ${arg} in
all)
config_mirror_and_update
install_python
install_php
install_nodejs_and_config
install_golang
install_tomcat_and_maven
install_jenkins
install_elasticsearch
install_mysql8_and_config
install_mongodb
install_docker
install_cmd_game
;;
base)
system_config
config_mirror_and_update
;;
kernel)
update_kernel
;;
python)
install_python
;;
golang)
install_golang
;;
php)
install_php
;;
nodejs)
install_nodejs_and_config
;;
cmd_game)
install_cmd_game
;;
java)
install_tomcat_and_maven
;;
jenkins)
install_jenkins
;;
mysql57)
install_mysql57_and_config
;;
mysql8)
install_mysql8_and_config
;;
mongodb)
install_mongodb
;;
docker)
install_docker
;;
c)
change_mirror
;;
esac
done
else
case $1 in
all)
config_mirror_and_update
install_python
install_php
install_nodejs_and_config
install_golang
install_tomcat_and_maven
install_jenkins
install_elasticsearch
install_mysql8_and_config
install_mongodb
install_docker
;;
base)
system_config
config_mirror_and_update
;;
kernel)
system_config
config_mirror_and_update
update_kernel
;;
python)
system_config
config_mirror_and_update
install_python
;;
golang)
system_config
config_mirror_and_update
install_golang
;;
php)
system_config
config_mirror_and_update
install_php
;;
nodejs)
system_config
config_mirror_and_update
install_nodejs_and_config
;;
cmd_game)
system_config
config_mirror_and_update
install_cmd_game
;;
java)
system_config
config_mirror_and_update
install_tomcat_and_maven
;;
jenkins)
system_config
config_mirror_and_update
install_jenkins
;;
elasticsearch)
system_config
config_mirror_and_update
install_elasticsearch
;;
mysql57)
system_config
config_mirror_and_update
install_mysql57_and_config
;;
mysql8)
system_config
config_mirror_and_update
install_mysql8_and_config
;;
mongodb)
system_config
config_mirror_and_update
install_mongodb
;;
docker)
system_config
config_mirror_and_update
install_docker
;;
c)
change_mirror
;;
esac
fi
fi