Skip to content

Commit 700888c

Browse files
committed
update codes
1 parent 50b09e2 commit 700888c

9 files changed

Lines changed: 158 additions & 39 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
- [Maven 安装](docs/linux/soft/maven-install.md)
1818
- [Nodejs 安装](docs/linux/soft/nodejs-install.md)
1919
- 开发工具
20-
- [Nexus 运维](docs/linux/soft/nexus-install.md)
20+
- [Nexus 运维](docs/linux/soft/nexus-ops.md)
2121
- [Gitlab 运维](docs/linux/soft/kafka-install.md)
2222
- [Jenkins 运维](docs/linux/soft/jenkins.md)
2323
- [Svn 运维](docs/linux/soft/svn-ops.md)

codes/linux/soft/config/redis-remote-access.conf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
# IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES
6767
# JUST COMMENT THE FOLLOWING LINE.
6868
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
69-
# bind 127.0.0.1
69+
bind 0.0.0.0
7070

7171
# Protected mode is a layer of security protection, in order to avoid that
7272
# Redis instances left open on the internet are accessed and exploited.
@@ -499,12 +499,12 @@ replica-priority 100
499499
#
500500
# This should stay commented out for backward compatibility and because most
501501
# people do not need auth (e.g. they run their own servers).
502-
#
502+
#:q
503503
# Warning: since Redis is pretty fast an outside user can try up to
504504
# 150k passwords per second against a good box. This means that you should
505505
# use a very strong password otherwise it will be very easy to break.
506506
#
507-
requirepass 123456
507+
# requirepass
508508

509509
# Command renaming.
510510
#

codes/linux/soft/nexus-install.sh

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
#!/usr/bin/env bash
22

3+
###################################################################################
4+
# 控制台颜色
5+
BLACK="\033[1;30m"
6+
RED="\033[1;31m"
7+
GREEN="\033[1;32m"
8+
YELLOW="\033[1;33m"
9+
BLUE="\033[1;34m"
10+
PURPLE="\033[1;35m"
11+
CYAN="\033[1;36m"
12+
RESET="$(tput sgr0)"
13+
###################################################################################
14+
15+
printf "${BLUE}"
16+
cat << EOF
17+
318
###################################################################################
419
# 安装 sonatype nexus(用于搭建 maven 私服) 脚本
520
# @system: 适用于所有 linux 发行版本。
@@ -8,11 +23,16 @@
823
# @author: Zhang Peng
924
###################################################################################
1025
11-
echo -e "\n>>>>>>>>> install sonatype nexus"
26+
EOF
27+
printf "${RESET}"
28+
29+
printf "${GREEN}>>>>>>>> install nexus begin.${RESET}\n"
1230

1331
mkdir -p /opt/maven
1432
cd /opt/maven
1533

1634
version=3.13.0-01
1735
curl -o /opt/maven/nexus-unix.tar.gz http://download.sonatype.com/nexus/3/nexus-${version}-unix.tar.gz
1836
tar -zxf nexus-unix.tar.gz
37+
38+
printf "${GREEN}<<<<<<<< install nexus end.${RESET}\n"

codes/linux/soft/redis-install.sh

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
#!/usr/bin/env bash
22

3+
###################################################################################
4+
# 控制台颜色
5+
BLACK="\033[1;30m"
6+
RED="\033[1;31m"
7+
GREEN="\033[1;32m"
8+
YELLOW="\033[1;33m"
9+
BLUE="\033[1;34m"
10+
PURPLE="\033[1;35m"
11+
CYAN="\033[1;36m"
12+
RESET="$(tput sgr0)"
13+
###################################################################################
14+
15+
printf "${BLUE}"
316
cat << EOF
417
518
###################################################################################
@@ -9,6 +22,7 @@ cat << EOF
922
###################################################################################
1023
1124
EOF
25+
printf "${RESET}"
1226

1327
command -v yum >/dev/null 2>&1 || { printf "${RED}Require yum but it's not installed.${RESET}\n"; exit 1; }
1428

@@ -37,37 +51,41 @@ if [[ -n $4 ]]; then
3751
password=$4
3852
fi
3953

40-
echo "Current execution: install redis ${version} to ${root}, service port = ${port}, password = ${password}"
41-
echo -e "\n>>>>>>>>> install libs"
54+
printf "${GREEN}>>>>>>>> install redis begin.${RESET}\n"
55+
56+
printf "\t${GREEN}Current execution: install redis ${version} to ${root}, service port = ${port}, password = ${password}${RESET}\n"
4257
yum install -y zlib zlib-devel gcc-c++ libtool openssl openssl-devel tcl
4358

44-
echo -e "\n>>>>>>>>> download redis"
4559
mkdir -p ${root}
4660
curl -o ${root}/redis-${version}.tar.gz http://download.redis.io/releases/redis-${version}.tar.gz
4761

48-
echo -e "\n>>>>>>>>> install redis"
4962
path=${root}/redis-${version}
5063
tar zxf ${root}/redis-${version}.tar.gz -C ${root}
5164
cd ${path}
5265
make && make install
5366
cd -
5467

55-
echo -e "\n>>>>>>>>> config redis"
68+
printf "\n${CYAN}>>>>>>>>> config redis${RESET}\n"
5669
cp ${path}/redis.conf ${path}/redis.conf.default
5770
wget -N https://gitee.com/turnon/linux-tutorial/raw/master/codes/linux/soft/config/redis-remote-access.conf -O ${path}/redis.conf
71+
mkdir -p /etc/redis
5872
cp ${path}/redis.conf /etc/redis/${port}.conf
5973
sed -i "s/^port 6379/port ${port}/g" /etc/redis/${port}.conf
60-
sed -i "s/^requirepass 123456/requirepass ${password}/g" /etc/redis/${port}.conf
74+
if [[ -n ${password} ]]; then
75+
sed -i "s/^# requirepass/requirepass ${password}/g" /etc/redis/${port}.conf
76+
fi
6177

62-
echo -e "\n>>>>>>>>> add firewall port"
78+
printf "\n${CYAN}>>>>>>>>> add firewall port${RESET}\n"
6379
firewall-cmd --zone=public --add-port=${port}/tcp --permanent
6480
firewall-cmd --reload
6581

66-
echo -e "\n>>>>>>>>> add redis service"
82+
printf "\n${CYAN}>>>>>>>>> add redis service${RESET}\n"
6783
# 注册 redis 服务,并设置开机自启动
68-
cp ${path}/utils/redis_init_script /etc/init.d/redis_${port}
84+
cp ${path}/utils/redis_init_script /etc/init.d/
85+
mv /etc/init.d/redis_init_script /etc/init.d/redis_${port}
6986
sed -i "s/^REDISPORT=.*/REDISPORT=${port}/g" /etc/init.d/redis_${port}
7087
chmod +x /etc/init.d/redis_${port}
7188
chkconfig --add redis_${port}
7289
service redis_${port} start
7390

91+
printf "\n${GREEN}<<<<<<<< install redis end.${RESET}\n"

docs/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
- [Maven 安装](linux/soft/maven-install.md)
1818
- [Nodejs 安装](linux/soft/nodejs-install.md)
1919
- 开发工具
20-
- [Nexus 运维](linux/soft/nexus-install.md)
20+
- [Nexus 运维](linux/soft/nexus-ops.md)
2121
- [Gitlab 运维](linux/soft/kafka-install.md)
2222
- [Jenkins 运维](linux/soft/jenkins.md)
2323
- [Svn 运维](linux/soft/svn-ops.md)

docs/coverpage.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<div align="center"><img width="100px" src="http://dunwu.test.upcdn.net/images/others/zp.png"/></div>
22

3-
# Linux 教程
3+
# Linux Tutorial
44

55
> Linux 教程
66

docs/linux/soft/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
- [Jenkins 安装](jenkins-install.md)
77
- [Kafka 安装](kafka-install.md)
88
- [Maven 安装](maven-install.md)
9-
- [Nexus 安装](nexus-install.md)
9+
- [Nexus 安装](nexus-ops.md)
1010
- [Nodejs 安装](nodejs-install.md)
1111
- [RocketMQ 安装](rocketmq-install.md)
1212
- [Svn 安装](svn-ops.md)
Lines changed: 94 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
# 部署并使用 Nexus 作为 Maven 私服
1+
# Nexus 运维
22

3+
> Nexus 是一个强大的 Maven 仓库管理器,可以用来搭建 Maven 私服。
4+
>
35
> 关键词:maven, nexus
46
>
57
> 部署环境
@@ -10,17 +12,22 @@
1012
1113
<!-- TOC depthFrom:2 depthTo:3 -->
1214

13-
- [下载安装 Nexus](#下载安装-nexus)
14-
- [启动停止 Nexus](#启动停止-nexus)
15-
- [使用 Nexus](#使用-nexus)
15+
- [安装 Nexus](#安装-nexus)
16+
- [启动/停止 Nexus](#启动停止-nexus)
17+
- [使用 Nexus 搭建 Maven 私服](#使用-nexus-搭建-maven-私服)
18+
- [配置仓库](#配置仓库)
1619
- [配置 settings.xml](#配置-settingsxml)
1720
- [配置 pom.xml](#配置-pomxml)
1821
- [执行 maven 构建](#执行-maven-构建)
22+
- [将 Nexus 设置为服务](#将-nexus-设置为服务)
23+
- [Nexus 备份和迁移](#nexus-备份和迁移)
24+
- [备份](#备份)
25+
- [迁移](#迁移)
1926
- [参考资料](#参考资料)
2027

2128
<!-- /TOC -->
2229

23-
## 下载安装 Nexus
30+
## 安装 Nexus
2431

2532
进入[官方下载地址](https://www.sonatype.com/download-oss-sonatype),选择合适版本下载。
2633

@@ -40,7 +47,7 @@ tar -zxf nexus-unix.tar.gz
4047
- nexus-3.13.0-01 - 包含了 Nexus 运行所需要的文件。是 Nexus 运行必须的。
4148
- sonatype-work - 包含了 Nexus 生成的配置文件、日志文件、仓库文件等。当我们需要备份 Nexus 的时候默认备份此目录即可。
4249

43-
## 启动停止 Nexus
50+
## 启动/停止 Nexus
4451

4552
进入 nexus-3.13.0-01/bin 目录,有一个可执行脚本 nexus。
4653

@@ -52,31 +59,47 @@ Usage: ./nexus {start|stop|run|run-redirect|status|restart|force-reload}
5259
```
5360

5461
- 启动 nexus - `./nexus start`
55-
- 停止 nexus -
62+
- 停止 nexus - `./nexus stop`
63+
- 重启 nexus - `./nexus restart`
5664

5765
启动成功后,在浏览器中访问 `http://<ip>:8081`,欢迎页面如下图所示:
5866

5967
<div align="center"><img src="http://dunwu.test.upcdn.net/snap/20181127203131.png"/></div>
6068

6169
点击右上角 Sign in 登录,默认用户名/密码为:admin/admin123。
6270

63-
有必要提一下的是,在 Nexus 的 Repositories 管理页面,展示了可用的 maven 仓库,如下图所示:
71+
## 使用 Nexus 搭建 Maven 私服
6472

65-
<div align="center"><img src="http://dunwu.test.upcdn.net/snap/20181127203156.png"/></div>
73+
### 配置仓库
6674

67-
> 说明:
68-
>
69-
> - maven-central - maven 中央库(如果没有配置 mirror,默认就从这里下载 jar 包),从 https://repo1.maven.org/maven2/ 获取资源
70-
> - maven-releases - 存储私有仓库的发行版 jar 包
71-
> - maven-snapshots - 存储私有仓库的快照版(调试版本) jar 包
72-
> - maven-public - 私有仓库的公共空间,把上面三个仓库组合在一起对外提供服务,在本地 maven 基础配置 settings.xml 中使用。
75+
Nexus 中的仓库有以下类型:
7376

74-
## 使用 Nexus
77+
- `hosted` - 宿主仓库。主要用于部署无法从公共仓库获取的构件(如 oracle 的 JDBC 驱动)以及自己或第三方的项目构件;
78+
- `proxy` - 代理仓库。代理公共的远程仓库;
79+
- `virtual` - 虚拟仓库。用于适配 Maven 1;
80+
- `group` - 仓库组。Nexus 通过仓库组的概念统一管理多个仓库,这样我们在项目中直接请求仓库组即可请求到仓库组管理的多个仓库。
7581

76-
如果要使用 Nexus,还必须在 settings.xml 和 pom.xml 中配置认证信息。
82+
<div align="center"><img src="https://gitee.com/turnon/images/raw/master/images/java/javalib/maven/nexus.png"/></div>
83+
84+
> **最佳实践**
85+
>
86+
> 建议配置如下:
87+
>
88+
> - hosted 仓库
89+
> - maven-releases - 存储私有仓库的发行版 jar 包
90+
> - maven-snapshots - 存储私有仓库的快照版(调试版本) jar 包
91+
> - proxy 仓库
92+
> - maven-central - maven 中央库(如果没有配置 mirror,默认就从这里下载 jar 包),从 https://repo1.maven.org/maven2/ 获取资源
93+
> - maven-aliyun - 国内 maven 仓库,提高访问速度。
94+
> - group 仓库
95+
> - maven-public - 私有仓库的公共空间,把上面三个仓库组合在一起对外提供服务,在本地 maven 基础配置 settings.xml 中使用。
96+
97+
<div align="center"><img src="http://dunwu.test.upcdn.net/snap/20181127203156.png"/></div>
7798

7899
### 配置 settings.xml
79100

101+
如果要使用 Nexus,还必须在 settings.xml 和 pom.xml 中配置认证信息。
102+
80103
一份完整的 `settings.xml`
81104

82105
```xml
@@ -186,8 +209,59 @@ $ mvn clean package -Dmaven.skip.test=true -P zp
186209
$ mvn clean deploy -Dmaven.skip.test=true -P zp
187210
```
188211

212+
## 将 Nexus 设置为服务
213+
214+
将 Nexus 添加为服务,以便开机自启动。
215+
216+
`/lib/systemd/system` 目录下创建 `nexus.service` 文件,内容如下:
217+
218+
```ini
219+
[Unit]
220+
Description=nexus
221+
After=network.target
222+
223+
[Service]
224+
Type=forking
225+
LimitNOFILE=65536 #警告处理
226+
Environment=RUN_AS_USER=root
227+
ExecStart=/opt/maven/nexus-3.13.0-01/bin/nexus start
228+
ExecReload=/opt/maven/nexus-3.13.0-01/bin/nexus restart
229+
ExecStop=/opt/maven/nexus-3.13.0-01/bin/nexus stop
230+
Restart=on-failure
231+
PrivateTmp=true
232+
233+
[Install]
234+
WantedBy=multi-user.target
235+
```
236+
237+
保存后,可以使用以下命令应用 nexus 服务:
238+
239+
- `systemctl enable nexus` - 启动 nexus 开机启动
240+
- `systemctl disable nexus` - 关闭 nexus 开机启动
241+
- `systemctl start nexus` - 启动 nexus 服务
242+
- `systemctl stop nexus` - 停止 nexus 服务
243+
- `systemctl restart nexus` - 重启 nexus 服务
244+
245+
## Nexus 备份和迁移
246+
247+
Nexus 三个重要目录:
248+
249+
| 名称 | 目录名 | 重要配置文件 |
250+
| :----------------- | :------------- | :------------------------------------------------ |
251+
| nexus 主目录 | nexus-2.6.4-02 | conf/nexus.properties 里面有 sonatype-work 的地址 |
252+
| sonatype-work 目录 | sonatype-work | nexus/conf/nexus.xml 里面有 storage 的地址 |
253+
| storage 目录 | storage | 里面主要是各种程序的 jar 包等 |
254+
255+
### 备份
256+
257+
Nexus 的数据都存储在 sonatype-work 目录,备份 Nexus 数据只需要将其打包即可。
258+
259+
### 迁移
260+
261+
将原 Nexus 服务器中的 sonatype-work 目录迁移到新 Nexus 服务器的 sonatype-work 目录下。
262+
189263
## 参考资料
190264

191-
- https://www.cnblogs.com/hoobey/p/6102382.html
192-
- https://blog.csdn.net/wzygis/article/details/49276779
193-
- https://blog.csdn.net/clj198606061111/article/details/52200928
265+
- [maven 私库 nexus3 安装及使用](https://blog.csdn.net/clj198606061111/article/details/52200928)
266+
- [Nexus 安装 使用说明](https://www.cnblogs.com/jtlgb/p/7473837.html)
267+
- [企业级开源仓库 nexus3 实战应用–使用 nexus3 配置 yum 私有仓库](http://www.eryajf.net/2002.html)

docs/linux/soft/redis-ops.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
# Redis 安装
22

3+
> **Redis** 是一个高性能的 key-value 数据库。
4+
>
5+
> SET 操作每秒钟 110000 次;GET 操作每秒钟 81000 次。
6+
37
<!-- TOC depthFrom:2 depthTo:3 -->
48

5-
- [安装](#安装)
9+
- [安装 Redis](#安装-redis)
610
- [启动](#启动)
711
- [脚本](#脚本)
812

913
<!-- /TOC -->
1014

11-
## 安装
15+
## 安装 Redis
1216

1317
安装步骤如下:
1418

@@ -56,3 +60,6 @@ cd /opt/redis/redis-4.0.8/src
5660
以上两种安装方式,我都写了脚本去执行:
5761

5862
| [安装脚本](https://github.com/dunwu/linux-tutorial/tree/master/codes/linux/soft) |
63+
64+
## 参考资料
65+

0 commit comments

Comments
 (0)