Maven 本地资源库配置
作者:尹正杰
版权声明:原创作品,谢绝转载!否则将追究法律责任。
一.操作系统环境
1>.查看操作系统环境(总共3台虚拟机)
2>.关闭防火墙并禁用开机自启动(“node102.yinzhengjie.org.cn”和“node103.yinzhengjie.org.cn”两个节点需要重复此操作)
[root@node101 ~]# systemctl status firewalld● firewalld.service - firewalld - dynamic firewall daemon Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled) Active: active (running) since Tue 2018-12-18 08:40:12 EST; 26min ago Docs: man:firewalld(1) Main PID: 689 (firewalld) CGroup: /system.slice/firewalld.service └─689 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopidDec 18 08:40:03 node101.yinzhengjie.org.cn systemd[1]: Starting firewalld - dynamic firewall daemon...Dec 18 08:40:12 node101.yinzhengjie.org.cn systemd[1]: Started firewalld - dynamic firewall daemon.[root@node101 ~]# [root@node101 ~]# [root@node101 ~]# [root@node101 ~]# systemctl stop firewalld[root@node101 ~]# [root@node101 ~]# [root@node101 ~]# systemctl disable firewalldRemoved symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.[root@node101 ~]# [root@node101 ~]# [root@node101 ~]# systemctl status firewalld● firewalld.service - firewalld - dynamic firewall daemon Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled) Active: inactive (dead) Docs: man:firewalld(1)Dec 18 08:40:03 node101.yinzhengjie.org.cn systemd[1]: Starting firewalld - dynamic firewall daemon...Dec 18 08:40:12 node101.yinzhengjie.org.cn systemd[1]: Started firewalld - dynamic firewall daemon.Dec 18 09:07:35 node101.yinzhengjie.org.cn systemd[1]: Stopping firewalld - dynamic firewall daemon...Dec 18 09:07:36 node101.yinzhengjie.org.cn systemd[1]: Stopped firewalld - dynamic firewall daemon.[root@node101 ~]#
3>.关闭selinux并禁用其开机自启动(“node102.yinzhengjie.org.cn”和“node103.yinzhengjie.org.cn”两个节点需要重复此操作)
[root@node101 ~]# getenforce Enforcing[root@node101 ~]# [root@node101 ~]# setenforce 0[root@node101 ~]# [root@node101 ~]# getenforce Permissive[root@node101 ~]# [root@node101 ~]# cat /etc/selinux/config | grep SELINUX= | grep -v ^#SELINUX=enforcing[root@node101 ~]# [root@node101 ~]# sed -i 's#SELINUX=enforcing#SELINUX=disabled#' /etc/selinux/config[root@node101 ~]# [root@node101 ~]# cat /etc/selinux/config | grep SELINUX= | grep -v ^#SELINUX=disabled[root@node101 ~]#
4>.编写集群管理脚本
[root@node101 ~]# ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsaGenerating public/private rsa key pair.Created directory '/root/.ssh'.Your identification has been saved in /root/.ssh/id_rsa.Your public key has been saved in /root/.ssh/id_rsa.pub.The key fingerprint is:SHA256:LzQFxaeYjEKQVSTx7RwZQaWkCYC8ry6dVkl4RzHJ6os root@node101.yinzhengjie.org.cnThe key's randomart image is:+---[RSA 2048]----+|..o====+*=o ||... .++* =. . || .o o+o=o.o || .. = oo+o. || .+ + S || .+ . o || ..+ . . . ||..E . . ||oo |+----[SHA256]-----+[root@node101 ~]#
[root@node101 ~]# ssh-copy-id root@node101.yinzhengjie.org.cn/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"The authenticity of host 'node101.yinzhengjie.org.cn (172.30.1.101)' can't be established.ECDSA key fingerprint is SHA256:aGk7Wv77uRVAElcihCH0Zu0sAPp6qEs2sSA1Zsj3o7g.ECDSA key fingerprint is MD5:2b:74:b8:ad:f8:92:78:04:38:90:f1:28:e7:70:68:fb.Are you sure you want to continue connecting (yes/no)? yes/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keysroot@node101.yinzhengjie.org.cn's password: Number of key(s) added: 1Now try logging into the machine, with: "ssh 'root@node101.yinzhengjie.org.cn'"and check to make sure that only the key(s) you wanted were added.[root@node101 ~]# [root@node101 ~]# ssh node101.yinzhengjie.org.cnLast login: Tue Dec 18 08:57:22 2018 from 172.30.1.1[root@node101 ~]# whoroot pts/0 2018-12-18 08:57 (172.30.1.1)root pts/1 2018-12-18 09:13 (node101.yinzhengjie.org.cn)[root@node101 ~]# exit logoutConnection to node101.yinzhengjie.org.cn closed.[root@node101 ~]#
[root@node101 ~]# ssh-copy-id root@node102.yinzhengjie.org.cn/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"The authenticity of host 'node102.yinzhengjie.org.cn (172.30.1.102)' can't be established.ECDSA key fingerprint is SHA256:aGk7Wv77uRVAElcihCH0Zu0sAPp6qEs2sSA1Zsj3o7g.ECDSA key fingerprint is MD5:2b:74:b8:ad:f8:92:78:04:38:90:f1:28:e7:70:68:fb.Are you sure you want to continue connecting (yes/no)? yes/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keysroot@node102.yinzhengjie.org.cn's password: Number of key(s) added: 1Now try logging into the machine, with: "ssh 'root@node102.yinzhengjie.org.cn'"and check to make sure that only the key(s) you wanted were added.[root@node101 ~]# [root@node101 ~]# ssh node102.yinzhengjie.org.cnLast login: Tue Dec 18 08:36:15 2018[root@node102 ~]# [root@node102 ~]# whoroot pts/0 2018-12-18 09:14 (172.30.1.101)[root@node102 ~]# [root@node102 ~]# exit logoutConnection to node102.yinzhengjie.org.cn closed.[root@node101 ~]#
[root@node101 ~]# ssh-copy-id root@node103.yinzhengjie.org.cn/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"The authenticity of host 'node103.yinzhengjie.org.cn (172.30.1.103)' can't be established.ECDSA key fingerprint is SHA256:aGk7Wv77uRVAElcihCH0Zu0sAPp6qEs2sSA1Zsj3o7g.ECDSA key fingerprint is MD5:2b:74:b8:ad:f8:92:78:04:38:90:f1:28:e7:70:68:fb.Are you sure you want to continue connecting (yes/no)? yes/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keysroot@node103.yinzhengjie.org.cn's password: Number of key(s) added: 1Now try logging into the machine, with: "ssh 'root@node103.yinzhengjie.org.cn'"and check to make sure that only the key(s) you wanted were added.[root@node101 ~]# [root@node101 ~]# ssh node103.yinzhengjie.org.cnLast login: Sat Dec 15 16:54:09 2018[root@node103 ~]# [root@node103 ~]# whoroot pts/0 2018-12-18 09:15 (172.30.1.101)[root@node103 ~]# [root@node103 ~]# exit logoutConnection to node103.yinzhengjie.org.cn closed.[root@node101 ~]#
[root@node101 ~]# vi /usr/local/bin/xcall.sh #我们创建该脚本时,直接就把它放在默认的“PATH”环境变量中。因此编辑好后只要有执行权限就可以在任意路径调用它啦![root@node101 ~]# [root@node101 ~]# [root@node101 ~]# cat /usr/local/bin/xcall.sh#!/bin/bash#@author :yinzhengjie#blog:http://www.cnblogs.com/yinzhengjie#EMAIL:y1053419035@qq.com#判断用户是否传参if [ $# -lt 1 ];then echo "请输入参数" exitfi#获取用户输入的命令cmd=$@for (( i=101;i<=103;i++ ))do #使终端变绿色 tput setaf 2 echo ============= node${i}.yinzhengjie.org.cn : $cmd ============ #使终端变回原来的颜色,即白灰色 tput setaf 7 #远程执行命令 ssh node${i}.yinzhengjie.org.cn $cmd #判断命令是否执行成功 if [ $? == 0 ];then echo "命令执行成功" fidone[root@node101 ~]# [root@node101 ~]# [root@node101 ~]# chmod +x /usr/local/bin/xcall.sh #别忘记添加执行权限哟![root@node101 ~]# [root@node101 ~]# xcall.sh cat /etc/redhat-release #我们在这里可以测试一些咱们的脚本是否好使~============= node101.yinzhengjie.org.cn : cat /etc/redhat-release ============CentOS Linux release 7.2.1511 (Core) 命令执行成功============= node102.yinzhengjie.org.cn : cat /etc/redhat-release ============CentOS Linux release 7.2.1511 (Core) 命令执行成功============= node103.yinzhengjie.org.cn : cat /etc/redhat-release ============CentOS Linux release 7.2.1511 (Core) 命令执行成功[root@node101 ~]# [root@node101 ~]#
[root@node101 ~]# xcall.sh "yum -y install rsync" ============= node101.yinzhengjie.org.cn : yum -y install rsync ============Loaded plugins: fastestmirrorLoading mirror speeds from cached hostfile * base: mirrors.huaweicloud.com * extras: mirrors.huaweicloud.com * updates: mirrors.163.comResolving Dependencies--> Running transaction check---> Package rsync.x86_64 0:3.1.2-4.el7 will be installed--> Finished Dependency ResolutionDependencies Resolved================================================================================ Package Arch Version Repository Size================================================================================Installing: rsync x86_64 3.1.2-4.el7 base 403 kTransaction Summary================================================================================Install 1 PackageTotal download size: 403 kInstalled size: 815 kDownloading packages:Running transaction checkRunning transaction testTransaction test succeededRunning transaction Installing : rsync-3.1.2-4.el7.x86_64 1/1 Verifying : rsync-3.1.2-4.el7.x86_64 1/1 Installed: rsync.x86_64 0:3.1.2-4.el7 Complete!命令执行成功============= node102.yinzhengjie.org.cn : yum -y install rsync ============Loaded plugins: fastestmirrorRepodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fasthttp://mirrors.njupt.edu.cn/centos/7.6.1810/os/x86_64/repodata/bc140c8149fc43a5248fccff0daeef38182e49f6fe75d9b46db1206dc25a6c1c-c7-x86_64-comps.xml.gz: [Errno 12] Timeout on http://10.10.254.10/cache/5/02/mirrors.njupt.edu.cn/033b2636ff3cf3103169fa739764fdd7/bc140c8149fc43a5248fccff0daeef38182e49f6fe75d9b46db1206dc25a6c1c-c7-x86_64-comps.xml.gz: (28, 'Connection timed out after 30682 milliseconds')Trying other mirror.http://mirrors.njupt.edu.cn/centos/7.6.1810/updates/x86_64/repodata/8e273c72093a2cfc3f3b2baccfb2b01f7f4bcdc1bb72d53e38074068a756f1c6-primary.sqlite.bz2: [Errno 12] Timeout on http://10.10.254.10/cache/4/02/mirrors.njupt.edu.cn/c35de49cce30395fb97f6c41a56fbad5/8e273c72093a2cfc3f3b2baccfb2b01f7f4bcdc1bb72d53e38074068a756f1c6-primary.sqlite.bz2: (28, 'Connection timed out after 30672 milliseconds')Trying other mirror.Determining fastest mirrors * base: mirrors.huaweicloud.com * extras: mirrors.huaweicloud.com * updates: mirrors.neusoft.edu.cnResolving Dependencies--> Running transaction check---> Package rsync.x86_64 0:3.1.2-4.el7 will be installed--> Finished Dependency ResolutionDependencies Resolved================================================================================ Package Arch Version Repository Size================================================================================Installing: rsync x86_64 3.1.2-4.el7 base 403 kTransaction Summary================================================================================Install 1 PackageTotal download size: 403 kInstalled size: 815 kDownloading packages:Running transaction checkRunning transaction testTransaction test succeededRunning transaction Installing : rsync-3.1.2-4.el7.x86_64 1/1 Verifying : rsync-3.1.2-4.el7.x86_64 1/1 Installed: rsync.x86_64 0:3.1.2-4.el7 Complete!命令执行成功============= node103.yinzhengjie.org.cn : yum -y install rsync ============Loaded plugins: fastestmirrorRepodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fasthttp://mirrors.njupt.edu.cn/centos/7.6.1810/os/x86_64/repodata/6614b3605d961a4aaec45d74ac4e5e713e517debb3ee454a1c91097955780697-primary.sqlite.bz2: [Errno 12] Timeout on http://10.10.254.10/cache/5/02/mirrors.njupt.edu.cn/fa6cd86bdbaedbbfedfbfa6d45952cd2/6614b3605d961a4aaec45d74ac4e5e713e517debb3ee454a1c91097955780697-primary.sqlite.bz2: (28, 'Connection timed out after 30867 milliseconds')Trying other mirror.Determining fastest mirrors * base: mirrors.huaweicloud.com * extras: mirrors.huaweicloud.com * updates: mirrors.cn99.comResolving Dependencies--> Running transaction check---> Package rsync.x86_64 0:3.1.2-4.el7 will be installed--> Finished Dependency ResolutionDependencies Resolved================================================================================ Package Arch Version Repository Size================================================================================Installing: rsync x86_64 3.1.2-4.el7 base 403 kTransaction Summary================================================================================Install 1 PackageTotal download size: 403 kInstalled size: 815 kDownloading packages:Running transaction checkRunning transaction testTransaction test succeededRunning transaction Installing : rsync-3.1.2-4.el7.x86_64 1/1 Verifying : rsync-3.1.2-4.el7.x86_64 1/1 Installed: rsync.x86_64 0:3.1.2-4.el7 Complete!命令执行成功[root@node101 ~]#
[root@node101 ~]# vi /usr/local/bin/xrsync.sh #编写同步脚本,注意:我们在编写脚本时,就把脚本放在Linux自带的“PATH”环境变量中。[root@node101 ~]# [root@node101 ~]# cat /usr/local/bin/xrsync.sh #!/bin/bash#@author :yinzhengjie#blog:http://www.cnblogs.com/yinzhengjie#EMAIL:y1053419035@qq.com#判断用户是否传参if [ $# -lt 1 ];then echo "请输入参数"; exitfi#获取文件路径file=$@#获取子路径filename=`basename $file`#获取父路径dirpath=`dirname $file`#获取完整路径cd $dirpathfullpath=`pwd -P`#同步文件到DataNodefor (( i=102;i<=103;i++ ))do #使终端变绿色 tput setaf 2 echo =========== node${i}.yinzhengjie.org.cn : $file =========== #使终端变回原来的颜色,即白灰色 tput setaf 7 #远程执行命令 rsync -lr $filename `whoami`@node${i}.yinzhengjie.org.cn:$fullpath #判断命令是否执行成功 if [ $? == 0 ];then echo "命令执行成功" fidone[root@node101 ~]# [root@node101 ~]# [root@node101 ~]# chmod +x /usr/local/bin/xrsync.sh #别忘记添加执行权限哟![root@node101 ~]#
[root@node101 ~]# xrsync.sh /etc/hosts=========== node102.yinzhengjie.org.cn : /etc/hosts ===========命令执行成功=========== node103.yinzhengjie.org.cn : /etc/hosts ===========命令执行成功[root@node101 ~]# [root@node101 ~]# xcall.sh cat /etc/hosts============= node101.yinzhengjie.org.cn : cat /etc/hosts ============127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4::1 localhost localhost.localdomain localhost6 localhost6.localdomain6172.30.1.101 node101.yinzhengjie.org.cn 172.30.1.102 node102.yinzhengjie.org.cn 172.30.1.103 node103.yinzhengjie.org.cn 命令执行成功============= node102.yinzhengjie.org.cn : cat /etc/hosts ============127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4::1 localhost localhost.localdomain localhost6 localhost6.localdomain6172.30.1.101 node101.yinzhengjie.org.cn 172.30.1.102 node102.yinzhengjie.org.cn 172.30.1.103 node103.yinzhengjie.org.cn 命令执行成功============= node103.yinzhengjie.org.cn : cat /etc/hosts ============127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4::1 localhost localhost.localdomain localhost6 localhost6.localdomain6172.30.1.101 node101.yinzhengjie.org.cn 172.30.1.102 node102.yinzhengjie.org.cn 172.30.1.103 node103.yinzhengjie.org.cn 命令执行成功[root@node101 ~]#
二.安装jdk并配置相应的环境变量
1>.JDK下载地址
Oracle官网JDK下载地址:。
2>.在"node101.yinzhengjie.org.cn"配置jdk的环境变量
[root@node101 ~]# yum -y install lrzszLoaded plugins: fastestmirrorLoading mirror speeds from cached hostfile * base: mirrors.aliyun.com * extras: mirrors.nju.edu.cn * updates: mirrors.nju.edu.cnResolving Dependencies--> Running transaction check---> Package lrzsz.x86_64 0:0.12.20-36.el7 will be installed--> Finished Dependency ResolutionDependencies Resolved============================================================================================================================================= Package Arch Version Repository Size=============================================================================================================================================Installing: lrzsz x86_64 0.12.20-36.el7 base 78 kTransaction Summary=============================================================================================================================================Install 1 PackageTotal download size: 78 kInstalled size: 181 kDownloading packages:lrzsz-0.12.20-36.el7.x86_64.rpm | 78 kB 00:00:00 Running transaction checkRunning transaction testTransaction test succeededRunning transaction Installing : lrzsz-0.12.20-36.el7.x86_64 1/1 Verifying : lrzsz-0.12.20-36.el7.x86_64 1/1 Installed: lrzsz.x86_64 0:0.12.20-36.el7 Complete![root@node101 ~]#
[root@node101 ~]# mkdir -pv /yinzhengjie/soft/mkdir: created directory ‘/yinzhengjie’mkdir: created directory ‘/yinzhengjie/soft/’[root@node101 ~]# [root@node101 ~]# lltotal 187260-rw-r--r--. 1 root root 191753373 Dec 18 09:25 jdk-8u191-linux-x64.tar.gz[root@node101 ~]# [root@node101 ~]# tar -zxf jdk-8u191-linux-x64.tar.gz -C /yinzhengjie/soft/[root@node101 ~]# [root@node101 ~]# ln -s /yinzhengjie/soft/jdk1.8.0_191/ /yinzhengjie/soft/jdk[root@node101 ~]# [root@node101 ~]# tail -3 /etc/profile#Add JDK Path by yinzhengjieJAVA_HOME=/yinzhengjie/soft/jdkPATH=$PATH:$JAVA_HOME/bin[root@node101 ~]# [root@node101 ~]# source /etc/profile[root@node101 ~]# [root@node101 ~]# java -versionjava version "1.8.0_191"Java(TM) SE Runtime Environment (build 1.8.0_191-b12)Java HotSpot(TM) 64-Bit Server VM (build 25.191-b12, mixed mode)[root@node101 ~]#
3>.分发"node101.yinzhengjie.org.cn"的配置到“node102.yinzhengjie.org.cn”和“node103.yinzhengjie.org.cn”主机上
[root@node101 ~]# xrsync.sh /etc/profile=========== node102.yinzhengjie.org.cn : /etc/profile ===========命令执行成功=========== node103.yinzhengjie.org.cn : /etc/profile ===========命令执行成功[root@node101 ~]# [root@node101 ~]# [root@node101 ~]# xrsync.sh /yinzhengjie/=========== node102.yinzhengjie.org.cn : /yinzhengjie/ ===========命令执行成功=========== node103.yinzhengjie.org.cn : /yinzhengjie/ ===========命令执行成功[root@node101 ~]# [root@node101 ~]# [root@node101 ~]# xcall.sh ln -s /yinzhengjie/soft/jdk/bin/jps /usr/local/bin/============= node101.yinzhengjie.org.cn : ln -s /yinzhengjie/soft/jdk/bin/jps /usr/local/bin/ ============命令执行成功============= node102.yinzhengjie.org.cn : ln -s /yinzhengjie/soft/jdk/bin/jps /usr/local/bin/ ============命令执行成功============= node103.yinzhengjie.org.cn : ln -s /yinzhengjie/soft/jdk/bin/jps /usr/local/bin/ ============命令执行成功[root@node101 ~]# [root@node101 ~]# xcall.sh jps============= node101.yinzhengjie.org.cn : jps ============9140 Jps命令执行成功============= node102.yinzhengjie.org.cn : jps ============8745 Jps命令执行成功============= node103.yinzhengjie.org.cn : jps ============8737 Jps命令执行成功[root@node101 ~]#
三.maven的安装配置
1>.安装maven
maven的官方下载地址:。
2>.Eclipse中maven配置
详情请参考:
3>.Idea中maven配置
其实配置方法和maven的方式基本雷同。
四.maven本地资源库配置
1>.maven的Setting.xml文件说明
如下是settings.xml的配置,重点讲解几个地方,因为接下来我们要配置安装自己的maven私有库${user.home}/.m2/repository true false false org.codehaus.mojo myproxy true http://… proxy.somewhere.com 8080 proxyuser somepassword *.google.com|ibiblio.org server001 my_login my_password ${usr.home}/.ssh/id_dsa some_passphrase 664 775 planetmirror.com PlanetMirror Australia http://downloads.planetmirror.com/pub/maven2 central test false 1.7 Windows XP Windows x86 5.1.2600 mavenVersion 2.0.3 /usr/local/hudson/hudson-home/jobs/maven-guide-zh-to-production/workspace/ /usr/local/hudson/hudson-home/jobs/maven-guide-zh-to-production/workspace/ usr/local/winner/jobs/maven-guide codehausSnapshots Codehaus Snapshots false always warn http://snapshots.maven.codehaus.org/maven2 default env-test
2>. Setting.xml之修改本地的仓库地址
3>.指定Maven的镜像地址(我们修改为阿里的或者我们自己建立的私有仓库)