安裝 CentOS 7 不寫如何安裝了吧 .....裝完 ssh 進去
1. 安裝所需的
[root@localhost ~]# yum -y install yum-utils git goling
[root@localhost ~]# yum-config-manager --enable centos-optional-7
[root@localhost ~]# yum install gem
[root@localhost ~]# gem install rhc
[root@localhost ~]# git init
2. 設定 rhc
[root@localhost ~]# rhc setup
OpenShift Client Tools (RHC) Setup Wizard
This wizard will help you upload your SSH keys, set your application namespace, and check that other programs like Git are properly installed.
If you have your own OpenShift server, you can specify it now. Just hit enter to use the server for OpenShift Online: openshift.redhat.com.
Enter the server hostname: |openshift.redhat.com|
You can add more servers later using 'rhc server'.
Login to openshift.redhat.com: chio@test.com
Password: **************
OpenShift can create and store a token on disk which allows to you to access the server without using your password. The key is stored in your home directory and should be kept secret. You can delete
the key at any time by running 'rhc logout'.
Generate a token now? (yes|no) yes
Generating an authorization token for this client ... lasts 30 days
Saving configuration to /root/.openshift/express.conf ... done
No SSH keys were found. We will generate a pair of keys for you.
Created: /root/.ssh/id_rsa.pub
Your public SSH key must be uploaded to the OpenShift server to access code. Upload now? (yes|no) yes
default (type: ssh-rsa)
-----------------------
Fingerprint: e9:48:58:d6:a9:88:06:8c:00:00:00:1b:dc:90:b6:47
You can enter a name for your key, or leave it blank to use the default name. Using the same name as an existing key will overwrite the old key.
Provide a name for this key: |chiolocalhost|
Uploading key 'chiolocalhost' ... done
Checking for git ... found git version 1.8.3.1
Checking common problems .. done
Checking for a domain ... test
Checking for applications ...
You are using 0 of 3 total gears
The following gear sizes are available to you: small
Your client tools are now configured.
3. 建立一個 golang
[root@localhost ~]# rhc app create golang diy
Using diy-0.1 (Do-It-Yourself 0.1) for 'diy'
Application Options
-------------------
Domain: nzgft
Cartridges: diy-0.1
Gear Size: default
Scaling: no
Creating application 'golang ' ... done
Disclaimer: This is an experimental cartridge that provides a way to try unsupported languages, frameworks, and middleware on OpenShift.
Waiting for your DNS name to be available ... done
Cloning into 'golang '...
Warning: Permanently added the RSA host key for IP address '52.101.7.29' to the list of known hosts.
Your application 'myjavademo' is now available.
URL: http://golang -test.rhcloud.com/
SSH to: 584806d30c1e66b945000046@golang -test.rhcloud.com
Git remote: ssh://584806d30c1e66b945000046@golang -test.rhcloud.com/~/git/golang.git/
Cloned to: /root/golang
Run 'rhc show-app golang ' for more details about your app.
4. 抓 git 放到 openshif 剛剛建立的 golang -test.rhcloud.com
[root@localhost ~]# git pull ssh://584806d30c1e66b945000046@golang -test.rhcloud.com/~/git/golang.git/
[root@localhost ~]# cd golang
[root@localhost golang ]# git remote add golang git://github.com/gcmurphy/golang-openshift.git
[root@localhost golang ]# git pull -s recursive -X theirs golang master
........
[root@localhost golang ]# git push
5. 修改程式 .....改成所需的
[root@localhost golang ]# cd server
[root@localhost server ]# vi main.go
package main
import (
"os"
"fmt"
"net/http"
)
func hello(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hi there, I love %s!", r.URL.Path[1:])
}
func main() {
ip := os.Getenv("OPENSHIFT_DIY_IP")
port := os.Getenv("OPENSHIFT_DIY_PORT")
http.HandleFunc("/", hello)
http.ListenAndServe(fmt.Sprintf("%s:%s", ip, port), nil)
}
6. 編譯 main.go
[root@localhost server ]# go build
[root@localhost server ]# mv server ../bin/server
7. 測試 程式 (local 機器 ip : 192.168.0.70 ....請將 iptables 關閉)
[root@localhost server ]# export OPENSHIFT_DIY_IP=192.168.0.70
[root@localhost server ]# export OPENSHIFT_DIY_PORT=8080
[root@localhost server ]# cd ../bin/
[root@localhost bin ]# ./server &
8.開啟測試的網頁
9. 上傳到 openshift
[root@localhost bin ]# cd ..
[root@localhost golang ]# git add .
[root@localhost golang ]# git commit -a -m "test"
[root@localhost golang ]# git push
[root@localhost golang ]# rhc app stop golang
[root@localhost golang ]# rhc app start golang
10. 開openshift 網頁確認
11. 寫個 SVGO Server ....哈參考 github.com/ajstarks/svgo
我有放 github : https://github.com/chio-nzgft/openshift-SVGO-Server
要先抓 go 的 svgo
[root@localhost ~]# go get github.com/ajstarks/svgo
[root@localhost ~]# go install github.com/ajstarks/svgo
程式如下 :
package main
import (
"os"
"fmt"
"net/http"
"github.com/ajstarks/svgo"
"math/rand"
"time"
"log"
)
const arcfmt = "stroke:%s;stroke-opacity:%.2f;stroke-width:%dpx;fill:none"
var colors = []string{"red", "green", "blue", "white", "gray"}
func randarc(canvas *svg.SVG, aw, ah, sw int, f1, f2 bool) {
begin := rand.Intn(aw)
arclength := rand.Intn(aw)
end := begin + arclength
baseline := ah / 2
al := arclength / 2
cl := len(colors)
canvas.Arc(begin, baseline, al, al, 0, f1, f2, end, baseline,
fmt.Sprintf(arcfmt, colors[rand.Intn(cl)], rand.Float64(), rand.Intn(sw)))
}
func main() {
ip := os.Getenv("OPENSHIFT_DIY_IP")
port := os.Getenv("OPENSHIFT_DIY_PORT")
http.Handle("/", http.HandlerFunc(circle))
err := http.ListenAndServe(fmt.Sprintf("%s:%s", ip, port), nil)
if err != nil {
log.Fatal("ListenAndServe:", err)
}
}
func circle(w http.ResponseWriter, req *http.Request) {
w.Header().Set("Content-Type", "image/svg+xml")
rand.Seed(time.Now().UnixNano())
width := 800
height := 800
aw := width / 2
maxstroke := height / 10
literactions := 50
canvas := svg.New(w)
canvas.Start(width, height)
canvas.Rect(0, 0, width, height)
for i := 0; i < literactions; i++ {
randarc(canvas, aw, height, maxstroke, false, true)
randarc(canvas, aw, height, maxstroke, false, false)
}
canvas.End()
}
結果
留言列表