Welcome to my website. I am always posting links to photo albums, art, technology and other creations. Everything that you will see on my numerous personal sites is powered by the formVistaTM Website Management Engine.

icon.linkedin.jpgicon.twitter.jpg

  • Mocking an HTTPS RESTful endpoint with Netcat
    06/12/2019 2:20PM

    Netcat is generally known as a TCP/IP Swiss Army Knife and is incredibly helpful for both debugging and mocking up network services

    Following is an example on how to setup a mock RESTful service that communicates over HTTPS.

    On the "server" side, run the following command.  The -l command instructs Netcat to listen.

    while true; do { echo -e "HTTP/1.1 200 OK\r\n$(date)\r\n\r\n<h1>hello world from $(hostname) on $(date)</h1>" |  nc -vl --ssl 8080; } done

    On the "client" side, run the following to PUT a sample json document.

    curl https://localhost:8080/foo/blah -k -XPUT -d @sample.json

    Alternatively, you can also generate a key cert pair to use if you have to test importing of certs

    To do so, first generate a self-signed cert and an ssl key without a passphrase for your nc "server".  Place the server.key and server.cert file in /var/tmp/server-cert

    openssl req -nodes -new -x509 -keyout server.key -out server.cert

    Then run nc as follows:

    while true; do { echo -e "HTTP/1.1 200 OK\r\n$(date)\r\n\r\n<h1>hello world from $(hostname) on $(date)</h1>" |  nc -vl --ssl 8080 --ssl-key /var/tmp/server-cert/server.key --ssl-cert /var/tmp/server-cert/server.cert; } done

  • Test Network Speed of Ethernet Ports
    03/30/2019 8:33AM

    If you have just bought a new (to you) nic card or other networking device and want to test that all of the ports can pass traffic at the expected rate, as long as you have nc and the firewall ports open on a "server" with a known good nic and have nc installed on your "client" device that you want to test it is very easy to test.

    Of course, if you are testing a switch itself, then it is just a matter of having two known good machines to act as the client and the server and to insert the switch between them.

    Ensure that you have a high port that is allowed by your firewall.  On the server side run the following to set up a listening service

    nc -l -k <port> > /dev/null

    Then on the client run the following:

    $ dd if=/dev/zero bs=1M count=1K | nc -vn <server-ip-addr> <port>
    Connection to <server-ip-addr> <port> port [tcp/*] succeeded!
    1024+0 records in
    1024+0 records out
    1073741824 bytes (1.1 GB) copied, 9.0998f s, 118 MB/s

    Then, just remember to multiply the MB copied to the server by 8 to get the rate in megabits/s.

  • Adding a New Disk to a Linux Server and Creating an LVM Partition
    10/20/2017 1:43PM
    There are a number of tutorials online for adding a new disk to a machine and then extending an existing LVM partition to use the new device.

    This particular tutorial covers the use case of adding a new disk to a Linux server and then creating a NEW LVM partition on it without modifying the existing devices and LVM partitions.

    The first thing you will need to do is add the physical device to the server (or VM).

    Then, you need to confirm that the OS can 'see' the device.  The following command will show you the list of avaiable disk devices.

    # fdisk -l

    Disk /dev/sdb: 80.5 GB, 80530636800 bytes, 157286400 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes


    Here, we see that the OS can 'see' the /dev/sdb device.  For the rest of this tutorial, we will assume that your new device is /dev/sdb.

    Using fdisk, create a primary partition on the new device

    # fdisk /dev/sdb
    Welcome to fdisk (util-linux 2.23.2).

    Changes will remain in memory only, until you decide to write them.
    Be careful before using the write command.

    Device does not contain a recognized partition table
    Building a new DOS disklabel with disk identifier 0xc78ce5fd.

    Command (m for help): n
    Partition type:
       p   primary (0 primary, 0 extended, 4 free)
       e   extended
    Select (default p): p
    Partition number (1-4, default 1):
    First sector (2048-157286399, default 2048):
    Using default value 2048
    Last sector, +sectors or +size{K,M,G} (2048-157286399, default 157286399):
    Using default value 157286399
    Partition 1 of type Linux and of size 75 GiB is set

    Command (m for help): w
    The partition table has been altered!

    Calling ioctl() to re-read partition table.
    Syncing disks.


    After partitioning re-run fdisk to list the partitions

    # fdisk -l

    Disk /dev/sdb: 80.5 GB, 80530636800 bytes, 157286400 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk label type: dos
    Disk identifier: 0xc78ce5fd

       Device Boot      Start         End      Blocks   Id  System
    /dev/sdb1            2048   157286399    78642176   83  Linux


    Now, create an LVM Physical Volume (PV)

    # pvcreate /dev/sdb1
      Physical volume "/dev/sdb1" successfully created.


    Create the LVM Volume Group (VG)

    # vgcreate centos_repos /dev/sdb1
      Volume group "centos_repos" successfully created


    Execute the vgdisplay command to list all of the Volume Groups

    # vgdisplay

      --- Volume group ---
      VG Name               centos_repos
      System ID             
      Format                lvm2
      Metadata Areas        1
      Metadata Sequence No  1
      VG Access             read/write
      VG Status             resizable
      MAX LV                0
      Cur LV                0
      Open LV               0
      Max PV                0
      Cur PV                1
      Act PV                1
      VG Size               75.00 GiB
      PE Size               4.00 MiB
      Total PE              19199
      Alloc PE / Size       0 / 0   
      Free  PE / Size       19199 / 75.00 GiB
      VG UUID               FDgd3y-keqV-riq6-vb46-C2F5-JJa2-Ew2DW4


    Create a LVM Logical Volume (LV).  In this case I am going to use the entire drive

    # lvcreate -n repos --size 74.9G centos_repos
      Rounding up size to full physical extent 74.90 GiB
      Logical volume "repos" created.


    lvdisplay will list all of the existing Logical Volumes

    # lvdisplay
    ...
      --- Logical volume ---
      LV Path                /dev/centos_repos/repos
      LV Name                repos
      VG Name                centos_repos
      LV UUID                pvNLX4-3wTf-2eMY-RebF-WnFU-8y9F-BRidMn
      LV Write Access        read/write
      LV Creation host, time nebula, 2017-10-20 17:36:38 +0000
      LV Status              available
      # open                 0
      LV Size                74.90 GiB
      Current LE             19175
      Segments               1
      Allocation             inherit
      Read ahead sectors     auto
      - currently set to     8192
      Block device           253:4


    Now we need to format the LV.  In this case we will use ext4, you may choose another filesystem format.  Be sure to use the LV Path returned by lvdisplay.

    # mkfs.ext4 /dev/centos_repos/repos
    mke2fs 1.42.9 (28-Dec-2013)
    Filesystem label=
    OS type: Linux
    Block size=4096 (log=2)
    Fragment size=4096 (log=2)
    Stride=0 blocks, Stripe width=0 blocks
    4915200 inodes, 19635200 blocks
    981760 blocks (5.00%) reserved for the super user
    First data block=0
    Maximum filesystem blocks=2168455168
    600 block groups
    32768 blocks per group, 32768 fragments per group
    8192 inodes per group
    Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
        4096000, 7962624, 11239424

    Allocating group tables: done                            
    Writing inode tables: done                            
    Creating journal (32768 blocks): done
    Writing superblocks and filesystem accounting information: done   


    Now you can mount the file system as usual and/or add it to /etc/fstab.

  • Mounting a Samba Share From Linux Client to Linux Samba Server
    06/02/2017 10:49PM

    In order to be able to access a Samba share on a remote client as a mounted file system execute the following command, as root on the client:

    mount -t cifs -o user=<user-on-samba-share>,uid=<uid-on-local-macheine>,gid=<gid-on-local-machine>,rw,workgroup=<your-workgroup> //ip/share /mnt/mount-point-dir

    You will be prompted for the password for the user defined on the Samba server.

    If you are able to authenticate, and then get the following error:

    ls: reading directory .: Permission denied

    Check the SELinux context type of the directory on the samba share.  It should be samba_share_t

  • Solution for Executing Native Process from Java that Requires sudo
    12/22/2016 9:52AM

    If you are building a Java program that requires the ability to execute native commands on the machine which require sudo it requires some additional considerations other than just writing the Java code.

    The problem is that sudo, by default, requires a tty for executing sudo such that a password can entered.  Even if you configure sudoers to grant NOPASSWD access to a specific command you will still get the following error

    sudo: sorry, you must have a tty to run sudo

    In my case, I was writing a set of integration tests in Java that needed to be able to start and stop a service to run a test.

    I settled on adding an additional sudoers config file in /etc/sudoers.d.  This ended up be the cleanest and most encapsulated change that did not then require any special considerations in the Java code.

    The change simply involved adding a file with the following contents to /etc/sudoers.d which indicates that running sudo for the rchapin user does NOT require a tty and then grants access to the specific commands.

    Defaults:rchapin !requiretty
    rchapin ALL=(root) NOPASSWD: /bin/systemctl stop rabbitmq-server.service
    rchapin ALL=(root) NOPASSWD: /bin/systemctl start rabbitmq-server.service

  • 1 2 3 4 5 6 7 8 9 10 11 12 13 14 >>
Advanced Search

Categories

Archives