Greenplum6使用ansible简化安装

Greenplum开发环境部署

环境规划,注意master上的host文件要把所有节点都加上,包括master

mdw
sdw1
sdw2

1 环境部署&源码安装(playbook)

从第三方机器上发起配置,例如你的MAC,直接运行即可

gp_src_install.yml(代码在文章末尾)

ansible-playbook gp_src_install.yml -e package_path=pathto/6.0.0.tar.gz

有几点需要注意的:

  1. orca的依赖包要单独的加到LD_LIBRARY_PATH里面,GP的source脚本不会加,不加pg的主程序起不来,初始化失败

  2. 安装之后执行一次ldconfig,数据目录都要提前建好,注意权限

  3. configure的用法LD_LIBRARY_PATH=/u01/dep/orca/lib ./configure --prefix=/u01/gpdb_600 --with-perl --with-python --with-libxml --with-gssapi --with-includes=/u01/dep/orca/include --with-libraries=/u01/dep/orca/lib

2 数据库初始化

主库上配置SSH

ssh-keygen -t rsa -b 4096 -C "[email protected]"

ssh-copy-id mdw
ssh-copy-id sdw1
ssh-copy-id sdw2

*环境变量配置*

创建安装配置文件

这里记录下DATA_DIRECTORY后面的三个路径含义是三台segment上的安装路径,GP会自动在这个路径下建文件夹类似seg0seg1,本例中会在sdw1上创建seg0和seg1,在sdw2上创建seg2和seg3

cat >> hostfile_gpinitsystem << EOF
sdw1
sdw2
EOF

cat >> gpinitsystem_config << EOF
ARRAY_NAME="Greenplum Data Platform"
SEG_PREFIX=gpseg
PORT_BASE=6000
declare -a DATA_DIRECTORY=(/u01/data/primary /u01/data/primary)
MASTER_HOSTNAME=`hostname`
MASTER_DIRECTORY=/u01/data/master
MASTER_PORT=5432
TRUSTED_SHELL=ssh
CHECK_POINT_SEGMENTS=8
ENCODING=UNICODE

#MIRROR_PORT_BASE=3420
#declare -a MIRROR_DATA_DIRECTORY=(/u01/data/mirror /u01/data/mirror)
EOF

初始化数据库

gpinitsystem -c gpinitsystem_config -h hostfile_gpinitsystem

安装结束!

验证

psql postgres -c "select * from gp_segment_configuration";
 dbid | content | role | preferred_role | mode | status | port |        hostname         |         address         |         datadir
------+---------+------+----------------+------+--------+------+-------------------------+-------------------------+--------------------------
    1 |      -1 | p    | p              | n    | u      | 5432 | iZbp1d1tuijx3xqf2kh89kZ | iZbp1d1tuijx3xqf2kh89kZ | /u01/data/master/gpseg-1
    2 |       0 | p    | p              | n    | u      | 6000 | iZbp16pjl9her1ittjz11fZ | sdw1                    | /u01/data/primary/gpseg0
    4 |       2 | p    | p              | n    | u      | 6000 | iZbp1d4tisi44j6vxze02fZ | sdw2                    | /u01/data/primary/gpseg2
    3 |       1 | p    | p              | n    | u      | 6001 | iZbp16pjl9her1ittjz11fZ | sdw1                    | /u01/data/primary/gpseg1
    5 |       3 | p    | p              | n    | u      | 6001 | iZbp1d4tisi44j6vxze02fZ | sdw2                    | /u01/data/primary/gpseg3
---
- hosts: gp
  vars:
    version: "6.0.0"
    admin_user: "gp12345678"
    admin_password: "333"
    base_version: 600
    base_dir: "/u01"
    data_dir: "/u01/data"
  remote_user: root
  tasks:
  ##
  #! auth
  ##
  - name: add ssh authorized keys for root
    authorized_key:
      user: root
      state: present
      key: "{{ lookup('file', lookup('env','HOME') + '/.ssh/id_rsa.pub') }}"
  - name: check base directory exists
    stat:
      path: "{{ base_dir }}"
    register: st
  - name: check base_dir
    fail: 
      msg: "{{ base_dir }} not found"
    when: st.stat.exists == false
  ##
  #! user
  ##
  - name: create admin user
    user:
      name: "{{ admin_user }}"
      password: "{{ admin_password | password_hash('sha512', 'iamsalt') }}"

  - name: add ssh authorized keys for admin
    authorized_key:
      user: "{{ admin_user }}"
      state: present
      key: "{{ lookup('file', lookup('env','HOME') + '/.ssh/id_rsa.pub') }}"
  ##    
  #! sysctl
  ##
  - name: backing up sysctl
    copy:
      src: /etc/sysctl.conf
      remote_src: yes
      dest: /tmp/sysctl.conf.bak
      backup: yes
  - name: get shmall 
    shell: echo $(expr $(getconf _PHYS_PAGES) / 2) 
    register: shmall
  - name: get shmmax
    shell: echo $(expr $(getconf _PHYS_PAGES) / 2 \* $(getconf PAGE_SIZE))
    register: shmmax
  - name: get min_free_kbytes
    shell: awk 'BEGIN {OFMT = "%.0f";} /MemTotal/ {print $2 * .03;}' /proc/meminfo
    register: min_free_kbytes
  - name: set shmall
    sysctl:
      name: kernel.shmall
      value: "{{ shmall.stdout }}"
      reload: yes
  - name: set shmmax
    sysctl:
      name: kernel.shmmax
      value: "{{ shmmax.stdout }}"
      reload: yes
  - name: set min_free_kbytes
    sysctl:
      name: vm.min_free_kbytes
      value: "{{ min_free_kbytes.stdout }}"
      reload: yes
  - name: set other sysctl
    sysctl:
       name: "{{ item.key }}"
       value: "{{ item.value }}"
       sysctl_set: yes
       state: present
       reload: yes
       ignoreerrors: yes
    with_dict:
      kernel.shmmni: 4096
      vm.overcommit_memory: 2
      vm.overcommit_ratio: 95
      net.ipv4.ip_local_port_range: 10000 65535
      kernel.sem: 500 2048000 200 40960
      kernel.sysrq: 1
      kernel.core_uses_pid: 1
      kernel.msgmnb: 65536
      kernel.msgmax: 65536
      kernel.msgmni: 2048
      net.ipv4.tcp_syncookies: 1
      net.ipv4.conf.default.accept_source_route: 0
      net.ipv4.tcp_max_syn_backlog: 4096
      net.ipv4.conf.all.arp_filter: 1
      net.core.netdev_max_backlog: 10000
      net.core.rmem_max: 2097152
      net.core.wmem_max: 2097152
      vm.swappiness: 0
      vm.zone_reclaim_mode: 0
      vm.dirty_expire_centisecs: 10
      vm.dirty_writeback_centisecs: 3
      vm.dirty_background_ratio: 10
      vm.dirty_ratio: 20
      vm.dirty_background_bytes: 0
      vm.dirty_bytes: 0 
  ##    
  #! pam limit
  ##
  - name: state PAM limits
    pam_limits:
      domain: '*'
      limit_type: '-'
      limit_item: "{{ item.key }}"
      value: "{{ item.value }}"
    with_dict:
      nofile: 655360
      nproc: 655360
      memlock: unlimited
      core: unlimited

  ##    
  #! install src gp
  #! https://github.com/greenplum-db/gpdb/blob/master/README.linux.md
  ##
  
  - name: copy package to host
    copy:
      src: "{{ package_path }}"
      dest: /tmp
  - name: install cmake3 repo
    shell: |
      echo '[group_kdesig-cmake3_EPEL]
      name=Copr repo for cmake3_EPEL owned by @kdesig
      baseurl=https://copr-be.cloud.fedoraproject.org/results/@kdesig/cmake3_EPEL/epel-7-$basearch/
      type=rpm-md
      skip_if_unavailable=True
      gpgcheck=1
      gpgkey=https://copr-be.cloud.fedoraproject.org/results/@kdesig/cmake3_EPEL/pubkey.gpg
      repo_gpgcheck=0
      enabled=1
      enabled_metadata=1' > /etc/yum.repos.d/cmake3.repo
  - name: install cmake3
    yum:
      name: "cmake3"
      state: present  
  - name: set env1
    shell: |
      ln -sf /usr/bin/cmake3 /usr/local/bin/cmake
      if ! grep -Fq "/usr/local/lib" /etc/ld.so.conf /etc/ld.so.conf;then echo /usr/local/lib >> /etc/ld.so.conf;fi
      if ! grep -Fq "/usr/local/lib64" /etc/ld.so.conf /etc/ld.so.conf;then echo /usr/local/lib64 >> /etc/ld.so.conf;fi
      ldconfig
      mkdir {{ base_dir }}/gpdb_{{base_version}}_src {{ base_dir }}/gpdb_{{base_version}} {{ base_dir }}/dep;
      tar -xzvf /tmp/{{package_path | basename}} -C {{ base_dir }}/gpdb_{{base_version}}_src
    args:
      warn: no
  - name: set env2
    shell: |
      pip install requests urllib3 pyOpenSSL --force --upgrade || true
      pip install conan || true
      sh {{ base_dir }}/gpdb_{{base_version}}_src/gpdb-6.0.0/README.CentOS.bash >/dev/null 2>&1 || true
    args:
      warn: no
  - name: build optimizer
    shell: |
      ./configure --prefix={{ base_dir }}/dep/orca
      make -sj32
      make install_local
    args:
      chdir: "{{ base_dir }}/gpdb_{{base_version}}_src/gpdb-6.0.0/depends"
      warn: no
  # LD_LIBRARY_PATH=/u01/dep/orca/lib ./configure --prefix=/u01/gpdb_600 --with-perl --with-python --with-libxml --with-gssapi --with-includes=/u01/dep/orca/include --with-libraries=/u01/dep/orca/lib
  - name: build database
    shell: |
      LD_LIBRARY_PATH={{ base_dir }}/dep/orca/lib ./configure --prefix={{ base_dir }}/gpdb_{{base_version}} --with-perl --with-python --with-libxml --with-gssapi --with-includes={{ base_dir }}/dep/orca/include --with-libraries={{ base_dir }}/dep/orca/lib >/dev/null 2>&1 || true
      make -sj32 >/dev/null 2>&1 || true
      make install >/dev/null 2>&1 || true
      ldconfig
      if ! grep -Fq "LD_LIBRARY_PATH" /home/{{ admin_user }}/.bashrc;then echo "export LD_LIBRARY_PATH={{ base_dir }}/dep/orca/lib:$LD_LIBRARY_PATH" >> /home/{{ admin_user }}/.bashrc;fi
      if ! grep -Fq "greenplum_path.sh" /home/{{ admin_user }}/.bashrc;then echo "source {{ base_dir }}/gpdb_{{base_version}}/greenplum_path.sh" >> /home/{{ admin_user }}/.bashrc;fi
      mkdir -p {{ data_dir }}/primary {{ data_dir }}/master
      chown {{ admin_user }}:{{ admin_user }} {{ data_dir }} -R
    args:
      chdir: "{{ base_dir }}/gpdb_{{base_version}}_src/gpdb-6.0.0"
      warn: no


你可能感兴趣的:(pgsql)