diff --git a/README.md b/README.md index be7a9b7..304dfca 100644 --- a/README.md +++ b/README.md @@ -58,5 +58,6 @@ | [Svn 安装](docs/linux/soft/svn.md) | Svn 是 Subversion 的简称,是一个开放源代码的版本控制系统,它采用了分支管理系统。 | | [Tomcat 安装](docs/linux/soft/tomcat.md) | Java 应用服务器 | | [Zookeeper 安装](docs/linux/soft/zookeeper.md) | 分布式系统协调软件 | +| [Nacos 安装](linux/soft/nacos.md) | 微服务发现、管理 | ## [Docker](docs/docker) diff --git a/codes/linux/ops/soft/README.md b/codes/linux/ops/soft/README.md index 2bd579d..ccf983f 100644 --- a/codes/linux/ops/soft/README.md +++ b/codes/linux/ops/soft/README.md @@ -148,6 +148,19 @@ curl -o- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/lin wget -qO- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/soft/rocketmq-install.sh | bash ``` +## Nacos 安装 + +说明: + +下载 Nacos `1.0.0` 并解压安装到 `/opt/nacos` 路径下。 + +使用方法:执行以下任意命令即可执行脚本。 + +```sh +curl -o- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/soft/nacos-install.sh | bash +wget -qO- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/soft/nacos-install.sh | bash +``` + ## ZooKeeper 安装 说明: diff --git a/codes/linux/ops/soft/jdk8-install.sh b/codes/linux/ops/soft/jdk8-install.sh index c87483e..1a60024 100644 --- a/codes/linux/ops/soft/jdk8-install.sh +++ b/codes/linux/ops/soft/jdk8-install.sh @@ -11,6 +11,8 @@ cat << EOF EOF +command -v yum >/dev/null 2>&1 || { echo >&2 "Require yum but it's not installed. Aborting."; exit 1; } + echo -e "\n>>>>>>>>> install jdk8" yum -y install java-1.8.0-openjdk.x86_64 diff --git a/codes/linux/ops/soft/kafka-install.sh b/codes/linux/ops/soft/kafka-install.sh index 7db97bb..b913cc8 100644 --- a/codes/linux/ops/soft/kafka-install.sh +++ b/codes/linux/ops/soft/kafka-install.sh @@ -10,6 +10,11 @@ cat << EOF EOF +if [[ $# -lt 1 ]] || [[ $# -lt 2 ]];then + echo "Usage: sh kafka-install.sh [version] [path]" + echo -e "Example: sh kafka-install.sh 2.2.0 /opt/kafka\n" +fi + version=2.2.0 if [[ -n $1 ]]; then version=$1 @@ -20,6 +25,7 @@ if [[ -n $2 ]]; then root=$2 fi +echo "Current execution: install kafka ${version} to ${root}" echo -e "\n>>>>>>>>> download kafka" mkdir -p ${root} wget -O ${root}/kafka_2.12-${version}.tgz http://mirrors.tuna.tsinghua.edu.cn/apache/kafka/${version}/kafka_2.12-${version}.tgz diff --git a/codes/linux/ops/soft/maven-install.sh b/codes/linux/ops/soft/maven-install.sh index b8c7c96..a563e43 100644 --- a/codes/linux/ops/soft/maven-install.sh +++ b/codes/linux/ops/soft/maven-install.sh @@ -10,6 +10,13 @@ cat << EOF ################################################################################### EOF +command -v java >/dev/null 2>&1 || { echo >&2 "Require java but it's not installed. Aborting."; exit 1; } + +if [[ $# -lt 1 ]] || [[ $# -lt 2 ]];then + echo "Usage: sh maven-install.sh [version] [path]" + echo -e "Example: sh maven-install.sh 3.6.0 /opt/maven\n" +fi + version=3.6.0 if [[ -n $1 ]]; then version=$1 @@ -20,6 +27,8 @@ if [[ -n $2 ]]; then root=$2 fi +echo "Current execution: install maven ${version} to ${root}" + echo -e "\n>>>>>>>>> download maven" mkdir -p ${root} wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" -O ${root}/apache-maven-${version}-bin.tar.gz http://mirrors.tuna.tsinghua.edu.cn/apache/maven/maven-3/${version}/binaries/apache-maven-${version}-bin.tar.gz diff --git a/codes/linux/ops/soft/mongodb-install.sh b/codes/linux/ops/soft/mongodb-install.sh index 9f668bf..45670b5 100644 --- a/codes/linux/ops/soft/mongodb-install.sh +++ b/codes/linux/ops/soft/mongodb-install.sh @@ -10,6 +10,11 @@ cat << EOF EOF +if [[ $# -lt 1 ]] || [[ $# -lt 2 ]];then + echo "Usage: sh mongodb-install.sh [version] [path]" + echo -e "Example: sh mongodb-install.sh 4.0.9 /opt/mongodb\n" +fi + version=4.0.9 if [[ -n $1 ]]; then version=$1 @@ -20,6 +25,8 @@ if [[ -n $2 ]]; then root=$2 fi +echo "Current execution: install mongodb ${version} to ${root}" + echo -e "\n>>>>>>>>> download mongodb" mkdir -p ${root} wget -O ${root}/mongodb-linux-x86_64-${version}.tgz https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-${version}.tgz diff --git a/codes/linux/ops/soft/nacos-install.sh b/codes/linux/ops/soft/nacos-install.sh new file mode 100644 index 0000000..0ab816d --- /dev/null +++ b/codes/linux/ops/soft/nacos-install.sh @@ -0,0 +1,41 @@ +#!/usr/bin/env bash + +cat << EOF + +################################################################################### +# 安装 nacos 脚本 +# 需要提前安装 jdk、maven +# @system: 适用于所有 linux 发行版本。 +# @author: Zhang Peng +################################################################################### + +EOF + +command -v java >/dev/null 2>&1 || { echo >&2 "Require java but it's not installed. Aborting."; exit 1; } +command -v mvn >/dev/null 2>&1 || { echo >&2 "Require mvn but it's not installed. Aborting."; exit 1; } + +if [[ $# -lt 1 ]] || [[ $# -lt 2 ]];then + echo "Usage: sh nacos-install.sh [version] [path]" + printf "Example: sh nacos-install.sh 1.0.0 /opt/nacos\n" +fi + +version=1.0.0 +if [[ -n $1 ]]; then + version=$1 +fi + +root=/opt/nacos +if [[ -n $2 ]]; then + root=$2 +fi + +echo "Current execution: install nacos ${version} to ${root}" + +echo -e "\n>>>>>>>>> download nacos" +mkdir -p ${root} +wget -O ${root}/nacos-server-${version}.zip https://github.com/alibaba/nacos/releases/download/${version}/nacos-server-${version}.zip + +echo -e "\n>>>>>>>>> install nacos" +unzip ${root}/nacos-server-${version}.zip -d ${root}/nacos-server-${version} +mv ${root}/nacos-server-${version}/nacos/* ${root}/nacos-server-${version} +rm -rf ${root}/nacos-server-${version}/nacos diff --git a/codes/linux/ops/soft/nginx-install.sh b/codes/linux/ops/soft/nginx-install.sh index 2c277bf..b416180 100644 --- a/codes/linux/ops/soft/nginx-install.sh +++ b/codes/linux/ops/soft/nginx-install.sh @@ -11,6 +11,13 @@ cat << EOF EOF +command -v yum >/dev/null 2>&1 || { echo >&2 "Require yum but it's not installed. Aborting."; exit 1; } + +if [[ $# -lt 1 ]] || [[ $# -lt 2 ]];then + echo "Usage: sh nginx-install.sh [version] [path]" + echo -e "Example: sh nginx-install.sh 1.16.0 /opt/nginx\n" +fi + version=1.16.0 if [[ -n $1 ]]; then version=$1 @@ -21,6 +28,7 @@ if [[ -n $2 ]]; then root=$2 fi +echo "Current execution: install nginx ${version} to ${root}" echo -e "\n>>>>>>>>> install libs" yum install -y zlib zlib-devel gcc-c++ libtool openssl openssl-devel pcre diff --git a/codes/linux/ops/soft/nodejs-install.sh b/codes/linux/ops/soft/nodejs-install.sh index fc3f13c..4862707 100644 --- a/codes/linux/ops/soft/nodejs-install.sh +++ b/codes/linux/ops/soft/nodejs-install.sh @@ -10,6 +10,11 @@ cat << EOF EOF +if [[ $# -lt 1 ]] || [[ $# -lt 2 ]];then + echo "Usage: sh nodejs-install.sh [version] [path]" + echo -e "Example: sh nodejs-install.sh 10.15.2 /opt/nodejs\n" +fi + version=10.15.2 if [[ -n $1 ]]; then version=$1 @@ -26,6 +31,7 @@ if [[ ${execode} != 0 ]]; then nvm --version fi +echo "Current execution: install nodejs ${version} to ${root}" echo -e "\n>>>>>>>>> install nodejs by nvm" nvm install ${version} nvm use ${version} diff --git a/codes/linux/ops/soft/redis-install.sh b/codes/linux/ops/soft/redis-install.sh index c3b7d6b..cc2ca8c 100644 --- a/codes/linux/ops/soft/redis-install.sh +++ b/codes/linux/ops/soft/redis-install.sh @@ -10,6 +10,13 @@ cat << EOF EOF +command -v yum >/dev/null 2>&1 || { echo >&2 "Require yum but it's not installed. Aborting."; exit 1; } + +if [[ $# -lt 1 ]] || [[ $# -lt 2 ]] || [[ $# -lt 3 ]] || [[ $# -lt 4 ]];then + echo "Usage: sh redis-install.sh [version] [path] [port] [password]" + echo -e "Example: sh redis-install.sh 5.0.4 /opt/redis 6379 123456\n" +fi + version=5.0.4 if [[ -n $1 ]]; then version=$1 @@ -30,6 +37,7 @@ if [[ -n $4 ]]; then path=$4 fi +echo "Current execution: install redis ${version} to ${root}, service port = ${port}, password = ${password}" echo -e "\n>>>>>>>>> install libs" yum install -y zlib zlib-devel gcc-c++ libtool openssl openssl-devel tcl diff --git a/codes/linux/ops/soft/rocketmq-install.sh b/codes/linux/ops/soft/rocketmq-install.sh index d3c3652..bc97613 100644 --- a/codes/linux/ops/soft/rocketmq-install.sh +++ b/codes/linux/ops/soft/rocketmq-install.sh @@ -10,6 +10,11 @@ cat << EOF EOF +if [[ $# -lt 1 ]] || [[ $# -lt 2 ]];then + echo "Usage: sh rocketmq-install.sh [version] [path]" + echo -e "Example: sh rocketmq-install.sh 4.5.0 /opt/rocketmq\n" +fi + version=4.5.0 if [[ -n $1 ]]; then version=$1 @@ -20,9 +25,12 @@ if [[ -n $2 ]]; then root=$2 fi +echo "Current execution: install rocketmq ${version} to ${root}" echo -e "\n>>>>>>>>> download rocketmq" mkdir -p ${root} wget -O ${root}/rocketmq-all-${version}-bin-release.zip http://mirrors.tuna.tsinghua.edu.cn/apache/rocketmq/${version}/rocketmq-all-${version}-bin-release.zip echo -e "\n>>>>>>>>> install rocketmq" unzip -o ${root}/rocketmq-all-${version}-bin-release.zip -d ${root}/rocketmq-all-${version}/ +mv ${root}/rocketmq-all-${version}/rocketmq-all-${version}-bin-release/* ${root}/rocketmq-all-${version} +rm -rf ${root}/rocketmq-all-${version}/rocketmq-all-${version}-bin-release diff --git a/codes/linux/ops/soft/tomcat8-install.sh b/codes/linux/ops/soft/tomcat8-install.sh index 524ea66..a20e0e8 100644 --- a/codes/linux/ops/soft/tomcat8-install.sh +++ b/codes/linux/ops/soft/tomcat8-install.sh @@ -10,6 +10,11 @@ cat << EOF EOF +if [[ $# -lt 1 ]] || [[ $# -lt 2 ]];then + echo "Usage: sh tomcat8-install.sh [version] [path]" + echo -e "Example: sh tomcat8-install.sh 8.5.28 /opt/tomcat8\n" +fi + version=8.5.28 if [[ -n $1 ]]; then version=$1 @@ -20,6 +25,7 @@ if [[ -n $2 ]]; then root=$2 fi +echo "Current execution: install tomcat8 ${version} to ${root}" echo -e "\n>>>>>>>>> download tomcat" mkdir -p ${root} wget -O ${root}/apache-tomcat-${version}.tar.gz https://archive.apache.org/dist/tomcat/tomcat-8/v${version}/bin/apache-tomcat-${version}.tar.gz diff --git a/codes/linux/ops/soft/zookeeper-install.sh b/codes/linux/ops/soft/zookeeper-install.sh index 7ca6676..55db52e 100644 --- a/codes/linux/ops/soft/zookeeper-install.sh +++ b/codes/linux/ops/soft/zookeeper-install.sh @@ -10,6 +10,11 @@ cat << EOF EOF +if [[ $# -lt 1 ]] || [[ $# -lt 2 ]];then + echo "Usage: sh zookeeper-install.sh [version] [path]" + echo -e "Example: sh zookeeper-install.sh 3.4.12 /opt/zookeeper\n" +fi + version=3.4.12 if [[ -n $1 ]]; then version=$1 @@ -20,6 +25,7 @@ if [[ -n $2 ]]; then root=$2 fi +echo "Current execution: install zookeeper ${version} to ${root}" echo -e "\n>>>>>>>>> download zookeeper" mkdir -p ${root} wget -O ${root}/zookeeper-${version}.tar.gz http://mirrors.hust.edu.cn/apache/zookeeper/zookeeper-${version}/zookeeper-${version}.tar.gz diff --git a/codes/linux/ops/soft/zsh-install.sh b/codes/linux/ops/soft/zsh-install.sh index dcf91ca..5892950 100644 --- a/codes/linux/ops/soft/zsh-install.sh +++ b/codes/linux/ops/soft/zsh-install.sh @@ -11,6 +11,8 @@ cat << EOF EOF +command -v yum >/dev/null 2>&1 || { echo >&2 "Require yum but it's not installed. Aborting."; exit 1; } + echo -e "\n>>>>>>>>> install zsh" yum install -y zsh @@ -20,7 +22,7 @@ wget https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh -O - sed -i "s#^ZSH_THEME=.*#ZSH_THEME=\"ys\"#g" ~/.zshrc # 下载 incr.zsh 补全插件 wget http://mimosa-pudica.net/src/incr-0.2.zsh -cp incr-0.2.zsh ~/.oh-my-zsh/plugins/incr/ +mv incr-0.2.zsh ~/.oh-my-zsh/plugins/incr/ echo "source ~/.oh-my-zsh/plugins/incr/incr*.zsh" >> ~/.zshrc # 更新配置 diff --git a/docs/linux/soft/nacos.md b/docs/linux/soft/nacos.md new file mode 100644 index 0000000..9b1df6f --- /dev/null +++ b/docs/linux/soft/nacos.md @@ -0,0 +1,103 @@ +# Nacos 安装配置 + +> [Nacos](https://nacos.io/zh-cn/) 是一款发现、配置和管理微服务的软件。 + +## 1.预备环境准备 + +Nacos 依赖 [Java](https://docs.oracle.com/cd/E19182-01/820-7851/inst_cli_jdk_javahome_t/) 环境来运行。如果您是从代码开始构建并运行Nacos,还需要为此配置 [Maven](https://maven.apache.org/index.html)环境,请确保是在以下版本环境中安装使用: + +1. 64 bit OS,支持 Linux/Unix/Mac/Windows,推荐选用 Linux/Unix/Mac。 +2. 64 bit JDK 1.8+;[下载](http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html) & [配置](https://docs.oracle.com/cd/E19182-01/820-7851/inst_cli_jdk_javahome_t/)。 +3. Maven 3.2.x+;[下载](https://maven.apache.org/download.cgi) & [配置](https://maven.apache.org/settings.html)。 + +## 2.下载源码或者安装包 + +你可以通过源码和发行包两种方式来获取 Nacos。 + +### 从 Github 上下载源码方式 + +```bash +git clone https://github.com/alibaba/nacos.git +cd nacos/ +mvn -Prelease-nacos clean install -U +ls -al distribution/target/ + +// change the $version to your actual path +cd distribution/target/nacos-server-$version/nacos/bin +``` + +### 下载编译后压缩包方式 + +您可以从 [最新稳定版本](https://github.com/alibaba/nacos/releases) 下载 `nacos-server-$version.zip` 包。 + +```bash + unzip nacos-server-$version.zip 或者 tar -xvf nacos-server-$version.tar.gz + cd nacos/bin +``` + +## 3.启动服务器 + +### Linux/Unix/Mac + +启动命令(standalone代表着单机模式运行,非集群模式): + +``` +sh startup.sh -m standalone +``` + +### Windows + +启动命令: + +``` +cmd startup.cmd +``` + +或者双击startup.cmd运行文件。 + +## 4.服务注册&发现和配置管理 + +### 服务注册 + +``` +curl -X POST 'http://127.0.0.1:8848/nacos/v1/ns/instance?serviceName=nacos.naming.serviceName&ip=20.18.7.10&port=8080' +``` + +### 服务发现 + +``` +curl -X GET 'http://127.0.0.1:8848/nacos/v1/ns/instances?serviceName=nacos.naming.serviceName' +``` + +### 发布配置 + +``` +curl -X POST "http://127.0.0.1:8848/nacos/v1/cs/configs?dataId=nacos.cfg.dataId&group=test&content=HelloWorld" +``` + +### 获取配置 + +``` +curl -X GET "http://127.0.0.1:8848/nacos/v1/cs/configs?dataId=nacos.cfg.dataId&group=test" +``` + +## 5.关闭服务器 + +### Linux/Unix/Mac + +``` +sh shutdown.sh +``` + +### Windows + +``` +cmd shutdown.cmd +``` + +或者双击shutdown.cmd运行文件。 + +## 参考资料 + +- [Nacos Quick Start](https://nacos.io/zh-cn/docs/quick-start.html) + diff --git a/docs/navbar.md b/docs/navbar.md index 936f868..358b0b3 100644 --- a/docs/navbar.md +++ b/docs/navbar.md @@ -22,3 +22,4 @@ - [Svn 安装](linux/soft/svn.md) - [Tomcat 安装](linux/soft/tomcat.md) - [Zookeeper 安装](linux/soft/zookeeper.md) + - [Nacos 安装](linux/soft/nacos.md)