MoinMoin Logo
  • Comments
  • Immutable Page
  • Menu
    • Navigation
    • RecentChanges
    • FindPage
    • Local Site Map
    • Help
    • HelpContents
    • HelpOnMoinWikiSyntax
    • Display
    • Attachments
    • Info
    • Raw Text
    • Print View
    • Edit
    • Load
    • Save
  • Login

Navigation

  • Start
  • Sitemap
Revision 33 as of 2022-06-12 22:01:27
  • FreeBSD

FreeBSD

FreeBSD is an advanced computer operating system used to power modern servers, desktops, and embedded platforms. http://www.freebsd.org

  • wget http://ftp.freebsd.org/pub/FreeBSD/releases/amd64/amd64/ISO-IMAGES/10.3/FreeBSD-10.3-RELEASE-amd64-dvd1.iso

VirtualBox installation

  • Start VirtualBox

  • New
  • Name FreeBSD_10_3
  • Choose type BSD
  • version FreeBSD 64 bit
  • RAM 512 MB
  • Create virtual disk dynamic VDI with Fixed size 8 GB
  • Create
  • Start VM
  • Choose ISO FreeBSD-10.3-RELEASE-amd64-dvd1.iso
  • Start
  • option 1 multi boot
  • Install
  • keymap portuguese iso-8859-1 accent keys
  • continue with pt.iso.acc.kbd keymap
  • hostname: freebsd
  • Distribution select: all
  • Partitioning: auto
  • Partition: entire disk
  • Partition scheme: GPT guid partition table
  • Partition editor, finish, commit
  • root password: ********
  • Network config: em0
  • configure ipv4: yes
  • use dhcp: yes
  • configure ipv6: no
  • search: <empty>

  • ipv4 dns1: 8.8.8.8
  • ipv4 dns2: 8.8.4.4
  • is cmos clock set to utc: yes
  • region: europe
  • country: portugal mainland
  • services: sshd dumpdev
  • add users? yes
  • username: vitor
  • several enters
  • add other account: no
  • exit, apply config and exit installer
  • manual configuration? no
  • reboot
  • release ISO
  • login as root

   1 df -h 
   2 traceroute www.sapo.pt
   3 pkg install wget 
   4 # install package management tool ? yes 
   5 proceed with action: yes 
   6 pkg info 
   7 cc --version 
   8 # https://www.freebsd.org/doc/handbook/pkgng-intro.html
   9 pkg search jdk 
  10 pkg install openjdk8-8.92.14_3  #203 MB
  11 # add lines to fstab ...
  12 java -version 
  13 pkg search python 
  14 pkg install python27-2.7.12 # 67MB 
  15 python2.7 --version 
  16 pkg install mongodb-2.6.12 #203MB
  17 pkg install rabbitmq-3.6.2 # 157MB
  18 df -h # avail 3.2 GB
  19 pkg install bash 
  20 pkg install xorg
  21 startx
  22 pkg install windowmaker-0.95.7_2 # 262MB 
  23 echo "exec /usr/local/bin/wmaker" > ~/.xinitrc
  24 startx 

Get and burn ISO

   1 wget  http://ftp.freebsd.org/pub/FreeBSD/releases/amd64/amd64/ISO-IMAGES/10.3/FreeBSD-10.3-RELEASE-amd64-dvd1.iso
   2 modprobe sg # for cdrecord
   3 cdrecord -scanbus #identify the device DVDRAM LG GP08NU6B
   4 cdrecord -dev=6,0,0 -pad -data FreeBSD-10.3-RELEASE-amd64-dvd1.iso
   5 # eject the DVD after burning
   6 eject
   7 cd /
   8 mount /dev/sr0 /mnt/cdrom #check DVD
   9 cd /mnt/cdrom/packages/FreeBSD:10:amd64/All
  10 ls
  11 ls -lah | wc -l # 1070 packages python gnome3 kde, qt, mysql, firefox, subversion, xorg, perl, gsl 
  12 cd /
  13 umount /mnt/cdrom 

Amazon AMI

  • https://aws.amazon.com/marketplace/pp/B00KSS55FY/

Info severity logging

  • add to /etc/rc.conf

   1 syslogd_enable="YES"
  • touch /var/log/syslog
  • Add to /etc/syslog.conf

*.info /var/log/syslog

Example program

   1 #!/usr/bin/python
   2 import threading
   3 import time
   4 import os
   5 import syslog
   6 import datetime
   7 import sys 
   8 import signal
   9 
  10 def termHandler(signal,frame):
  11     print('Signal term caught')
  12     sys.exit(0)
  13     
  14 if __name__=="__main__":
  15     f=open('/var/run/beat.pid','wa')
  16     f.write('%d'%(os.getpid()))
  17     f.close()
  18     signal.signal(signal.SIGTERM,termHandler)    
  19     
  20     while True:
  21         syslog.syslog(syslog.LOG_INFO, "Beat %s"%(datetime.datetime.now()) )
  22         time.sleep(5)

Custom service

/home/vitor/beat.py

   1 #!/usr/bin/python
   2 import threading
   3 import time
   4 import os
   5 import syslog
   6 import datetime
   7 import sys 
   8 import signal
   9 
  10 def termHandler(signal,frame):
  11     print('Signal term caught')
  12     sys.exit(0)
  13     
  14 if __name__=="__main__":
  15     f=open('/var/run/beat.pid','wa')
  16     f.write('%d'%(os.getpid()))
  17     f.close()
  18     signal.signal(signal.SIGTERM,termHandler)    
  19     
  20     while True:
  21         syslog.syslog(syslog.LOG_INFO, "Beat %s"%(datetime.datetime.now()) )
  22         time.sleep(5)

In /etc/rc.conf

beat_enable="YES"

/etc/rc.d/beat

   1 #!/bin/sh
   2 
   3 # PROVIDE: beat
   4 
   5 . /etc/rc.subr
   6 
   7 name=beat
   8 rcvar=beat_enable
   9 command="/usr/local/bin/python2"
  10 command_args="/home/vitor/${name}.py &"
  11 
  12 load_rc_config $name
  13 
  14 run_rc_command "$1"

Give user permission to use su -

   1 pw user mod userxyz -G wheel
   2 su -

Bash

   1 pkg install bash
   2 chsh -s /usr/local/bin/bash vitor
   3 chsh -s /usr/local/bin/bash root

~/.profile

   1 #normal user
   2 PS1="\e[0;33m\]\D{%Y-%m-%d}T\A\[\e[m\] \e[0;32m\]\u@\H:\w\r\n\$\[\e[m\] "

MongoDB

  • mkdir -p /data/db

/etc/rc.conf

mongodb_enable="YES"

/etc/rc.d/mongodb

   1 #!/bin/sh
   2 
   3 # PROVIDE: mongodb
   4 
   5 . /etc/rc.subr
   6 
   7 name=mongodb
   8 rcvar=mongodb_enable
   9 pidfile="/var/run/mongodb.pid"
  10 command="/usr/local/bin/mongod"
  11 command_args="--pidfilepath=$pidfile --smallfiles --syslog &"
  12 
  13 load_rc_config $name
  14 
  15 run_rc_command "$1"
  • check file /usr/local/etc/rc.d/mongod
  • mongod_enable="YES" in /etc/rc.conf
  • mkdir -p /var/db/mongodb
  • add --smallfiles to mongod_flags in file /usr/local/etc/rc.d/mongod

RabbitMQ service

/etc/rc.conf

rabbitmqserver_enable=YES

/etc/rc.d/rabbitmq

   1 #!/bin/sh
   2 # PROVIDE: rabbitmq-server
   3 
   4 . /etc/rc.subr
   5 
   6 name=rabbitmqserver
   7 load_rc_config $name
   8 
   9 #rcvar=rabbitmqserver_enable
  10 command="/usr/local/sbin/rabbitmq-server"
  11 pidfile="/var/db/rabbitmq/mnesia/rabbit@freebsd.pid"
  12 
  13 if [ $rabbitmqserver_enable = "YES" ];then
  14   case "$1" in
  15     start)
  16       echo "Starting ${name} "
  17       $command &
  18       ;;
  19     status)
  20       if [ -f $pidfile ];then
  21         PID=$(cat $pidfile)
  22         echo "${name} running with PID $PID"
  23       else
  24         echo "${name} not running"
  25       fi
  26       ;;
  27     stop)
  28       if [ -f $pidfile ];then
  29         PID=$(cat $pidfile)
  30         echo "Killing ${name} with PID $PID"
  31         /usr/local/sbin/rabbitmqctl stop
  32         rm $pidfile
  33       else
  34         echo "${name} not running"
  35       fi
  36       ;;
  37     *)
  38       echo "Usage: /etc/rc.d/rabbitmq {start|status|stop}"
  39       exit 1
  40     ;;
  41   esac
  42 else
  43   echo "${name} service is not enabled in /etc/rc.conf"
  44 fi
  45 
  46 exit 0
  • check file /usr/local/etc/rc.d/rabbitmq
  • rabbitmq_enable="YES" in /etc/rc.conf

   1 /usr/local/sbin/rabbitmq-plugins list
   2 /usr/local/sbin/rabbitmq-plugins enable rabbitmq_management #port 15672
   3 rabbitmqctl add_user rmq rmq
   4 rabbitmqctl  set_user_tags rmq administrator
   5 rabbitmqctl set_permissions -p / rmq ".*" ".*" ".*"
   6 python -m ensurepip
   7 pip install pika

Vagrant box

  • https://app.vagrantup.com/freebsd/boxes/FreeBSD-13.1-STABLE

   1 cd /tmp
   2 mkdir freebsd-test
   3 cd freebsd-test
   4 vagrant init freebsd/FreeBSD-13.1-STABLE
   5 vagrant up
   6 vagrant ssh
   7 sudo pkg install openjdk17-17.0.3+7.1
   8 sudo pkg install nano
   9 cat Main.java 
  10 #public class Main{
  11 #  public static void main(String[] args){
  12 #    System.out.println("Main hello world !");
  13 #  }
  14 #}
  15 javac Main.java
  16 java Main
  17 vagrant suspend
  • MoinMoin Powered
  • Python Powered
  • GPL licensed
  • Valid HTML 4.01