Friday, November 10, 2017

Ubuntu Setup

Ubuntu Setup

  • docker CE
    • sudo apt-get update
    • sudo apt-get install apt-transport-https ca-certificates curl software-properties-common
    • curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
    • test: sudo apt-key fingerprint 0EBFCD88
    • sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
    • sudo apt-get install docker-ce
    • sudo groupadd docker
    • sudo gpasswd -a yjpark docker
    • sudo usermod -aG docker yjpark
    • su - yjpark
    • id -nG
  • ssh
    • apt-get install openssh-server
    • cp /etc/ssh/ssd_config /etc/ssh_sshd_config.factory-defaults
    • chmod a-w /etc/ssh/sshd_config.factory-defaults
    • systemctl restart ssh
  • openstack
    • sudo apt-get install python-pip
    • sudo pip install python-openstackclient
    • /etc/openstack/clouds-public.yaml
      • public-clouds:
          eu-zrh:
            auth:
              auth_url: https://cloud.eu-zrh.hub.kudelski.com:5000/
          us-phx:
            auth:
              auth_url: https://cloud.us-phx.hub.kudelski.com:5000/
    • ~/.config/openstack/clouds.yaml
      • clouds:
          eu-zrh-uex-proci:
            cloud: eu-zrh
            identity_api_version: '3'
            interfacepublic
            auth:
              domain_name: hq.k.grp
              project_name: uex-proci
              username: ludovic.pierre@nagra.com
              password: xxxx
          us-phx-uex-proci:
            cloud: us-phx
            identity_api_version: '3'
            interfacepublic
            auth:
              domain_name: hq.k.grp
              project_name: uex-proci
              username: ludovic.pierre@nagra.com
  • ansible
    • $ sudo apt-get update
      $ sudo apt-get install software-properties-common
      $ sudo apt-add-repository ppa:ansible/ansible
      $ sudo apt-get update
      $ sudo apt-get install ansible
    • sudo pip install shade
  • ss

Thursday, November 9, 2017

Fedora Setup

Fedora 24 Setup
















  • Insert DVD and reboot.

  • Fedora 24 Boot Screen
    • Select "Install to Hard Drive"
    Install Fedora 24 to Hard Drive
    • Select "Installation destination"
    Fedora 24 Installation Summary

    • Select a device, "Automatically configure partitioning", and "I would like to make additional space available".
    Configure Fedora 24 Installation Destination

    • Go back to "Installation Summary" and select "Network and Host Name"
    • Give a host name
    Configure Network Hostname
    • Select "Begin Installation" to continue.
    Begin Fedora 24 Installation
    • As the system files are being installed, setup root password and setup user.
    Setup Fedora 24 Users
    • Once installation is completed, remove the media and reboot
    • dnf update to update installed packages
    • Reboot
    • vi /etc/sysconfig/selinux to "disabled"
      • If cannot login with NIS (specially with Fedora 26), re-enable (enforce) selinux
      • If you want to use samba, do this:
        setsebool -P samba_export_all_rw 1
    • Stop & disable firewalld.service unless you want to use firewall
    • If you need to use NIS in OpenTV:
      • dnf install ypbind rpcbind
      • /etc/nfsmount.conf
        • Defaultvers=3
      • ypdomainname hq.k.grp
      • /etc/sysconfig/authconfig
        • USENIS=yes
      • /etc/yp.conf
        • domain hq.k.grp server 10.4.50.16
        • domain hq.k.grp server 10.4.50.17
      • /etc/nsswitch.conf
        • passwd: add nis
        • shadow: comment out
        • group: add nis
        • netgroup: nis sss
        • automount: files nis sss
      • systemctl enable rpcbind ypbind and reboot

    • autofs
      • dnf install autofs
      • /etc/sysconfig/autofs
        • BROWSE_MODE="yes"
      • /etc/auto.master
        • auto.master.mtvlnx
      • /etc/resolv.conf
        • search hq.k.grp
        • nameserver 10.4.40.7
        • nameserver 10.4.20.46
      • systemctl enable & start autofs.service

    • samba
      • dnf install samba
      • vi /etc/samba/smb.conf

         [global]
         workgroup = HQ
         server string = yjpark_linux

              security = user 



              [homes]

              comment = Home Directories

              valid users = %S, %D%w%S

              browseable = Yes

              writable = yes

              inherit acls = Yes
    • To export other than user home directory, e.g. /home/yjpark:

         [test]
         comment = test directory
         path = /home/test
         public = yes
         writable = yes

              browseable = Yes
      • systemctl smb restart
      • smbpasswd -a user_id
      • If firewalld is enabled:
        • firewall-cmd --permanent --add-service=samba
        • service firewalld restart
    • Apach
      • systemctl enable/start httpd.service
      • default html documents are in /var/www/html
    • Docker CE
      • dnf install dnf-plugins-core
      • dnf config-manager --add-repo https://download.docker.com/linux/fedora/docker-ce.repo
      • dnf install docker-ce
    • Add user to docker
      • groupadd docker
      • gpasswd -a yjpark docker
      • usermod -aG docker yjpark
    • docker-compose upgrade
      • curl -L https://github.com/docker/compose/releases/download/1.17.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
      • replace /usr/bin/docker-compose
    • docker registry
      • docker pull registry:2
      • docker run -d -p 5000:5000 --restart always --name registry registry:2
      • vi /etc/docker/daemon.json
    {
      "insecure-registries":["10.0.0.211:5000"]
    }
      • systemctl restart docker
      • push docker image
        • vi Dockerfile

    FROM ubuntu:12.04

    CMD while true; do echo 'Hit CTRL+C'; sleep 1; done

        • docker build -t docker_test_1 .
        • docker run --rm -it docker_test_1
        • docker tag docker_test_1 10.0.0.211:5000/docker_test_1
        • docker push 10.0.0.211:5000/docker_test_1
      • pull docker image
        • CE:
          • vi /etc/docker/daemon.json
    {
      "insecure-registries":["10.0.0.211:5000"]
    }
          • Older:
      INSECURE_REGISTRY='--insecure-registry 10.0.0.211:5000'
          • systemctl restart docker
          • docker pull 10.0.0.211:5000/docker_test_1
          • docker tag 10.0.0.211:5000/docker_test_1 docker_test_1
          • lookup
            • curl 'http://10.0.0.211:5000/v2/_catalog'
          • stop registry
            • docker stop registry
          • cleanup registry
            • docker rm -v registry
      • docker swarm
        • docker swarm init --listen-addr 0.0.0.0:2377 --advertise-addr 10.0.0.211
        • docker swarm join-token manager
        • docker swarm join-token worker
        • docker swarm join --manager --listen-addr 0.0.0.0:2377 10.0.0.211:2377
        • In different machine, docker swarm join --token SWMTKN-1-28hbo372s2s7vqksqu95xjka1tlq2u44cyzxeu7nkp510nfhbs-0qcw90bwph9vph3pmg45wqbfi 10.0.0.211:2377
        • docker node ls
        • docker node update --label-add nodelabel=ubuntu dqviprkfsjriozb7a37n5ccvt
        • docker node inspect dqviprkfsjriozb7a37n5ccvt
        • docker service create --replicas 2 --detach=false --name docker_test 10.0.0.211:5000/docker_test_1
        • docker service ls

      ID                  NAME                MODE                REPLICAS            IMAGE                                  PORTS

      o29rus4yn3m5        docker_test         replicated          2/2                 10.0.0.211:5000/docker_test_1:latest   

        • docker service ps o29rus4yn3m5        
      ID                  NAME                IMAGE                                  NODE                DESIRED STATE       CURRENT STATE           ERROR               PORTS
      a5ea1hinp1s6        docker_test.1       10.0.0.211:5000/docker_test_1:latest   yjpark-linux-01     Running             Running 2 minutes ago                       
      ce41xdqa9ef5        docker_test.2       10.0.0.211:5000/docker_test_1:latest   Ubuntu-VirtualBox   Running             Running 2 minutes ago                       
        • docker service logs a5ea1hinp1s6
        • docker service scale docker_test=1
        • docker service rm o29rus4yn3m5
      • virtualbox
        • download https://www.virtualbox.org/wiki/Download_Old_Builds_5_1
        • dnf install kernel-devel
        • /sbin/vboxconfig
        • Download ubuntu iso file
        • Create new vm
      • Perforce
        • download p4d from https://www.perforce.com/downloads/helix-versioning-engine-p4d
        • vi /etc/systemd/system/p4d.service
      # Example Perforce systemd file (p4d.service):
      #
      # This service file will start Perforce at boot, and
      # provide everything needed to use systemctl to control
      # the Perforce server process.
      
      [Unit]
      # Note that descriptions are limited to 80 characters:
      Description=Perforce Server
      
      # Starts Perforce only after the network services are 
      # ready:
      #After=network.target
      After=network-online.target
      
      [Service]
      # The type should always be set to "forking" to support
      # multiple Perforce processes:
      Type=forking
      
      # Set the system user used to launch this process (usually
      # 'perforce':
      User=perforce
      
      # The command used to start Perforce:
      ExecStart=/usr/bin/p4d -r /home/yjpark/p4d/p4d -p 10.0.0.211:1666 -d
      
      [Install]
      # Describes the target for this service -- this will always
      # be 'multi-user.target':
      WantedBy=multi-user.target
        • systemctrl start p4d
        • systemctl enable p4d
          • a symbolic link to p4d.service file will be created in /etc/systemd/system/multi-user.target.wants
        • download p4v from https://www.perforce.com/downloads/helix-visual-client-p4v
        • create a symbolic link to p4v in /usr/local/bin.
      • git
        • git user:
          • ssh-keygen -t rsa -b 2048
          • sudo adduser git
          • cd /home/git
          • su git
          • mkdir git-shell-commands
          • sudo vi /etc/passwd, change bash to git-shell
          • sudo -u git -s
          • mkdir .ssh
          • chmod 700 .ssh
          • cat ./id_rsa.pub >> ./authorized_keys
          • chmod 600 ./authorized_keys
          • rm -rf ./id_rsa.pub
          • cd /home/git
          • mkdir repos
          • cd repos
          • mkdir test_project.git
          • cd test_project.git
          • git init --bare --shared
        • user:
          • git config --global user.name "yjpark"
          • git config --global user.email "yongjin.park.kr@gmail.com"
          • cd git/workspace
          • git clone ssh://git@10.0.0.211:/home/git/repos/test_project.git
          • cd test_projec
          • vi test.py
          • git add .
          • git status
          • git commit -a -m "initial commit"
          • git push origin master
          • git status
      • Jenkins
        • In the staging server:
          • Setup staging Jenkins server and install plugins
          • curl -sSL "http://user:pass@10.0.0.211:8080/pluginManager/api/xml?depth=1&xpath=/*/*/shortName|/*/*/version&wrapper=plugins" | perl -pe 's/.*?<shortName>([\w-]+).*?<version>([^<]+)()(<\/\w+>)+/\1 \2\n/g'|sed 's/ /:/' > plugins.txt
        • In the target server (VM), using a Jenkins job:
          • sync workspace in Perforce, e.g. /home/perforce/workspace/jenkins/, which has a Dockerfile and plugins.txt (see above) in it
          • Dockerfile example:
      FROM jenkins/jenkins
      COPY plugins.txt /usr/share/jenkins/ref/plugins.txt
      RUN /usr/local/bin/install-plugins.sh < /usr/share/jenkins/ref/plugins.txt
          • mkdir /home/jk
          • docker build -t 10.0.0.211:5000/jenkins .
          • docker push 10.0.0.211:5000/jenkins
          • docker run -p 8090:8080 -p 50000:50000 -v /home/jk:/var/jenkins_home 10.0.0.211:5000/jenkins