温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

weblogic的部署方法

发布时间:2021-08-25 01:24:48 来源:亿速云 阅读:237 作者:chen 栏目:云计算

本篇内容介绍了“weblogic的部署方法”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

  • 首先是Weblogic的Docker部署。

请仔细阅读:https://my.oschina.net/u/3867634/blog/2246865

至此,我们已经构建了oracle/weblogic:12.2.1.3-developer镜像,为了方便后续使用,我们可以搭建Harbor本地私有镜像仓库,将次镜像push至仓库中。

  • 搭建Harbor仓库

请参阅:https://github.com/goharbor/harbor/blob/release-1.6.0/docs/installation_guide.md

中文版:https://blog.csdn.net/aixiaoyang168/article/details/73549898

搭建完成后,kubernetes节点中需要修改insecure-registry:

//编辑配置docker-option配置文件
vi /etc/systemd/system/docker.service.d/docker-options.conf
//在文件中添加 --insecure-registry=172.17.20.25 
[Service]
Environment="DOCKER_OPTS=--insecure-registry=10.233.0.0/18 --insecure-registry=172.17.20.25 --graph=/var/lib/docker  --log-opt max-size=50m --log-opt max-file=5 \
--iptables=false"
//重启docker
systemctl daemon-reload
systemctl restart docker

然后,将构建好的镜像push至仓库中:

//给image打标签
docker tag oracle/weblogic:12.1.3-developer 172.17.20.25/oracle/weblogic:12.1.3-developer
//push至172.17.20.25
docker push 172.17.20.25/oracle/weblogic:12.1.3-developer

现在,可以登录至http://172.17.20.25查看镜像

weblogic的部署方法

拉取镜像:

    docker pull 172.17.20.25/oracle/weblogic:12.2.1.3-developer
  • kubernetes集群中部署Weblogic

    拉取docker-images代码:

$ git clone https://github.com/oracle/docker-images.git
//进入wls-k8s-domain目录
[root@localhost ~]# cd docker-images/OracleWebLogic/samples/wls-k8s-domain/
[root@localhost wls-k8s-domain]# ls
build.sh  container-scripts  Dockerfile  k8s  README.md

     构建wls-k8s-domain镜像:

$ docker build -t wls-k8s-domain .

将镜像tag打成172.17.20.25/oracle/wls-k8s-domain:1.0后push至Harbor以方便k8s节点拉取。

再修改k8s/wls-admin.yml为如下所示:

apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: admin-server
spec:
  selector:
    matchLabels:
      app: admin-server
  replicas: 1
  template:
    metadata:
      labels:
        app: admin-server
    spec:
      podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
          - labelSelector:
              matchExpressions:
              - key: app
                operator: In
                values:
                - admin-server
            topologyKey: "kubernetes.io/hostname"
      containers:
      - name: admin-server
#image修改为harbor上的名字
        image: 172.17.20.25/oracle/wls-k8s-domain:1.0
        imagePullPolicy: IfNotPresent
        command: ["sh"]
        args: ["/u01/oracle/startadmin.sh"]
        readinessProbe:
            httpGet:
              path: /weblogic/ready
              port: 8001
            initialDelaySeconds: 15
            timeoutSeconds: 5
        ports:
        - containerPort: 8001

        env:
        - name: WLUSER
          valueFrom:
            secretKeyRef:
              name: wlsecret
              key: username
        - name: WLPASSWORD
          valueFrom:
            secretKeyRef:
              name: wlsecret
              key: password
        volumeMounts:
        - mountPath: /u01/wlsdomain
          name: domain-home

      volumes:
      - name: domain-home
        persistentVolumeClaim:
          claimName: wlserver-pvc-1

---

apiVersion: v1
kind: Service
metadata:
  name: admin-server
  labels:
    app: admin-server
spec:
  type: NodePort
  selector:
    app: admin-server
  ports:
    - name: client
      protocol: TCP
      port: 8001
      targetPort: 8001
      nodePort: 30007
  selector:
    app: admin-server

     修改k8s/wls-stateful.yml为:

apiVersion: apps/v1beta1 # for versions before 1.6.0 use extensions/v1beta1
kind: StatefulSet
metadata:
  name: managed-server
spec:
  serviceName: wls-subdomain
  selector:
    matchLabels:
      app: managed-server
  replicas: 2
  template:
    metadata:
      name: ms
      labels:
        app: managed-server
    spec:
#将managed-server与admin-server部署在同一个node上
      affinity:
        podAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
          - labelSelector:
              matchExpressions:
              - key: app
                operator: In
                values:
                - admin-server
            topologyKey: "kubernetes.io/hostname"
      subdomain: wls-subdomain
      containers:
      - name: managed-server
        image: 172.17.20.25/oracle/wls-k8s-domain:1.0
        imagePullPolicy: IfNotPresent
        command: ["sh"]
        args: ["/u01/oracle/startms.sh"]
        readinessProbe:
            httpGet:
              path: /weblogic/ready
              port: 8011
            initialDelaySeconds: 15
            timeoutSeconds: 5
        ports:
        - containerPort: 8011
        env:
        - name: JAVA_OPTIONS
          value: "-Dweblogic.StdoutDebugEnabled=true"
        - name: USER_MEM_ARGS
          value: "-Xms64m -Xmx256m "
        - name: MY_POD_IP
          valueFrom:
            fieldRef:
              fieldPath: status.podIP
        - name: MY_POD_NAME
          valueFrom:
            fieldRef:
              fieldPath: metadata.name
        - name: DNS_DOMAIN_NAME
          value: "wls-subdomain"
        - name: WLUSER
          valueFrom:
            secretKeyRef:
              name: wlsecret
              key: username
        - name: WLPASSWORD
          valueFrom:
            secretKeyRef:
              name: wlsecret
              key: password

        volumeMounts:
        - mountPath: /u01/wlsdomain
          name: domain-home
        - mountPath: /u01/filestores
          name: filestore-data

      volumes:
      - name: domain-home
        persistentVolumeClaim:
          claimName: wlserver-pvc-1
      - name: filestore-data
        persistentVolumeClaim:
          claimName: wlserver-pvc-2
---

apiVersion: v1 # headless service required for statefulSet
kind: Service
metadata:
  name: wls-subdomain
  labels:
    app: managed-server
spec:
  ports:
  - name: client
    port: 8011
    protocol: TCP
    targetPort: 8011
  clusterIP: None
  selector:
    app: managed-server

---

apiVersion: v1
kind: Service
metadata:
  name: wls-service
  labels:
    app: managed-server
spec:
  type: NodePort
  ports:
  - name: client
    port: 8011
    protocol: TCP
    targetPort: 8011
    nodePort: 30009
  selector:
    app: managed-server

修改k8s/pv.yml

kind: PersistentVolume
apiVersion: v1
metadata:
  name: pv1
  labels:
    app: wls-domain
spec:
  storageClassName: manual
  capacity:
    storage: 10Gi
  accessModes:
    - ReadWriteMany
  persistentVolumeReclaimPolicy: Recycle  # Retain, Recycle, Delete
  hostPath:
#path填上本地目录
    path: "/home/oracle/pv/pv1"
  #nfs:
    #server: <nfs_server_ip>
    #path: <shared_path>
---

kind: PersistentVolume
apiVersion: v1
metadata:
  name: pv2
  labels:
    app: wls-domain
spec:
  storageClassName: manual
  capacity:
    storage: 10Gi
  accessModes:
    - ReadWriteMany
  persistentVolumeReclaimPolicy: Recycle  # Retain, Recycle, Delete
  hostPath:
    path: "/home/oracle/pv/pv2"
  #nfs:
    #server: <nfs_server_ip>
    #path: <shared_path>

---

kind: PersistentVolume
apiVersion: v1
metadata:
  name: pv3
  labels:
    app: wls-domain
spec:
  storageClassName: manual
  capacity:
    storage: 10Gi
  accessModes:
    - ReadWriteOnce
  persistentVolumeReclaimPolicy: Recycle  # Retain, Recycle, Delete
  hostPath:
    path: "/home/oracle/pv/pv3"
  #nfs:
    #server: <nfs_server_ip>
    #path: <shared_path>

NOTE:hostPath下所填的目录需有777权限。

IMPORTANT:在执行创建脚本之前,必须确保有一个用户的UID和GID为1000:1000。

然后,依次执行以下命令:

$ kubectl create -f  k8s/secrets.yml
$ kubectl create -f  k8s/pv.yml
$ kubectl create -f  k8s/pvc.yml
$ kubectl create -f  k8s/wls-admin.yml
$ kubectl create -f  k8s/wls-stateful.yml

至此,一个带有两个managed-server的domain便创建好了。

$ kubectl get all
NAME                               READY     STATUS    RESTARTS   AGE
po/admin-server-1238998015-f932w   1/1       Running   0          11m
po/managed-server-0                1/1       Running   0          11m
po/managed-server-1                1/1       Running   0          8m

NAME                CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
svc/admin-server    10.102.160.123   <nodes>       8001:30007/TCP   11m
svc/kubernetes      10.96.0.1        <none>        443/TCP          39d
svc/wls-service     10.96.37.152     <nodes>       8011:30009/TCP   11m
svc/wls-subdomain   None             <none>        8011/TCP         11m

NAME                          DESIRED   CURRENT   AGE
statefulsets/managed-server   2         2         11m

NAME                  DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
deploy/admin-server   1         1         1            1           11m

NAME                         DESIRED   CURRENT   READY     AGE
rs/admin-server-1238998015   1         1         1         11m

    现在可以登录http:IP:30007/console访问控制台,默认账号为:weblogic,密码为:weblogic1。

    在weblogic中部署的应用访问端口为30009。

  • 改进

我们可以制作chart来一键安装,步骤如下:

1.创建名为hello-world的charts

helm create weblogic

2.将k8s/目录放入weblogic/templates目录下

注:helloworld程序简单,程序不需引入相关依赖,也不需要传入参数。charts提供了版本控制,引入依赖,传参等配置文件。

3.打包tar

helm package weblogic

4.在本地创建charts文件夹,并将打包的tar文件移入,生成index.yaml

mv weblogic-0.1.0.tgz charts/

helm serve --repo-path ./charts

5、安装chart

helm install weblogic

“weblogic的部署方法”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注亿速云网站,小编将为大家输出更多高质量的实用文章!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI