@abelsu7
2019-05-19T12:10:51.000000Z
字数 15784
阅读 4935
IBM
LinuxONE
RHEL
云计算
登录后,进入Manage Instances
,点击Create
:
选择General purpose VM
,输入实例名,并选择RHEL7.6
镜像:
在Select a SSH Key Pair
下,点击Create
,并在弹出窗口中输入密钥名,创建密钥:
之后会保存一个名为myKey.pem
的文件:
最后选中刚才创建的 SSH Key,点击Create
创建实例。等待一段时间后,即可看到实例处于ACTIVE
状态。记录下实例的 IP 地址,并确认用户名是否为linux1
:
如果你用的是 Mac 或 Linux,可以直接使用该密钥文件登录:
ssh -i /path/to/key/keyname.pem linux1@serveripaddress
如果是 Windows,可以使用 PuTTY,步骤如下:
下载并安装 PuTTY
打开 PuTTYgen,点击Load
,选择刚才保存的.pem
文件将其导入,之后 PuTTY 会提示导入成功:
Save private key
,保存*.ppk
私钥文件,名字任取为了方便退出 PuTTY 后再次登录,在Saved Sessions
中输入会话名,然后点Save
保存:
最后双击LinuxOne
会话登录。当提示输入用户名时,输入linux1
即可登录:
PuTTY 快捷键:复制
Ctrl+Insert
,粘贴Shift+Insert
Github Repo:Cloud-Native-Workloads-on-LinuxONE
[linux1@myserver ~]$ sudo su # 切换至 root
[root@myserver linux1]$ cd ~
[root@myserver ~]$ wget ftp://ftp.unicamp.br/pub/linuxpatch/s390x/redhat/rhel7.3/docker-17.05.0-ce-rhel7.3-20170523.tar.gz
# 解压 Docker 归档包
[root@myserver ~]$ tar -xzvf docker-17.05.0-ce-rhel7.3-20170523.tar.gz
[root@myserver ~]$ cp docker-17.05.0-ce-rhel7.3-20170523/docker* /usr/bin/
注意:这里直接
cp
到/usr/bin
就好,因为/usr/local/bin
不在PATH
环境变量里
之后启动docker daemon
:
[root@myserver ~]$ docker daemon -g /local/docker/lib &
输出类似如下内容:
[root@myserver ~]$ docker daemon -g /local/docker/lib &
[1] 21376
[root@myserver ~]$ Command "daemon" is deprecated, and will be removed in Docker 17.12. Please run `dockerd` directly.
WARN[0000] the "-g / --graph" flag is deprecated. Please use "--data-root" instead
WARN[0000] could not change group /var/run/docker.sock to docker: group docker not found
INFO[0000] libcontainerd: new containerd process, pid: 21387
WARN[0000] containerd: low RLIMIT_NOFILE changing to max current=1024 max=4096
INFO[0001] Graph migration to content-addressability took 0.00 seconds
INFO[0001] Loading containers: start.
INFO[0001] Default bridge (docker0) is assigned with an IP address 172.17.0.0/16. Daemon option --bip can be used to set a preferred IP address
INFO[0001] Loading containers: done.
INFO[0001] Daemon has completed initialization
INFO[0001] Docker daemon commit=89658be graphdriver=overlay version=17.05.0-ce
INFO[0001] API listen on /var/run/docker.sock
启动完成后,检查一下后台有无docker
进程运行:
[root@myserver ~]$ ps aux | grep docker
root 21505 0.1 1.1 508456 43508 ? Sl 10:55 0:51 dockerd -g /local/docker/lib root 21515 0.0 0.3 213372 12868 ? Ssl 10:55 0:26 docker-containerd -l unix:///var/run/docker/libcontainerd/docker-containerd.sock --metrics-interval=0 --start-timeout 2m --state-dir /var/run/docker/libcontainerd/containerd --shim docker-containerd-shim --runtime docker-runc
[root@myserver ~]$ docker version
Client:
Version: 17.05.0-ce
API version: 1.29
Go version: go1.8.1
Git commit: 89658be
Built: Tue May 23 20:15:42 2017
OS/Arch: linux/s390x
Server:
Version: 17.05.0-ce
API version: 1.29 (minimum version 1.12)
Go version: go1.8.1
Git commit: 89658be
Built: Tue May 23 20:15:42 2017
OS/Arch: linux/s390x
Experimental: false
使用yum
安装python-setuptools
:
[root@myserver ~]$ yum info python-setuptools
Name : python-setuptools
Arch : noarch
Version : 0.9.8
Release : 7.el7
Size : 1.9 M
Repo : installed
From repo : rhel7-base
Summary : Easily build and distribute Python packages
URL : http://pypi.python.org/pypi/setuptools
License : Python or ZPLv2.0
Description : Setuptools is a collection of enhancements to the Python
: distutils that allow you to more easily build and distribute
: Python packages, especially ones that have dependencies on
: other packages.
:
: This package contains the runtime components of setuptools,
: necessary to execute the software that requires
: pkg_resources.py.
:
: This package contains the distribute fork of setuptools.
[root@myserver ~]$ yum install -y python-setuptools
之后使用easy_install
安装pip
:
网速过慢的话先禁用掉 IPv6:
echo 1 > /proc/sys/net/ipv6/conf/all/disable_ipv6
[root@myserver ~]$ easy_install pip
升级backports.ssl_match_hostname
,由于系统自带安装了backports.ssl-match-hostname 3.5.0.1
,pip 无法将其卸载,这里会提示出错:
[root@myserver ~]$ pip install backports.ssl_match_hostname --upgrade
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.
Collecting backports.ssl_match_hostname
Downloading https://files.pythonhosted.org/packages/ff/2b/8265224812912bc5b7a607c44bf7b027554e1b9775e9ee0de8032e3de4b2/backports.ssl_match_hostname-3.7.0.1.tar.gz
Installing collected packages: backports.ssl-match-hostname
Found existing installation: backports.ssl-match-hostname 3.5.0.1
ERROR: Cannot uninstall 'backports.ssl-match-hostname'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.
添加--ignore-installed
参数即可解决:
[root@myserver ~]$ pip install backports.ssl_match_hostname --upgrade --ignore-installed
最后,使用pip
安装docker-compose
:
[root@myserver ~]$ yum install python-devel libffi-devel # 先安装依赖,不然会报错
[root@myserver ~]$ pip install docker-compose==1.13.0
注意:这里若不指定版本,会报
ImportError: No module named glob
的错误,pip install glob2
也无法解决。。暂时没找到解决办法
验证一下docker-compose
是否已经安装:
[root@myserver ~]$ docker-compose version
docker-compose version 1.13.0, build 1719ceb
docker-py version: 2.7.0
CPython version: 2.7.5
OpenSSL version: OpenSSL 1.0.2k-fips 26 Jan 2017
先手动拉取websphere-liberty
镜像到本地:
[root@myserver ~]$ docker image pull s390x/websphere-liberty:webProfile7
webProfile7: Pulling from s390x/websphere-liberty
a39cfce7a60d: Pull complete
4e699efbddb6: Pull complete
9a3ffeac4412: Pull complete
52c5a080fd6d: Pull complete
6f0d27faa63a: Pull complete
a3d346a6c218: Pull complete
e9129f75e0bc: Pull complete
905ebfd4a924: Pull complete
bd9b8600bfe7: Pull complete
5746a3a16c6e: Pull complete
621479e04496: Pull complete
26db9a45b5d9: Pull complete
32c81cd7fa4a: Pull complete
705855d9301f: Pull complete
0bd5ae8e4470: Pull complete
Digest: sha256:87e41c209fa1c8ab33fc0cd0e126eec1493a50c49fe557f398707b4f4755d07a
Status: Downloaded newer image for s390x/websphere-liberty:webProfile7
[root@myserver ~]$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
s390x/websphere-liberty webProfile7 def868b21def 27 hours ago 473MB
后台运行容器,并指定端口映射规则:
[root@myserver ~]$ docker run -d -p 80:9080 -p 443:9443 s390x/websphere-liberty:webProfile7
3c9d3b02de11bc5b912a8df1b3987e60bf797ea02cbbbc4457a6e09307f3c95e
[root@myserver ~]$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3c9d3b02de11 s390x/websphere-liberty:webProfile7 "/opt/ibm/helpers/..." 21 seconds ago Up 19 seconds 0.0.0.0:80->9080/tcp, 0.0.0.0:443->9443/tcp mystifying_golick
浏览器访问http://[LinuxOne Host IP]
,即可看到WebSphere Liberty
的界面:
首先,RHEL 7.6
已经自带安装了VIM 7.4
,启动命令是vi
,习惯用vim
命令的同学可以先设置一下别名:
[root@myserver ~]$ alias vim='vi'
不过该别名仅在当前会话中生效。可以将上面这句加到~/.bashrc
中,再使用source
命令使其生效:
[root@myserver ~]$ source ~/.bashrc
创建并编辑docker-compose.yml
:
[root@myserver ~]$ vim docker-compose.yml
按i
进入编辑模式(所有 Vim 命令注意区分大小写),输入以下内容:
version: '2'
services:
wordpress:
image: s390x/wordpress
ports:
- 8080:80 # 将本地 8080 端口映射到容器的 80 端口
environment:
WORDPRESS_DB_PASSWORD: example
mysql:
image: brunswickheads/mariadb-5.5-s390x
environment:
MYSQL_ROOT_PASSWORD: example
之后按Esc
退出编辑模式,输入:wq
保存并退出。
检查一下docker-compose.yml
的内容:
[root@myserver ~]$ cat docker-compose.yml
version: '2'
services:
wordpress:
image: s390x/wordpress
ports:
- 8080:80 # 将本地 8080 端口映射到容器的 80 端口
environment:
WORDPRESS_DB_PASSWORD: example
mysql:
image: brunswickheads/mariadb-5.5-s390x
environment:
MYSQL_ROOT_PASSWORD: example
创建wordpress
目录方便整理:
[root@myserver ~]$ mkdir wordpress
[root@myserver ~]$ mv docker-compose.yml wordpress/
[root@myserver ~]$ cd wordpress/
[root@myserver wordpress]$ ls
docker-compose.yml
最后,根据docker-compose.yml
中定义的服务启动容器:
[root@myserver wordpress]$ docker-compose up -d
创建完成后,查看相关容器的状态:
[root@myserver wordpress]$ docker-compose ps
Name Command State Ports
-------------------------------------------------------------------------------------
wordpress_mysql_1 /docker-entrypoint.sh mysq ... Up 3306/tcp
wordpress_wordpress_1 docker-entrypoint.sh apach ... Up 0.0.0.0:8080->80/tcp
浏览器访问http://[Your LinuxONE IP Address]:8080
,即可看到 WordPress 的页面:
MEAN
Stack :
实验是参考 Creating a Single Page Todo App with Node and Angular | Scotch.io 这篇文章作为示例,简单起见代码主要目录如下:
-app (Express routes and MongoDB connections)
-config (MongoDB and other config parameters)
-public (Frontend : Angular.js code, index page etc)
实验的 Github Repo 中已经准备了这部分代码,可以直接拉取到本地使用:
[root@myserver ~]$ git clone https://github.com/IBM/Cloud-Native-Workloads-on-LinuxONE
[root@myserver ~]$ cp -r Cloud-Native-Workloads-on-LinuxONE/files/mean-docker ./
[root@myserver ~]$ yum install -y tree
[root@myserver ~]$ tree mean-docker
mean-docker
├── docker-compose.yml
├── express-server
│ ├── app
│ │ ├── models
│ │ │ └── todo.js
│ │ └── routes.js
│ ├── config
│ │ └── database.js
│ ├── Dockerfile
│ ├── license
│ ├── package.json
│ ├── public
│ │ ├── index.html
│ │ └── js
│ │ ├── controllers
│ │ │ └── main.js
│ │ ├── core.js
│ │ └── services
│ │ └── todos.js
│ ├── README.md
│ └── server.js
└── README.md
8 directories, 14 files
首先修改 Angular.js 的 CDN 为国内的源:
[root@myserver ~]$ ll
total 28K
-rw-------. 1 root root 1.4K Aug 23 2016 anaconda-ks.cfg
drwxr-xr-x 6 root root 4.0K May 16 23:28 Cloud-Native-Workloads-on-LinuxONE
drwxr-xr-x 2 root root 4.0K May 23 2017 docker-17.05.0-ce-rhel7.3-20170523
drwxr-xr-x 11 linadm users 4.0K May 16 23:22 htop-2.2.0
drwxr-xr-x 5 root root 4.0K May 17 04:47 ICp-banking-microservices
drwxr-xr-x 3 root root 4.0K May 18 23:22 mean-docker
drwxr-xr-x 2 root root 4.0K May 16 23:10 wordpress
[root@myserver ~]$ vi mean-docker/express-server/public/index.html
然后修改高亮的部分为以下内容:
//cdn.bootcss.com/angular.js/1.2.16/angular.min.js
注意:如果之前使用
docker-compose up
启动过应用,则需要先重新构建镜像,再启动应用,以下是说明:
[root@myserver ~]$ cd mean-docker
[root@myserver mean-docker]$ docker-compose down # 停止正在运行的容器
[root@myserver mean-docker]$ docker-compose build # 先重新构建镜像
[root@myserver mean-docker]$ docker-compose up # 再基于新镜像重新启动容器
看到两个绿色的done
,就可以访问:8081
端口查看应用了。
重新构建镜像说明结束
查看docker-compose.yml
的内容:
[root@myserver ~]$ cd mean-docker/
[root@myserver mean-docker]$ ls
docker-compose.yml express-server README.md
[root@myserver mean-docker]$ vim docker-compose.yml
docker-compose.yml
内容如下:
version: '2' # specify docker-compose version
# Define the services/containers to be run
services:
express: # name of the second service
build: express-server # specify the directory of the Dockerfile
ports:
- "8080:8080" # specify ports forwarding
links:
- database
database: # name of the third service
image: mongo # specify image to build container from
ports:
- "27017:27017" # specify port forewarding
查看express-server/Dockerfile
:
[root@myserver mean-docker]$ vim express-server/Dockerfile
Dockerfile
内容如下:
FROM s390x/ibmnode:latest
# Create a directory where our app will be placed
RUN mkdir -p /usr/src
# Change directory so that our commands run inside this new dir
WORKDIR /usr/src
# Copy dependency definitions
COPY package.json /usr/src
# Install dependecies
RUN npm install
# Get all the code needed to run the app
COPY . /usr/src
# Expose the port the app runs in
EXPOSE 8080
# Serve the app
CMD ["npm", "start"]
注意:需要一些 Docker 基础知识,可以参考 Docker 实践简明指南
因为之前本地的8080
端口被 WordPress 占用了,所以这里我们使用8081
端口。
docker-compose.yml
修改如下:
...
...
ports:
- "8081:8081" # 本地 8081 端口映射到 express 容器的 8081 端口
...
...
express-server/Dockerfile
修改如下:
# Expose the port the app runs in
EXPOSE 8081
...
...
# Express listening port
ENV PORT 8081
在mean-docker
目录下运行docker-compose up
:
[root@myserver mean-docker]$ docker-compose up
Starting meandocker_database_1 ...
Starting meandocker_database_1 ... done
Starting meandocker_express_1 ...
Starting meandocker_express_1 ... done
Attaching to meandocker_database_1, meandocker_express_1
database_1 | note: noprealloc may hurt performance in many applications
express_1 |
express_1 | > node-todo@0.0.1 start /usr/src
express_1 | > node server.js
express_1 |
express_1 | App listening on port 8081
使用
docker-compose -d
即可在后台运行express-server
浏览器访问http://[ip of machine]:8081
,即可看到你的 TODO-List App:
使用docker-compose ps
命令查看启动的容器:
[root@myserver mean-docker]$ docker-compose ps
Name Command State Ports
----------------------------------------------------------------------------------------------------
meandocker_database_1 /bin/sh -c mongod --dbpath ... Up 0.0.0.0:27017->27017/tcp, 28017/tcp
meandocker_express_1 npm start Up 0.0.0.0:8081->8081/tcp
Github Repo:ICp-banking-microservices
首先登录 Github,Fork 该实验的 Github Repo - ICp-banking-microservices 到自己账号下:
因为之后要使用 Git 的命令行工具,推荐下载 Cmder,选择Download Full
,其中包含了Git for Windows
:
之后运行Cmder.exe
,验证 Git 是否可用:
将你 Fork 的项目git clone
至本地:
git clone https://github.com/YOUR_USERNAME/ICp-banking-microservices
注意:因为我已经在 Github 上配好了
SSH Key
,所以选择的是Clone with SSH
。未配置SSH Key
使用Clone with HTTPS
的链接就可以,只是在每次git push
的时候要输入用户名和密码
最后在 IDE 中打开源码目录banking-application
(推荐 VS Code):
app.js
:server codepublic/index.html
:client code (banking dashboard)public/css
:Bootstrap 4.1.0public/js
:JS 库,包括Bootstrap
、JQuery
、popper.js
和bankingAPI
package.json
:Node .js相关依赖包Dockerfile
:用于构建 Docker 镜像首先注册一个 IBM ID。
之后前往 API Developer Portal,点击Create an account
创建新用户。注意:要使用之前注册 IBM ID 的邮箱进行注册:
注册完毕后登录,在Apps
选项卡下点击Create new App
创建新应用:
Title
输入My Banking Application
即可,之后点击Submit
提交:
注意:需要记录下
Client ID
和Client Secret
,之后会用到。
之后需要申请banking API
。在API Products
选项卡下找到Banking Product
:
点击Subscribe
申请Default Plan
:
选择刚才创建的应用My Banking Application
:
最后在banking-application/public/js/bankingAPI.js
中填入你的Client ID
和Client Secret
:
需要安装 Node.js,选择10.15.3 LTS
下载安装包并安装,之后验证 Node.js 以及 npm 版本:
进入ICp-banking-microservices/banking-application
目录,执行npm install
:
也可以直接在 VS Code 的内建终端中操作
node app.js
启动应用:
浏览器访问http://localhost:3000
,即可访问应用:
随便选择一个customer ID
测试,若有JSON
格式的数据返回,则说明 API 可用:
git add public/js/bankingAPI.js
git commit -m "Update of bankingAPI.js"
git push origin master
注意:实际上不应该把
Client ID
和Client Secret
这种密钥类型的数据推到 Github 上,这里为了方便实验暂时这么做,以后切勿模仿。。
先登录你的 LinuxONE 主机实例,之后将你 Fork 后又更新的代码拉取到本地:
[root@myserver ~]$ git clone https://github.com/abelsu7/ICp-banking-microservices.git # 改成你自己的账号
Cloning into 'ICp-banking-microservices'...
remote: Enumerating objects: 42, done.
remote: Counting objects: 100% (42/42), done.
remote: Compressing objects: 100% (42/42), done.
remote: Total 771 (delta 1), reused 36 (delta 0), pack-reused 729
Receiving objects: 100% (771/771), 5.56 MiB | 0 bytes/s, done.
Resolving deltas: 100% (433/433), done.
之后需要用到banking-application
目录下的Dockerfile
:
FROM ibmcom/ibmnode
WORKDIR "/app"
# Install app dependencies
COPY package.json /app/
RUN cd /app; npm install; npm prune --production
# Bundle app source
COPY . /app
ENV NODE_ENV production
ENV PORT 3000
EXPOSE 3000
CMD ["npm", "start"]
具体含义略。之后使用docker build
命令构建镜像:
[root@myserver ICp-banking-microservices]$ cd banking-application/
[root@myserver banking-application]$ ls
app.js Dockerfile package.json public
[root@myserver banking-application]$ docker build -t "abelsu7-banking-image:latest" ./ # 改成你的用户名
...
...
Successfully built b5b7495e8495
Successfully tagged abelsu7-banking-image:latest
[root@myserver banking-application]$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
abelsu7-banking-image latest b5b7495e8495 About a minute ago 462MB
meandocker_express latest f3cf2438cdb9 5 hours ago 470MB
s390x/websphere-liberty webProfile7 def868b21def 33 hours ago 473MB
ibmcom/ibmnode latest 9a87e4f94692 12 months ago 457MB
s390x/ibmnode latest 9a87e4f94692 12 months ago 457MB
s390x/wordpress latest d3ab4dbbe59f 17 months ago 388MB
sinenomine/mongodb-s390x latest c23b42b446b7 20 months ago 658MB
brunswickheads/mariadb-5.5-s390x latest 1cc1be288a3e 3 years ago 311MB
运行容器:
[root@myserver banking-application]$ docker run -p 3000:3000 abelsu7-banking-image
> banking-application@1.0.0 start /app
> node app.js
To view your app, open this link in your browser: http://localhost:3000
浏览器访问http://[LinuxOne Host IP]:3000
,即可访问应用。
利用 Jenkins 实现 CI/CD 与 DevOps,略
点击 这里 注册申请 ICP,之后从 这里 登录 IBM Cloud Private:
点击右上角的 Catalog
,稍等片刻(页面加载可能比较慢),找到openmplbank
并点击进入:
点击Configure
:
输入Release name
和Target Namespace
:
Release Name
:用于部署的服务名,例如我的就是abelsu7-openmplbank
Target Namespace
:下拉可选,应该只有一个,ns
开头镜像已经指定好了,最后点击Install
,完成配置,ICP 会自动部署:
点击View Helm Release
,查看已部署的服务。
首先确定Deployment
标签下的AVAILABLE
数量为1
,表示有可用的Pod
,之后点击Launch
,浏览器会自动跳转到分配的端口:
之后就和此前的实验一样了,只不过你的应用是部署在 ICP 上,由 Kubernetes 自动维护可用的 Pod 数量: