1 安装java
#!/bin/bash
# jdk install
# 请将下载的jdk-xxx-linux-xxx.tar.gz包与此脚本放置到同一目录
# 授予此脚本可执行权限(chmod +x install_jdk.sh)
# 在终端执行此脚本开始安装(./文件名)
# 注意:不可有多个版本的jdk包!
# 为了使配置的环境变量生效,安装完成后你应该重新登陆。
jvmpath=/usr/local/java
# 不存在
if [ ! -d "$jvmpath" ]; then
echo "正在创建$jvmpath目录"
sudo mkdir $jvmpath
echo "目录$jvmpath创建成功"
fi
jdkfile=$(ls | grep jdk-*-linux-*.gz)
jdkdirname="jdk1.8.0_201"
if [ ! -f "$jdkfile" ]; then
echo "正在下载jdk请稍等..."
wget --no-cookies --no-check-certificate --header "Cookie: oraclelicense=accept-securebackup-cookie" "https://download.oracle.com/otn-pub/java/jdk/8u201-b09/42970487e3af4f5aa5bca3f542482c60/jdk-8u201-linux-x64.tar.gz"
fi
jdkfile=$(ls | grep jdk-*-linux-*.gz)
if [ -f "$jdkfile" ]; then
sudo tar -zxvf $jdkfile -C /usr/local/java/
echo "安装JDK成功"
echo "配置环境变量"
mv ~/.bashrc ~/.bashrc.backup.java
cat ~/.bashrc.backup.java >> ~/.bashrc
echo "PATH=\"$PATH:$jvmpath/$jdkdirname/bin\"" >> ~/.bashrc
echo "JAVA_HOME=$jvmpath/$jdkdirname" >> ~/.bashrc
echo "CLASSPATH=.:%JAVA_HOME%/lib/dt.jar:%JAVA_HOME%/lib/tools.jar" >> ~/.bashrc
source ~/.bashrc
echo "配置环境成功"
echo "测试是否安装成功"
java -version
echo "安装成功"
fi
2 安装maven
#!/bin/bash
# maven install
mvnpath=/usr/local/maven
# 不存在
if [ ! -d "$mvnpath" ]; then
echo "正在创建$mvnpath目录"
sudo mkdir $mvnpath
echo "目录$mvnpath创建成功"
fi
#apache-maven-3.6
echo "正在下载maven安装包,请稍等..."
#wget --no-cookies --no-check-certificate --header "Cookie: oraclelicense=accept-securebackup-cookie" "https://downloads.apache.org/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz"
mvnfile=$(ls | grep apache*maven-*.gz)
if [ -f "$mvnfile" ]; then
#这个名字其实就是mvn .tar.gz解压之后的文件夹的名字
mvndirname="apache-maven-3.6.3"
#不能加 用'zxvf' 加了 z 就创建了包里面的apace* 文件夹,而我们只要把apace*文件夹下的文件全部解压到 mvnpath里面就好
tar zxvf $mvnfile -C $mvnpath
echo "安装maven成功"
echo "配置环境变量"
mv ~/.bashrc ~/.bashrc.backup.mvn
cat ~/.bashrc.backup.mvn >> ~/.bashrc
echo "PATH=\"$PATH:$mvnpath/$mvndirname/bin\"" >> ~/.bashrc
echo "MAVEN_HOME=$mvnpath/$mvndirname" >> ~/.bashrc
source ~/.bashrc
echo "配置环境成功"
echo "测试是否安装成功"
mvn -v
echo "安装成功"
else
echo "没有找到maven文件"
fi
3 安装nexus
#!/bin/bash
#判断是否是roo用户
if [ $(id -u) != "0" ]; then
echo "Error:You must be root to run this script"
fi
#每次使用只需修改自定义内容即可
#自定义用户名和组
Group_Name="nexus"
User_Name="nexus"
#自定义nginx变量
Install_Path="/usr/local/nexus"
Version="nexus-3.15.0-01"
Package_Type=".tar.gz"
Package=$Version$Package_Type
#创建/usr/local/nexus目录
#mkdir /usr/local/nexus
if [ -e $Install_Path ]
then
echo " $Install_Path 目录已经存在."
echo " $Install_Path Directory Already Exists."
else
echo " $Install_Path 目录正在创建."
mkdir $Install_Path
fi
#下载nexus 文件
Setup_path="/root/"
cd $Setup_path
wget https://sonatype-download.global.ssl.fastly.net/repository/repositoryManager/3/nexus-3.15.0-01-unix.tar.gz
Group_User(){
egrep "^$Group_Name" /etc/group >& /dev/null
if [ $? -ne 0 ]
then
echo "nexus 用户组正在添加."
groupadd $Group_Name
else
echo " The $Group_Name user group already exists."
echo "nexus 用户组已经添加."
fi
#判断nexus用户是否存在
egrep "^$User_Name" /etc/passwd >& /dev/null
if [ $? -ne 0 ]
then
echo "nexus 用户正在添加."
useradd -g $Group_Name $User_Name
else
echo "nexus 用户已经添加."
echo " The $User_Name user already exists."
fi
}
Group_User
# 设置/usr/local/nexus 目录所属组和用户是nexus
chown -R nexus:nexus $Install_Path
#判断文件是否存在
if [ -e $Setup_path$Version$Package_Type ]
then
echo "$Package The Package exists."
else
echo "$Package The package does not exist."
fi
cd $Setup_path
#解压nexus包到/usr/local/nexus
tar -zxvf $Package -C $Install_Path
echo '设置环境变量'
mv ~/.bashrc ~/.bashrc.backup.nexus
cat ~/.bashrc.backup.nexus >> ~/.bashrc
echo "NEXUS_HOME=$Install_Path/$Version" >> ~/.bashrc
echo "PATH=\"$PATH:$NEXUS_HOME/bin\"" >> ~/.bashrc
# 切换nexus用户
su nexus
echo '接下来配置:1、vim bin/nexus.rc run_as_user="nexus"'
4 nexus启动和关闭
设置本地jdk目录
/usr/local/nexus/nexus-3.15.0-01/bin目录下修改nexus文件
INSTALL4J_JAVA_HOME_OVERRIDE="/usr/local/java/jdk1.8.0_201"
设置使用用户(nexus.rc文件,指定用户是nexus而不是root,如果是root会出现警告!)
run_as_user="nexus"
启动nexus
#./nexus start
关闭nexus
#./nexus stop
5.1 安装nginx(可忽略)
安装nginx并代理nexus 8081端口,同时配置https访问
因为访问网站的时候端口是8081,所以想要使用80端口访问的话,我们就用nginx 80端口代理8081,同时设置https访问
安装nginx 我们还是通过shell文件来安装,如下
#!/bin/bash
#判断是否是roo用户
if [ $(id -u) != "0" ]; then
echo "Error:You must be root to run this script"
fi
#每次使用只需修改自定义内容即可
#自定义用户名和组
Group_Name="nginx"
User_Name="nginx"
#自定义nginx变量
Install_Path="/usr/local/nginx"
Package_Type=".tar.gz"
Version="nginx-1.15.8"
Package=$Version$Package_Type
Setup_path="/root/"
RPM="nginx"
#创建/usr/local/nginx目录
#mkdir /usr/local/nginx
if [ -e $Install_Path ]
then
echo " $Install_Path 目录已经存在."
echo " $Install_Path Directory Already Exists."
else
echo " $Install_Path 目录正在创建."
mkdir $Install_Path
fi
#下载nginx 文件
cd $Setup_path
wget http://nginx.org/download/nginx-1.15.8.tar.gz
#安装依赖关系
yum group install "Development Tools" "Server Platform Deveopment"
yum install -y curl openssl-devel pcre-devel
Group_User(){
egrep "^$Group_Name" /etc/group >& /dev/null
if [ $? -ne 0 ]
then
echo "nginx 用户组正在添加."
groupadd $Group_Name
else
echo " The $Group_Name user group already exists."
echo "nginx 用户组已经添加."
fi
#判断nginx用户是否存在
egrep "^$User_Name" /etc/passwd >& /dev/null
if [ $? -ne 0 ]
then
echo "nginx 用户正在添加."
useradd -g $Group_Name $User_Name
else
echo "nginx 用户已经添加."
echo " The $User_Name user already exists."
fi
}
Group_User
#判断文件是否存在
if [ -e $Setup_path$Version$Package_Type ]
then
echo "$Package The Package exists."
else
echo "$Package The package does not exist."
fi
#编译安装nginx
cd $Setup_path
#解压nginx包到/usr/local/nginx
tar -zxvf $Package -C $Install_Path
cd $Install_Path
cd $Version
configure_opts=(
--prefix=$Install_Path
--user=nginx
--group=nginx
--with-http_ssl_module
--with-http_flv_module
--with-http_stub_status_module
--with-http_gzip_static_module
)
./configure ${configure_opts[@]}
if [[ $? -eq 0 ]]
then
make && make install
else
echo "编译失败,请重新编译" && exit 1
fi
#添加Nginx命令到环境变量
cat >/etc/profile.d/nginx.sh <<EOF
export PATH=/usr/local/nginx/sbin/:$PATH
EOF
source /etc/profile
#启动服务
/usr/local/nginx/sbin/nginx
ss -tnlp | grep nginx
安装成功后,我们把一步上传的证书.zip复制到/root文件夹下,并解压缩,如下:
# 创建ssl文件夹
mkdir -p /usr/local/nginx/cert
# 把上一步的.zip证书解压并复制到ssl文件夹下
unzip /root/your-cert-package.zip
# 解压之后应该是两个文件.pem和.key
# 复制.crt和.key文件到ssl目录下
cp your-cert.crt your-cert.key /usr/local/nginx/cert
5.2 配置nginx
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
client_max_body_size 100m;
client_header_timeout 1m;
client_body_timeout 1m;
proxy_connect_timeout 18000; ##修改成半个小时
proxy_send_timeout 18000;
proxy_read_timeout 18000;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name nexus.awbeci.com;
return 301 https://nexus.awbeci.com$request_uri;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
proxy_pass http://127.0.0.1:8081; #代理8081端口
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Port $server_port;
}
}
# HTTPS server
#
server {
listen 443 ssl;
server_name nexus.awbeci.com;
ssl_certificate /usr/local/nginx/cert/nexus.awbeci.com.pem;
ssl_certificate_key /usr/local/nginx/cert/nexus.awbeci.com.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
proxy_pass http://127.0.0.1:8081; #代理8081端口
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Port $server_port;
}
}
}
5.3 重启nginx
# 重启nginx
/usr/local/nginx/sbin/nginx -s reload