一堆脚本分享(jdk、nginx、docker等)
最近搞项目的私有化一键部署,写出来了好多个脚本,这里记录一下;
jdk脚本
#!/bin/bash
yum list installed |grep -e java -e jdk
if [ $? -eq 0 ]
then
JAVA_VERSION=`java -version 2>&1 |awk 'NR==1{ gsub(/"/,""); print $3 }'`
if [[ "$JAVA_VERSION" =~ ^1.8.* ]]; then
echo $JAVA_VERSION
else
echo '检测您已安装非1.8版本jdk, 请自行卸载!!'
fi
else
yum install -y java-1.8.0-openjdk.x86_64
fi
nginx脚本
#!/bin/bash
echo '开始安装Nginx..'
sudo yum install -y gcc zlib zlib-devel pcre-devel openssl openssl-devel
wget https://nginx.org/download/nginx-1.17.0.tar.gz
tar -zxvf nginx-1.17.0.tar.gz
cd nginx-1.17.0 || exit
./configure --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module
make
make install
ln -s /usr/local/nginx /home/nginx
ln -s /usr/local/nginx/sbin/nginx /usr/local/bin/
nginx -v
docker脚本
#!/bin/sh
sudo yum remove -y docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotatedocker-selinux docker-engine-selinux docker-engine
# 安装依赖包
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
# 配置下阿里的源
yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
# 安装Docker-CE版本
sudo yum install -y docker-ce
# 允许开机启动
sudo systemctl enable docker
# 启动docker
sudo systemctl start docker
# 安装docker-compose
echo '开始安装docker-compose...'
#sudo curl -L https://github.com/docker/compose/releases/download/1.16.1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose 比较慢
sudo curl -L https://get.daocloud.io/docker/compose/releases/download/1.25.1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
# 开放docker 2375端口
echo '默认开放2375端口. 服务器安全组不需开放2375权限'
sed -i "/^ExecStart/c\ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock \\" /usr/lib/systemd/system/docker.service
# 更换docker镜像为阿里源
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://vwzbzayi.mirror.aliyuncs.com"]
}
EOF
systemctl daemon-reload
systemctl restart docker
docker network create net-mark-private
docker -H 0.0.0.0:2375 info
echo 'docker组件安装完成!!'
时在中春,阳和方起