CentOS 初始化脚本
#!/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 初始化脚本的更多相关文章
- centos初始化脚本
centos初始化脚本 添加IP.主机名.挂载/dev/sdb1磁盘 #!/bin/bash # ip=$ hostname=$ if [ -z $ip ] || [ -z $hostname ]; ...
- CentOS初始化脚本(未完)
#!/bin/bash release=`` .shutdown selinux [ -e "/etc/selinux/config" ] && sed -i 's ...
- centos7初始化脚本(转)
#!/bin/bash # 描述: CentOS 初始化脚本 # 加载配置文件 if [ -n "${1}" ];then /bin/} fi # 可接受配置(shell 变量格式 ...
- centos 7 初始化脚本
#!/bin/bash # 时间: 2018-11-21 # 作者: HuYuan # 描述: CentOS 7 初始化脚本 # 加载配置文件 if [ -n "${1}" ];t ...
- bash-1 初始化CentOS系统的初始化脚本
初始化CentOS系统的初始化脚本 #!/bin/bash # #******************************************************************* ...
- Centos7初始化脚本
今天分享一个自己写的一个初始化的小脚本. 编写初始化系统要考虑到系统的版本问题,现在用的比较多的就是centos6和centos7,所以首先要判断一下系统的版本. cat /etc/redhat-re ...
- centos7 初始化脚本
#!/bin/bash # 时间: 2018-11-21 # 作者: HuYuan # 描述: CentOS 7 初始化脚本 # 加载配置文件 if [ -n "${1}" ];t ...
- liunx用户环境初始化脚本
liunx用户环境初始化脚本 编写生成脚本基本格式,包括作者,联系方式,版本,时间,描述等 [root@magedu ~]# vim .vimrc set ignorecase set c ...
- Linux初始化脚本
以下脚本用于linux系统的初始化脚本,可以在服务器系统安装完毕之后立即执行.脚本结合各位大牛一些参数,已经在CentOS 5下通过. 使用方法:将其复制,保存为一个shell文件,比如init.sh ...
随机推荐
- 微信程序开发之-WeixinJSBridge调用
微信的WeixinJSBridge还是很厉害的,虽然官方文档只公布了3个功能,但是还内置的很多功能没公布,但是存在.今天就好好和大家聊聊 功能1------发送给好友 代码如下: functi ...
- node爬虫爬取中文时乱码问题 | nodejs gb2312、GBK中文乱码解决方法
iconv需要依赖native库,这样一来,在一些不支持native模块安装的虚拟主机和windows平台上,我们还是无法安心处理GBK编码. 老外写了一个通过纯Javascript转换编码的模块 i ...
- P2340 奶牛会展 DP 背包
P2340 奶牛会展 DP \(n\)头牛,每头牛有智商\(s[i]\)情商\(f[i]\),问如何从中选择几头牛使得智商情商之和最大 且 情商之和.智商之和非负 \(n\le 400,-10^3\l ...
- 47、Spark SQL核心源码深度剖析(DataFrame lazy特性、Optimizer优化策略等)
一.源码分析 1. ###入口org.apache.spark.sql/SQLContext.scala sql()方法: /** * 使用Spark执行一条SQL查询语句,将结果作为DataFram ...
- linux 安装mysql mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz
下边连接:https://www.cnblogs.com/zero-gg/p/8875598.html,大神的结晶啊,我就悄悄的留下来自己用,链接缺少的部分补充下: 1.包的下载方法:wget htt ...
- 随机采样方法整理与讲解(Acceptance-Rejection、MCMC、Gibbs Sampling等)
本文是对参考资料中多篇关于sampling的内容进行总结+搬运,方便以后自己翻阅.其实参考资料中的资料写的比我好,大家可以看一下!好东西多分享!PRML的第11章也是sampling,有时间后面写到P ...
- CTF CMS(转)
CTF--CMS漏洞总结 海洋CMS 6.28 海洋CMS6.28命令执行漏洞 6.45-6.54 漏洞预警 | 海洋CMS(SEACMS)0day漏洞预警 8.8(未验证) 海洋cms前台到后台的g ...
- 作业——09 安装关系型数据库MySQL 安装大数据处理框架Hadoop
作业的要求来自于:https://edu.cnblogs.com/campus/gzcc/GZCC-16SE2/homework/3161 简述Hadoop平台的起源.发展历史与应用现状. 起源: 2 ...
- 大数据应用期末总评(hadoop综合大作业)
作业要求源于:https://edu.cnblogs.com/campus/gzcc/GZCC-16SE1/homework/3363 一.将爬虫大作业产生的csv文件上传到HDFS (1)在/usr ...
- 【自学Spring Boot】什么是Spring Boot
为啥要有Spring Boot? 以前大学刚开始学java web的时候,需要搭建起web框架,当时使用的是SSH(struts+spring+hibernate),那就开始搭建吧,初学者哪里知道整套 ...