#!/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. js Date对象和数字对象

    <script type="text/javascript"> alert(new Date.toLocaleString()); </script> 以本 ...

  2. MySQL命令操作(Linux平台)

    Linux shell 批量创建数据库/表 Shell 脚本如下: # create database and table HOST='localhost' PORT='3306' USER='roo ...

  3. 使用postman上传excel文件测试导入excel

    今日思语:城市的生活很快,有时学会让自己慢下来,慢慢来 对于做一些文件上传操作时,一般我们是直接在前端页面加入类型为file的input标签,也可以使用postman来进行文件的上传测试,如下: po ...

  4. CLR如何将SEH异常映射到托管异常类型

    托管异常处理构建在Windows操作系统的结构化异常处理之上,通常称为SEH.这意味着CLR了解如何在SEH和托管异常系统之间进行互操作,这是一个非常关键的点,因为SEH基于异常代码的概念,而托管异常 ...

  5. 使用 DML 自定义调试器输出

    调试器标记语言 (DML) 提供了一种机制增强来自调试器和扩展的输出. 与 HTML 类似,调试器的标记支持允许将输出包括显示指令和额外非显示的标记窗体中的信息. 调试器用户界面,WinDbg 等中分 ...

  6. edgedb-js 来自官方的js 驱动

    目前对于edgedb 主要还是来自官方的python驱动,目前js 版本的已经快发布了,代码在github 可以看到了 同时官方文档也提供了一个关于edgedb 内部的协议说明,结合js 驱动以及文档 ...

  7. 【JZOJ6229】【20190621】san

    题目 \(n\)个点\(m\)条边的有向图,每个点有点权 你可以选择拓扑序的一个区间的 最大化点权和 $n \le 50  , m \le \frac{n*(n-1)}{2} , 0 \le |a_i ...

  8. mysql 修改字段名称以及长度

    //修改字段长度 alter table table1 modify name ); //修改字段名称以及长度 alter table table1 change name name_new ); a ...

  9. Fluent Meshing对称模型形成完整模型

    原视频下载地址:https://pan.baidu.com/s/1i4NZnVZ 密码:ts5a

  10. Res-DenseNetSegmentation模型调试记录

    参考:https://blog.csdn.net/AbstractSky/article/details/76769202 https://blog.csdn.net/jsliuqun/article ...