#!/bin/bash
# curl https://yiyingcanfeng.github.io/centos-init.sh | bash
# 可选参数base kernel python php nodejs cmd_game jdk mysql mongodb docker
# 比如
# curl https://yiyingcanfeng.github.io/centos-init.sh | bash -s base function system_config() {
# 修改主机名
#hostnamectl set-hostname aaa
# 禁用selinux
sed -i 's/SELINUX=.*/SELINUX=permissive/g' /etc/selinux/config
setenforce
# 修改开机引导等待时间
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.huaweicloud.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
mv /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.(包括对应版本的pip,epel源里有python3.6但没有对应版本的pip),php7.,redis5等等
# https://mirrors.aliyun.com https://mirrors.tuna.tsinghua.edu.cn
cat > /etc/yum.repos.d/ius.repo <<- "EOF"
[ius]
name=ius
baseurl=https://mirrors.aliyun.com/ius/stable/CentOS/7/$basearch
gpgcheck=
enabled= EOF
yum makecache
yum update -y
#一些实用工具,这些大部分在EPEL源里
yum install -y bash-completion git2u 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 redis5 lftp vsftpd
} # 更新内核为主分支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\' '$=="menuentry " {print $}' /etc/grub2.cfg | grep ${KERNEL_VERSION})
grub2-set-default '${GRUB_ITEM}'
echo '请重启后执行uname -r查看是否生效'
} function install_python() {
# python3.,包括对应版本的pip
yum install python36u-pip -y
# 使用国内pypi源,使用阿里云的源
# 备选:http://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 --upgrade pip
# 一些基于python的实用或者有意思的工具
pip3. install cheat mycli icdiff you-get lolcat youtube-dl } function install_php() {
yum install php72u* nginx -y
} function install_nodejs_and_config() {
#配置nodejs的yum源,安装 nodejs (epel源里有nodejs,但版本比较老),使用清华大学的源
yum install https://mirrors.tuna.tsinghua.edu.cn/nodesource/rpm_10.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 - $basearch
baseurl=https://mirrors.tuna.tsinghua.edu.cn/nodesource/rpm_10.x/el/7/$basearch
enabled=
gpgcheck= [nodesource-source]
name=Node.js for Enterprise Linux - $basearch - Source
baseurl=https://mirrors.tuna.tsinghua.edu.cn/nodesource/rpm_10.x/el/7/SRPMS
enabled=
gpgcheck= EOF
yum makecache
yum install nodejs -y
# 更换国内npm源
npm config set registry https://mirrors.huaweicloud.com/repository/npm/
# 备选:npm config set registry https://mirrors.huaweicloud.com/repository/npm/
# npm config set registry https://registry.npm.taobao.org/
npm cache clean -f
# 一些基于nodejs的实用或者有意思的工具
npm install --global n npm get-port-cli hasha-cli http-server } #命令行小游戏
function install_cmd_game() {
#
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 sedtris/*
# ./sedtris/sedtris.sh
} #安装jdk和tomcat
function install_jdk_and_tomcat() {
#安装openjdk
yum install java-1.8.0-openjdk-devel.x86_64 -y #或者 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}')
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=Tomcat9.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 } #安装mysql5.7 http://mirrors.tuna.tsinghua.edu.cn/mysql,使用清华大学的源
function install_mysql_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_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"${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.0" "3.2" "3.4" "3.6" "4.0"; do
cat >> /etc/yum.repos.d/mongodb.repo <<- EOF
[mongodb-org-$version]
name=MongoDB Repository
baseurl=https://mirrors.tuna.tsinghua.edu.cn/mongodb/yum/el7-$version/
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
}
system_config
# 如果不指定参数,则执行所有功能模块
if [[ -z $* ]]; then
config_mirror_and_update
update_kernel
install_python
install_php
install_nodejs_and_config
install_cmd_game
install_jdk_and_tomcat
install_mysql_and_config
install_mongodb
install_docker
fi for arg in $* ; do
case ${arg} in
base)
config_mirror_and_update
;;
kernel)
config_mirror_and_update
update_kernel
;;
python)
config_mirror_and_update
install_python
;;
php)
config_mirror_and_update
install_php
;;
nodejs)
config_mirror_and_update
install_nodejs_and_config
;;
cmd_game)
config_mirror_and_update
install_cmd_game
;;
jdk)
config_mirror_and_update
install_jdk_and_tomcat
;;
mysql)
config_mirror_and_update
install_mysql_and_config
;;
mongodb)
config_mirror_and_update
install_mongodb
;;
docker)
config_mirror_and_update
install_docker
;;
esac
done

#!/bin/bash# curl https://yiyingcanfeng.github.io/centos-init.sh | bash# 可选参数base kernel python php nodejs cmd_game jdk mysql mongodb docker# 比如# curl https://yiyingcanfeng.github.io/centos-init.sh | bash -s base
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.huaweicloud.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    mv /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    cat > /etc/yum.repos.d/ius.repo <<- "EOF"[ius]name=iusbaseurl=https://mirrors.aliyun.com/ius/stable/CentOS/7/$basearchgpgcheck=0enabled=1
EOF    yum makecache    yum update -y#一些实用工具,这些大部分在EPEL源里    yum install -y bash-completion git2u 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 redis5 lftp vsftpd}
# 更新内核为主分支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 ${KERNEL_VERSION})    grub2-set-default '${GRUB_ITEM}'    echo '请重启后执行uname -r查看是否生效'}
function install_python() {    # python3.6,包括对应版本的pip    yum install python36u-pip -y    # 使用国内pypi源,使用阿里云的源    # 备选:http://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.6 install --upgrade pip    # 一些基于python的实用或者有意思的工具    pip3.6 install cheat mycli icdiff you-get lolcat youtube-dl
}
function install_php() {    yum install php72u* nginx -y}
function install_nodejs_and_config() {#配置nodejs的yum源,安装 nodejs (epel源里有nodejs,但版本比较老),使用清华大学的源    yum install https://mirrors.tuna.tsinghua.edu.cn/nodesource/rpm_10.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 - $basearchbaseurl=https://mirrors.tuna.tsinghua.edu.cn/nodesource/rpm_10.x/el/7/$basearchenabled=1gpgcheck=0
[nodesource-source]name=Node.js for Enterprise Linux 7 - $basearch - Sourcebaseurl=https://mirrors.tuna.tsinghua.edu.cn/nodesource/rpm_10.x/el/7/SRPMSenabled=0gpgcheck=1
EOF    yum makecache    yum install nodejs -y    # 更换国内npm源    npm config set registry https://mirrors.huaweicloud.com/repository/npm/    # 备选:npm config set registry https://mirrors.huaweicloud.com/repository/npm/    # npm config set registry https://registry.npm.taobao.org/    npm cache clean -f    # 一些基于nodejs的实用或者有意思的工具    npm install --global n npm get-port-cli hasha-cli http-server
}
#命令行小游戏function install_cmd_game() {    # 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和tomcatfunction install_jdk_and_tomcat() {#安装openjdk    yum install java-1.8.0-openjdk-devel.x86_64 -y
#或者 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}')    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=Tomcat9.0.17After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]Type=forkingEnvironment='CATALINA_OPTS=-Xms128M -Xmx512M -server -XX:+UseParallelGC'WorkingDirectory=/usr/apache-tomcat-9.0.17
ExecStart=/usr/apache-tomcat-9.0.17/bin/startup.shExecReload=/bin/kill -s HUP $MAINPIDExecStop=/bin/kill -s QUIT $MAINPIDPrivateTmp=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
}
#安装mysql5.7 http://mirrors.tuna.tsinghua.edu.cn/mysql,使用清华大学的源function install_mysql_and_config() {    cat > /etc/yum.repos.d/mysql-community.repo <<- "EOF"[mysql-connectors-community]name=MySQL Connectors Communitybaseurl=http://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-connectors-community-el7enabled=1gpgcheck=0gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[mysql-tools-community]name=MySQL Tools Communitybaseurl=http://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-tools-community-el7enabled=1gpgcheck=0gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[mysql57-community]name=MySQL 5.7 Community Serverbaseurl=http://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql57-community-el7enabled=1gpgcheck=0gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[mysql80-community]name=MySQL 8.0 Community Serverbaseurl=http://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql80-community-el7enabled=0gpgcheck=0gpgkey=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"${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.0" "3.2" "3.4" "3.6" "4.0"; do    cat >> /etc/yum.repos.d/mongodb.repo <<- EOF[mongodb-org-$version]name=MongoDB Repositorybaseurl=https://mirrors.tuna.tsinghua.edu.cn/mongodb/yum/el7-$version/gpgcheck=0enabled=1
EOF    done    yum makecache    yum install mongodb-org -y
}
#安装dockerfunction 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}system_config# 如果不指定参数,则执行所有功能模块if [[ -z $* ]]; then    config_mirror_and_update    update_kernel    install_python    install_php    install_nodejs_and_config    install_cmd_game    install_jdk_and_tomcat    install_mysql_and_config    install_mongodb    install_dockerfi
for arg in $* ; do    case ${arg} in    base)    config_mirror_and_update    ;;    kernel)    config_mirror_and_update    update_kernel    ;;    python)    config_mirror_and_update    install_python    ;;    php)    config_mirror_and_update    install_php    ;;    nodejs)    config_mirror_and_update    install_nodejs_and_config    ;;    cmd_game)    config_mirror_and_update    install_cmd_game    ;;    jdk)    config_mirror_and_update    install_jdk_and_tomcat    ;;    mysql)    config_mirror_and_update    install_mysql_and_config    ;;    mongodb)    config_mirror_and_update    install_mongodb    ;;    docker)    config_mirror_and_update    install_docker    ;;    esacdone

CentOS 初始化脚本的更多相关文章

  1. centos初始化脚本

    centos初始化脚本 添加IP.主机名.挂载/dev/sdb1磁盘 #!/bin/bash # ip=$ hostname=$ if [ -z $ip ] || [ -z $hostname ]; ...

  2. CentOS初始化脚本(未完)

    #!/bin/bash release=`` .shutdown selinux [ -e "/etc/selinux/config" ] && sed -i 's ...

  3. centos7初始化脚本(转)

    #!/bin/bash # 描述: CentOS 初始化脚本 # 加载配置文件 if [ -n "${1}" ];then /bin/} fi # 可接受配置(shell 变量格式 ...

  4. centos 7 初始化脚本

    #!/bin/bash # 时间: 2018-11-21 # 作者: HuYuan # 描述: CentOS 7 初始化脚本 # 加载配置文件 if [ -n "${1}" ];t ...

  5. bash-1 初始化CentOS系统的初始化脚本

    初始化CentOS系统的初始化脚本 #!/bin/bash # #******************************************************************* ...

  6. Centos7初始化脚本

    今天分享一个自己写的一个初始化的小脚本. 编写初始化系统要考虑到系统的版本问题,现在用的比较多的就是centos6和centos7,所以首先要判断一下系统的版本. cat /etc/redhat-re ...

  7. centos7 初始化脚本

    #!/bin/bash # 时间: 2018-11-21 # 作者: HuYuan # 描述: CentOS 7 初始化脚本 # 加载配置文件 if [ -n "${1}" ];t ...

  8. liunx用户环境初始化脚本

          liunx用户环境初始化脚本 编写生成脚本基本格式,包括作者,联系方式,版本,时间,描述等 [root@magedu ~]# vim .vimrc set ignorecase set c ...

  9. Linux初始化脚本

    以下脚本用于linux系统的初始化脚本,可以在服务器系统安装完毕之后立即执行.脚本结合各位大牛一些参数,已经在CentOS 5下通过. 使用方法:将其复制,保存为一个shell文件,比如init.sh ...

随机推荐

  1. HDU3109: Worms(字符串变换类 DP)

    pro:开始有一个字母虫,然后字母虫在每一天可以选择自己身上的部分字母变换,变换规则形如A->BC. 现状给定最终字母虫的字符串,求最少用了多少天. 如有规则A->BC,B->AC, ...

  2. wordpress如何调用特定页面模板

    我们在制作page页面时经常会调用特定的页面模板,比如专题页,其实我们只要做一个这样的模板就可以了,很简单,定义一下,代码如下,Template Name: service就是具体的页面模板名,这个在 ...

  3. [NPM + React] Prepare a Custom React Hook to be Published as an npm Package

    Before we publish our package, we want to make sure everything is set up correctly. We’ll cover vers ...

  4. Boosting and AdaBoost

    Boosting是一种从一些弱分类器中创建一个强分类器的集成技术(提升算法). 它先由训练数据构建一个模型,然后创建第二个模型来尝试纠正第一个模型的错误.不断添加模型,直到训练集完美预测或已经添加到数 ...

  5. B/S大附件上传,支持断点续传

    核心原理: 该项目核心就是文件分块上传.前后端要高度配合,需要双方约定好一些数据,才能完成大文件分块,我们在项目中要重点解决的以下问题. * 如何分片: * 如何合成一个文件: * 中断了从哪个分片开 ...

  6. 66、Spark Streaming:数据处理原理剖析与源码分析(block与batch关系透彻解析)

    一.数据处理原理剖析 每隔我们设置的batch interval 的time,就去找ReceiverTracker,将其中的,从上次划分batch的时间,到目前为止的这个batch interval ...

  7. 洛谷P2029跳舞

    题目 DP, 用的\(dp[i][j]\)表示\(i\)之前的数选了\(j\)个得到的最大结果,然后状态转移方程应该是 \[if (j \% t == 0)~~dp[i][j] = max(dp[i] ...

  8. Doors Breaking and Repairing

    题目链接:Doors Breaking and Repairing 题目大意:有n个门,先手攻击力为x(摧毁),后手恢复力为y(恢复),输入每个门的初始“生命值”,当把门的生命值攻为0时,就无法恢复了 ...

  9. mysql 日期处理

    mysql> select curdate(); +------------+ | curdate() | +------------+ | -- | +------------+ row in ...

  10. Intellij IDEA 自动清除无效 import 和 清除无效 import 的快捷键

    可以settings-general-auto import-java项,勾选optimize imports on the fly,在当前项目下会自动清除无效的import,而且这个是随时自动清除的 ...