Page not found – ShopingServer Wiki https://wiki.shopingserver.com Tutorials and Articles About Technology and Gadgets Wed, 02 Sep 2020 02:26:54 +0000 en-US hourly 1 https://wordpress.org/?v=5.5.14 https://wiki.shopingserver.com/wp-content/uploads/2018/07/cropped-favicon-150x150.png Page not found – ShopingServer Wiki https://wiki.shopingserver.com 32 32 FreeBSD Show Disk Quota Limits Command https://wiki.shopingserver.com/freebsd-show-disk-quota-limits-command/ https://wiki.shopingserver.com/freebsd-show-disk-quota-limits-command/#respond Sat, 06 Jan 2018 08:26:22 +0000 http://wiki.shopingserver.com/?p=18459 I

‘m a new FreeBSD unix user and backup file on a FreeBSD based unix server. How can I check quota limits and disk usage using shell prompt on a FreeBSD based system?

 

You need to use the quota command line utility to see your disk usage and limits. By default only the user quotas are printed. Disk block usage and limits are shown in 1024-byte blocks.

Checking Disk Quota on FreeBSD Server

The syntax is as follows:

quota

quota -v

quota [options] username

quota [options] groupname

The following is sample output from my server:

$ quota -v

 

OR

$ quota -v -h

 

Sample outputs:

Disk quotas for user vivek (uid 40142):

Filesystem   usage    quota   limit   grace  files   quota  limit   grace

/mnt/sales      0B       0B      0B               0         0       0

/mnt/homes   7289M   97656M 107422M             579   10000000 11000000

Where,

-v : Display quotas on file systems where no storage is allocated.

-h : “Human-readable” output. Use unit suffixes: Byte, Kilobyte,Megabyte, Gigabyte, Terabyte and Petabyte.

You can use the following command over ssh based session:

ssh vivek@nas01 quota -hv

ssh vivek@server1.cyberciti.biz quota -hv

I strongly suggest that you read quota man page for more information.

 

 

]]>
https://wiki.shopingserver.com/freebsd-show-disk-quota-limits-command/feed/ 0
FreeBSD 10: Apply Binary Updates To Keep Base System Up To Date https://wiki.shopingserver.com/freebsd-10-apply-binary-updates-keep-base-system-date/ https://wiki.shopingserver.com/freebsd-10-apply-binary-updates-keep-base-system-date/#respond Sat, 06 Jan 2018 07:42:12 +0000 http://wiki.shopingserver.com/?p=18405 I

know keeping a FreeBSD server up to date is a very important. How can I apply binary system patches and updates to a new installation of FreeBSD 10 server?

 

You need to use the freebsd-update tool. It is used to fetch, install, and rollback binary updates to the FreeBSD base system.

Find out current FreeBSD release

Type the following command:

uname -mrs

OR

uname -a

Sample outputs:

FreeBSD netbook02 10.0-RELEASE FreeBSD 10.0-RELEASE #0 r260789: Thu Jan 16 22:34:59 UTC 2014     root@snap.freebsd.org:/usr/obj/usr/src/sys/GENERIC  amd64

FreeBSD install security updates and patch the server

Type the following command on a newly installed FreeBSD server:

# freebsd-update fetch install

 

Sample outputs:

freebsd-update fetch install

Looking up update.FreeBSD.org mirrors… 5 mirrors found.

Fetching metadata signature for 10.0-RELEASE from update4.freebsd.org… done.

Fetching metadata index… done.

Inspecting system… done.

Preparing to download files… done.

 

The following files will be updated as part of updating to 10.0-RELEASE-p5:

/bin/freebsd-version

/boot/kernel/ciss.ko

/boot/kernel/ciss.ko.symbols

/boot/kernel/kernel

/boot/kernel/kernel.symbols

/boot/kernel/nfsd.ko

/boot/kernel/nfsd.ko.symbols

/etc/defaults/rc.conf

/lib/libcrypto.so.7

/rescue/[

/rescue/atmconfig

/rescue/badsect

….

..

/usr/src/etc/defaults/rc.conf

/usr/src/sys/conf/newvers.sh

/usr/src/sys/dev/ciss/ciss.c

/usr/src/sys/fs/nfsserver/nfs_nfsdserv.c

/usr/src/sys/kern/kern_exec.c

/usr/src/sys/netinet/tcp_reass.c

/usr/src/sys/sys/proc.h

/usr/src/sys/vm/vm_map.c

/var/db/mergemaster.mtree

Installing updates… done.

Reboot the FreeBSD server

Type the following command:

# reboot

Verify new system

Type the following command:

# uname -mrs

 

OR

# uname -a

 

Sample outputs:

Fig. 01: Newly updated FreeBSD 10 server

See also

FreeBSD apply security updates for installed ports/applications

 

 

]]>
https://wiki.shopingserver.com/freebsd-10-apply-binary-updates-keep-base-system-date/feed/ 0
HowTo: Use ps, kill, nice, and killall To Manage processes in FreeBSD and OS X Unix Operating System https://wiki.shopingserver.com/howto-use-ps-kill-nice-killall-manage-processes-freebsd-os-x-unix-operating-system/ https://wiki.shopingserver.com/howto-use-ps-kill-nice-killall-manage-processes-freebsd-os-x-unix-operating-system/#respond Fri, 05 Jan 2018 16:13:51 +0000 http://wiki.shopingserver.com/?p=18379 I

‘m a new Unix system user. How can I manage process on a FreeBSD operating systems?

 

A process is nothing but an executing program on FreeBSD or Unix-like system. Each process on the system provides the resources needed to run a program such as vim or firefox. Each process has:

A unique process identifier number (PID)

A virtual address space

A security context

Open devices/handles, executable code

Environment variables, priority and more.

In this quick tutorial, I will write about process management on a FreeBSD operating systems.

View running processes in FreeBSD

The ps or process status command is a command that lists process activities. Many people use the top command to interactively list the processes, but for scripting purpose ps is user friendly. The basic syntax is as follows:

$ ps

 

Sample outputs:

Fig.01: FreeBSD ps command output showing process

List process using ps command

Example using flags:

$ ps -auxw

 

Fig.02 ps command with flags

 

Where,

a = Display information about other users’ processes as well as your own.

u = Display the processes belonging to the specified usernames.

x = When displaying processes matched by other options, skip any processes which do not have a controlling terminal. This is the default behavior.

w = Use 132 columns to display information, instead of the default which is your window size.

How to list process using top command

Another easiest way to find out what processes are running on FreeBSD is to type top command:

$ top

 

Sample outputs:

last pid:   762;  load averages:  0.35,  0.30,  0.20                                                                                                 up 0+00:17:04  11:09:01

15 processes:  1 running, 14 sleeping

CPU:  0.0% user,  0.0% nice,  0.0% system,  0.4% interrupt, 99.6% idle

Mem: 13M Active, 16M Inact, 65M Wired, 23M Buf, 3624M Free

Swap: 4071M Total, 4071M Free

 

PID USERNAME    THR PRI NICE   SIZE    RES STATE    TIME    WCPU COMMAND

736 ec2-user      1  20    0 17064K  2660K wait     0:00   0.00% sh

734 ec2-user      1  20    0 25752K  3024K pause    0:00   0.00% screen

714 ec2-user      1  20    0 86472K  7228K select   0:00   0.00% sshd

735 ec2-user      1  20    0 25752K  4432K select   0:00   0.00% screen

712 root          1  20    0 86472K  7228K select   0:00   0.00% sshd

602 root          1  20    0 24104K  5292K select   0:00   0.00% sendmail

411 root          1  20    0 14492K  2136K select   0:00   0.00% syslogd

715 ec2-user      1  20    0 17064K  2668K wait     0:00   0.00% sh

762 ec2-user      1  20    0 21916K  2816K RUN      0:00   0.00% top

657 root          1  20    0 16592K  2256K nanslp   0:00   0.00% cron

627 root          1  20    0 61204K  6556K select   0:00   0.00% sshd

333 root          1  20    0 13164K  4508K select   0:00   0.00% devd

294 root          1  52    0 14624K  2236K select   0:00   0.00% dhclient

605 smmsp         1  52    0 24104K  4952K pause    0:00   0.00% sendmail

332 _dhcp         1  52    0 14624K  2340K select   0:00   0.00% dhclient

To quit from the top command type (or hit) q and to display help hit h.

Quickly finding the PID of a process on FreeBSD

Use the pgrep command to search the process table on the running system and prints the process IDs (PID) of all processes that match the criteria given on the command line. The syntax is:

pgrep process

pgrep -u user process

pgrep firefox

pgrep -u www-data nginx

A quick way of getting the PID of a process called dhclient is with the pgrep command, type:

$ pgrep dhclient

 

Sample outputs:

332

How to send processes signals in FreeBSD Unix system

You can send signals to all processes in FreeBSD. For example, SIGTERM can gracefully kill the process.

Send processes signals by PID

The kill command kills process by process identification (PID). Note that the user must have sufficient privileges to kill the process. The basic syntax is as follows:

$ kill <PID>

$ kill -s signalName <PID>

 

For example:

$ kill -s SIGTERM 454

$ kill -signalName <PID>

$ kill -SIGHUP 6765

$ kill -signalNumber <PID>

$ kill -9 868

 

To find your PID use pgrep command. It will look like this for example:

$ pgrep firefox

 

23872

From there you can issue the kill command to kill firefox process:

$ kill 23872

 

You can also send multiple kills.

$ kill <PID> <PID> <PID>

$ kill 3455 79754 3454

 

If you want to kill without cleaning up you use the -9 signal:

$ kill -9 <PID>

$ kill -9 5858

List signals

Type the following command:

$ kill -l

 

Sample output:

Fig.03: List the signal names with the -l option on Unix

SOME OF THE MORE COMMONLY USED SIGNALS AND MEANING

———-+———————————————-

SIGNAL  |   NAME (Meaning)

———-+———————————————-

1    |   HUP (hang up)

2    |   INT (interrupt)

3    |   QUIT (quit)

6    |   ABRT (abort)

9    |   KILL (non-catchable, non-ignorable kill)

14   |   ALRM (alarm clock)

15   |   TERM (software termination signal)


To kill process by name, use killall command

The basic syntax is as follows:

$ killall process

$ killall firefox

$ killall -SIGNAL process

$ killall -term firefox

$ killall -15 command

$ killall -15 firefox

 

To kill user’s process:

$ killall -u <user> process

$ killall -u tom firefox

 

Depending upon your shell you might need different flags or signals. Consult your man pages (man signal). The examples are so you get an idea and not absolute. For example, on my laptop using csh I cannot use the command killall process. I must use at least one option or argument to specify process. Note, there is also pkill command which kills the processes by name, but since it uses pattern matching and not the precise process name, it can be potentially dangerous compared to killall. Here is an example of dangerous pkill command which kills FreeBSD based server or desktop:

$ sudo pkill -v firefox

 

The -v option reverse the sense of the matching; display processes that do not match the given criteria. See pkill man page for more info.

How to adjust process priorities

The nice command runs process at a low priority. nice assumes the value of 10. The priority is a value range -20 to 20. The default priority is 0, priority 20 is the lowest possible. Negative numbers are expressed by -. You need to be root if you want to change the process prority to higher priorities. Different shells are different so it’s best to consult your nice manual page. I mainly use csh. nice command is more useful on servers or workstation where several processes are demanding more resources than the CPU can provide. Use following commands to set a larger chunk of the CPU time than a lower priority process on a FreeBSD.

nice command usage examples

Execute command date at priority 5 assuming the priority of the shell is 0.

$ nice -n 5 date

 

This is an example where you need to be superuser or root:

# nice -16 nice –35 date

 

Execute command date`at priority -19 assuming the priority of the shell is 0. I have never had to use this command because with today’s systems we have such high RAM+CPU and processing power these things aren’t a problem like when first introduced. It’s nice to know nice though just in case.

How to alters the scheduling priority of running processes

The nice command only works when beginning a new process i.e. start of the command. Use the renice command to alters the scheduling priority running processes. The syntax is:

$ renice priority pid

$ renice -n increment pid

$ renice -u user pid

 

To Change the priority of process ID’s 4242 and 344, and all processes owned by root, enter:

$ sudo renice +1 -u root -p 344 4242

How to see realtime and idle priority of of running processes

A process with a realtime priority is not subject to priority degradation, and will only be preempted by another process of equal or higher realtime priority. A process with an idle priority will run only when no other process is runnable and then only if its idle priority is equal or greater than all other runnable idle priority processes. Priority is an integer between 0 and RTP_PRIO_MAX (usually 31). 0 is the highest priority. 31 is the lowest priority. To see which realtime priority the current process is at, just type the following command:

$ rtprio

 

Sample outputs:

rtprio: normal priority

To see which realtime priority of process 715:

$ rtprio 715

 

To change the realtime priority of process 715 to 16, enter:

# rtprio 16 -1423

 

To run backup.py script while not disturbing other server usage, enter:

# idprio 31 /path/to/my/awesome/backup.py

 

See rtprio command man page for more info.

This quick tutorial was contributed by Wendy Michele. You can too contribute to nixCraft.

 

 

]]>
https://wiki.shopingserver.com/howto-use-ps-kill-nice-killall-manage-processes-freebsd-os-x-unix-operating-system/feed/ 0
How To Install MariaDB Databases on a FreeBSD v10/11 Unix Server https://wiki.shopingserver.com/install-mariadb-databases-freebsd-v10-11-unix-server/ https://wiki.shopingserver.com/install-mariadb-databases-freebsd-v10-11-unix-server/#respond Fri, 05 Jan 2018 16:06:18 +0000 http://wiki.shopingserver.com/?p=18371 I

‘m a new FreeBSD unix user. How can I install MariaDB database server on a FreeBSD unix based system?

 

MySQL is a very fast, multi-threaded, multi-user and robust SQL database server. The latest version is located at /usr/ports/databases/mysql57-server/. MariaDB is a database server that offers drop-in replacement functionality for MySQL1. MariaDB is built by some of the original authors of MySQL, with assistance from the broader community of Free and open source software developers around the world. In addition to the core functionality of MySQL, MariaDB offers a rich set of feature enhancements including alternate storage engines, server optimizations, and patches. The latest version is located at /usr/ports/databases/mariadb55-server/. In this tutorial, you will learn how to install MariaDB server and create a databases, users, and grant sql rights using sql commands on a FreeBSD 10 or 11 server.

Update all your ports

Make sure your ports are installed and up to date. I like to do:

# portsnap fetch update && portupgrade -a

FreeBSD MariaDB installation

To install MariaDB Server, MariaDB Client and MariaDB Scripts type the following commands.

A note about MySQL and MariaDB server together

You cannot run MariaDB and MySQL installed together. You will have deinstall one or the other and the clients if you have them. If you want to run them both, you

will need them to be jailed apart. If you are new it’s best to not think about this and run them one at a time focusing on learning one or the other. So for example if you have MySQL and want to install MariaDB you need to deinstall before installing. Check what version you are using by typing the command as root:

# pkg version | grep mysql

 

or as user or root you can type this command:

# mysql –version

 

or use pkg command:

# pkg info | grep mysql

 

Make sure you backup database before you uninstall mysql-server. To deinstall that:

# cd /usr/ports/databases/mysql57-server/ && make deinstall clean

# cd /usr/ports/databases/mysql57-client/ && make deinstall clean

# rm -rf /var/db/mysql/

 

or use pkg command to delete them:

# pkg remove mysql56-server mysql56-client

# rm -rf /var/db/mysql/

Install MariaDB server

To install the port, type:

# cd /usr/ports/databases/mariadb100-server && make install clean

 

When you install make sure you check what you want off in the configuration:

Fig.01: FreeBSD 10 Mariadb Server Install Command

 

Or, to add the binary package using pkg command, run:

# pkg install databases/mariadb100-server

 

Sample outputs:

Fig.02: FreeBSD 10 Install Mariadb using the pkg command

 

Here is output from my FreeBSD 11 box:

Updating FreeBSD repository catalogue…

FreeBSD repository is up-to-date.

All repositories are up-to-date.

The following 5 package(s) will be affected (of 0 checked):

 

New packages to be INSTALLED:

mariadb100-server: 10.0.29

openssl: 1.0.2j_1,1

mariadb100-client: 10.0.29

readline: 6.3.8

indexinfo: 0.2.6

 

Number of packages to be installed: 5

 

The process will require 244 MiB more space.

34 MiB to be downloaded.

 

Proceed with this action? [y/N]: y

Install MariaDB client only

MariaDB Client will be installed automatically. You should now check following options:

[X] THREADSAFE  Build thread-safe client

[X] SSL         Activate SSL support (yassl)

However, if you need MariaDB client on another FreeBSD server or jail, run:

# cd /usr/ports/databases/mariadb100-client

# make install clean

 

OR

# pkg install databases/mariadb100-client

 

Sample outputs:

Fig.03: FreeBSD 11 install mariadb client

How do I start MariaDB on boot?

Type the following command:

echo  mysql_enable= YES   >> /etc/rc.conf

How do I install MariaDB server configuration file?

MariaDB respects FreeBSD layout of file systems (and doesn’t check /etc and /etc/mysql for my.cnf. You will find the following default config files:

# ls -l /usr/local/share/mysql/my*.cnf

 

Sample outputs:

-rw-r–r–  1 root  wheel   4898 Nov 26 12:56 /usr/local/share/mysql/my-huge.cnf

-rw-r–r–  1 root  wheel  20418 Nov 26 12:56 /usr/local/share/mysql/my-innodb-heavy-4G.cnf

-rw-r–r–  1 root  wheel   4885 Nov 26 12:56 /usr/local/share/mysql/my-large.cnf

-rw-r–r–  1 root  wheel   4898 Nov 26 12:56 /usr/local/share/mysql/my-medium.cnf

-rw-r–r–  1 root  wheel   2824 Nov 26 12:56 /usr/local/share/mysql/my-small.cnf

I’m setting up a medium sized server, so I’m going to copy /usr/local/share/mysql/my-medium.cnf to /usr/local/etc/ directory using cp command:

# cp /usr/local/share/mysql/my-medium.cnf /usr/local/etc/my.cnf

 

To edit /usr/local/etc/my.cnf, enter:

# vi !!:2

 

OR

# vi /usr/local/etc/my.cnf

 

To enable remote access to MariaDB database server, enter:

# change ip

bind-address = 127.0.0.1

Save and close the file.

How do I start/stop/restart MariaDB on a FreeBSD 10?

To start the server you are going to type:

# service mysql-server start

 

You will see the following information when you start the server for the first time:

Fig.03 Starting the start for the first time

 

To stop the server you are going to type:

# service mysql-server stop

 

To restart the server you are going to type:

# service mysql-server restart

 

To see the server status you are going to type:

# service mysql-server status

 

You can also use the following commands for the same purpose:

call rc.d script to control MariaDB server ##

/usr/local/etc/rc.d/mysql-server start

/usr/local/etc/rc.d/mysql-server stop

/usr/local/etc/rc.d/mysql-server restart

/usr/local/etc/rc.d/mysql-server status

Sample outputs:

Fig.04: Starting/Stopping MariaDB server on a FreeBSD 10

How do I set root user password for MariaDB?

You should create password for root user after MariaDB installation, enter:

# mysqladmin -u root password YOURSECUREPASSWORD

 

Alternatively, I suggest that you can run the following command to set root password. This command will also give you the option of removing the test databases and anonymous user created by default. This is strongly recommended for production servers:

# /usr/local/bin/mysql_secure_installation

 

Sample outputs:

 

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB

SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

 

In order to log into MariaDB to secure it, we ll need the current

password for the root user.  If you ve just installed MariaDB, and

you haven t set the root password yet, the password will be blank,

so you should just press enter here.

 

Enter current password for root (enter for none):

OK, successfully used password, moving on…

 

Setting the root password ensures that nobody can log into the MariaDB

root user without the proper authorisation.

 

Set root password? [Y/n] y

New password:

Re-enter new password:

Password updated successfully!

Reloading privilege tables..

… Success!

 

 

By default, a MariaDB installation has an anonymous user, allowing anyone

to log into MariaDB without having to have a user account created for

them.  This is intended only for testing, and to make the installation

go a bit smoother.  You should remove them before moving into a

production environment.

 

Remove anonymous users? [Y/n] y

… Success!

 

Normally, root should only be allowed to connect from  localhost .  This

ensures that someone cannot guess at the root password from the network.

 

Disallow root login remotely? [Y/n] y

… Success!

 

By default, MariaDB comes with a database named  test  that anyone can

access.  This is also intended only for testing, and should be removed

before moving into a production environment.

 

Remove test database and access to it? [Y/n] y

– Dropping test database…

… Success!

– Removing privileges on test database…

… Success!

 

Reloading the privilege tables will ensure that all changes made so far

will take effect immediately.

 

Reload privilege tables now? [Y/n] y

… Success!

 

Cleaning up…

 

All done!  If you ve completed all of the above steps, your MariaDB

installation should now be secure.

 

Thanks for using MariaDB!

Notes: If you get message with unknown MySQL version when installing ports, you should edit /etc/make.conf and add line:

MYSQL52_LIBVER=16

You can edit with ee or your favorite editor. With ee type:

ee  /etc/make.conf

MYSQL52_LIBVER=16

pres Esc

a,a

or b if you do not want to save the changes.

How do I connect to MariaDB server?

The syntax is:

mysql

mysql -u user -p

mysql -h db-hostname-here -u user-name-here -p

How do I create MariaDB database and users?

First, login as root user:

mysql -u root -p mysql

Sample outputs:

Fig.05: Connecting to the server using mysql client

 

Create a new mysql database called foo. Type the following command at mysql> prompt:

MariaDB [mysql]>  CREATE DATABASE foo;

Create a new user called user1 for database called foo with a password called ‘hiddensecret’:

MariaDB [mysql]>  GRANT ALL ON foo.* TO user1@localhost IDENTIFIED BY  hiddensecret ;

How do I connect to MariaDB database foo using user1 account?

User user1 can connect to the foo database using the following shell command:

$ mysql -u user1 -p foo

 

OR

$ mysql -u user1 -h your-mysql-server-host-name-here -p foo

 

Sample session:

Fig.06: Creating users and database on the MariaDB server

 

See “Mysql User Creation: Setting Up a New MySQL User Account” tutorial for more information.

How do I enable remote access to the MariaDB server?

Edit the my.cnf file, run:

# vi /usr/local/etc/my.cnf

 

Make sure line skip-networking is commented (or remove line) and add the following line in the [mysqld] section:

bind-address=YOUR-SERVER-IP

For example, if your MariaDB server IP is 192.168.1.5 then entire block should be look like as follows:

# The MariaDB server

[mysqld]

port            = 3306

bind-address    = 192.168.1.5

socket          = /tmp/mysql.sock

skip-external-locking

key_buffer_size = 16M

max_allowed_packet = 1M

table_open_cache = 64

sort_buffer_size = 512K

net_buffer_length = 8K

read_buffer_size = 256K

read_rnd_buffer_size = 512K

myisam_sort_buffer_size = 8M

 

# Point the following paths to different dedicated disks

#tmpdir         = /tmp/

# Don t listen on a TCP/IP port at all. This can be a security enhancement,

# if all processes that need to connect to mysqld run on the same host.

# All interaction with mysqld must be made via Unix sockets or named pipes.

# Note that using this option without enabling named pipes on Windows

# (via the  enable-named-pipe  option) will render mysqld useless!

#

#skip-networking

log-bin=mysql-bin

binlog_format=mixed

server-id       = 1

Save and close the file. Restart the server:

# service mysql-server restart

 

Update your pf.conf file:

allows mysql client from 192.168.1.200 ##

pass in on $ext_if proto tcp from 192.168.1.200to any port 3306  flags S/SA synproxy state

Restart pf and test connectivity from 192.168.1.200 by typing any one of the following command:

# use nc for port testing ##

nc -z -w1 192.168.1.5 3306

# or old good telnet ##

echo X | telnet -e X 192.168.1.5 3306

telnet -e X 192.168.1.5 3306<<< X

or use mysql client ##

mysql -h 192.168.1.5 -u USER -p DB

How do I grant access to an existing database over the LAN based session?

Let us assume that you are always making connection from remote IP called 192.168.1.200 for database called foo for user bar, To grant access to this IP address type the following command at MariaDB [mysql]> prompt for existing database, enter:

MariaDB [mysql]> update db set Host= 192.168.1.200  where Db= foo ;

MariaDB [mysql]> update user set Host= 192.168.1.200  where user= bar ;

See “How Do I Enable Remote Access To MySQL Database Server?” tutorial for more information.

How to open ports in a FreeBSD pf firewall

Add the following rule in your pf.conf file:

pass in on $ext_if proto tcp from any to any port 3306

OR only allow access from 192.168.1.10:

pass in on $ext_if proto tcp from 192.168.1.10 to any port 3306

]]>
https://wiki.shopingserver.com/install-mariadb-databases-freebsd-v10-11-unix-server/feed/ 0
How To Add Swap on FreeBSD Unix Systems https://wiki.shopingserver.com/add-swap-freebsd-unix-systems/ https://wiki.shopingserver.com/add-swap-freebsd-unix-systems/#respond Fri, 05 Jan 2018 15:58:03 +0000 http://wiki.shopingserver.com/?p=18361 I

need additional swap space to improve my FreeBSD Unix server/desktop performance. How do I add a swap file to FreeBSD system using command line options without creating a new partitions? How do I encrypt swap space on a FreeBSD Unix server for security purpose?

 

A swap is nothing but space or file on a disk that can used as virtual memory. In FreeBSD and Unix-like operating systems, it is common to use a whole partition of a hard disk for swapping. When a FreeBSD based server runs out of memory, the kernel can move sleeping or inactive processes into swap area. A dedicated Swap partition goes a long way to avoid system freeze but if you notice you are running out of RAM or your applications are consuming too much of it then you may want to setup a swapfile. This guide helps you add a swap space on FreeBSD based Unix server.

How do I add swap on FreeBSD version 9 or older?

You will create the swap file by typing the following dd command as the root user:

dd if=/dev/zero of=/root/swap.8G.bin bs=1M count=8192

This should create an 8GB file called swap.8G.bin in /root/. To make sure this worked you can type:

ls -alh  /root/swap.8G.bin

For security reason set the permissions, run:

chmod 0600 /root/swap.8G.bin

ls -alh  /root/swap.8G.bin

Sample outputs:

Fig.01: How to create a swap file on FreeBSD version 9.X and Earlier Commands

How do I activate swap space on the boot time?

To add this to your rc.conf you will type:

echo  swapfile= /root/swap.8G.bin   >> /etc/rc.conf

If you want to see if it is there in your rc.conf you can type:

tail /etc/rc.conf

Reboot the system:

reboot

A NOTE ABOUT ENABLING THE SWAP FILE IMMEDIATELY WITHOUT REBOOTING THE SYSTEM

If you want to apply the swapfile immediately type the following command:

Enable swap space ##

mdconfig -a -t vnode -f /root/swap.8G.bin -u 0

 

Find out configured devices i.e. swap device name ##

mdconfig -l -v

 

Turn it on ##

swapon /dev/md0

Sample outputs:

Fig.02: FreeBSD find out swap device name created/attached with the mdconfig command

 

To see details of your swap information type:

swapinfo -k

swapinfo -k | grep  /root/swap.8G.bin

swapinfo -h

Sample outputs:

Device          1K-blocks     Used    Avail Capacity

/dev/ada0p3       1048540     736K     1.0G     0%

/dev/md0          8388608       0B     8.0G     0%

Total             9437148     736K     9.0G     0%

How to set up swap file on FreeBSD version 10.x or later

First, create the swap file (128M) using dd command:

dd if=/dev/zero of=/root/swap1 bs=1m count=128

Set the proper permissions on the new file for security reason:

chmod 0600 /root/swap1

Edit /etc/fstab, enter:

vi /etc/fstab

Add/append the following line:

md42 will be assigned by system, use any unused device name (run  mdconfig -lv  to get list of attached memory device names) ##

md42 none swap sw,file=/root/swap1 0 0

If you want to see if it is there in your /etc/fstab you can type:

tail /etc/fstab

Now, swap space will be added on system boot time. To add and activate swap space immediately, run:

swapon -aq

To see details of your swap type:

swapinfo -k

Sample session from my FreeBSD10 based server:

Fig.03: How to add a swap file on FreeBSD version 10.x and Later

A note about securing and encrypting swap space on a FreeBSD server

Encrypting swap space can avoid leakage of sensitive information such as passwords and other data in memory.

Procedure to encrypt swap file

Type the following command to create a swap file called /root/en.swap0

# dd if=/dev/random of=/root/en.swap0 bs=1m count=64

# mdconfig -a -t vnode -f /root/en.swap0

# geom eli init md0

 

Sample outputs:

Enter new passphrase:

Reenter new passphrase:

 

Metadata backup can be found in /var/backups/md0.eli and

can be restored with the following command:

 

# geli restore /var/backups/md0.eli md0

Attach md0, enter:

# geom eli attach md0

 

Turn on encrpted swap file:

# swapon /dev/md0.eli

 

Verify newly created swap space:

# swapinfo -k

 

Sample session:

Fig.04: Encrypting swap file on a FreeBSD 10.x server

 

This hack is a little ugly but works. I strongly suggest that you use encrypted swap space as described here.

How can I disable devices and files for paging and swapping on FreeBSD?

Type the following command to disable /dev/md0 swap space:

# swapoff /dev/md0

# swpainfo -k

How can I display swap usage summary on FreeBSD?

Use the top command:

# top

 

Sample outputs (look for Swap in outputs):

last pid:   874;  load averages:  0.47,  0.32,  0.27                                                                                                                                                                                                    up 0+00:34:48  16:52:35

22 processes:  1 running, 21 sleeping

CPU:  0.0% user,  0.0% nice,  0.0% system,  0.0% interrupt,  100% idle

Mem: 14M Active, 13M Inact, 104M Wired, 80M Buf, 1841M Free

Swap: 1216M Total, 1216M Free

 

PID USERNAME    THR PRI NICE   SIZE    RES STATE    TIME    WCPU COMMAND

721 root          1  20    0 25328K  3704K select   0:00   0.00% ntpd

755 root          1  20    0 86084K  6896K select   0:00   0.00% sshd

765 root          1  20    0 23980K  5188K select   0:00   0.00% sendmail

758 root          1  20    0 23492K  3452K pause    0:00   0.00% csh

….

..

You can also use pstat or swapinfo commands:

# pstat -s

 

OR

# swapinfo -k

 

You can also use vmstat/systat commands:

# vmstat

# systat swap

 

See man pages for more info:

$ man vmstat

$ man systat

$ man top

$ man swapinfo

$ man pstat

 

This entry is 2 of 2 in the Linux and UNIX Swap File Management Tutorial series. Keep reading the rest of the series:

Linux Add a Swap File

FreeBSD Add a Swap File

 

 

]]>
https://wiki.shopingserver.com/add-swap-freebsd-unix-systems/feed/ 0
FreeBSD Force DHCP Client (dhclient) to Renew IP Address To Get A New Lease https://wiki.shopingserver.com/freebsd-force-dhcp-client-dhclient-renew-ip-address-get-new-lease/ https://wiki.shopingserver.com/freebsd-force-dhcp-client-dhclient-renew-ip-address-get-new-lease/#respond Fri, 05 Jan 2018 15:50:34 +0000 http://wiki.shopingserver.com/?p=18353 I

have a Linux DD-WRT router DHCP server running on my network. How can I force my FreeBSD based dhcp client to get a new lease from this Linux based router? What is the command in FreeBSD equivalent to Windows’ “ipconfig /renew” command?

 

The dhclient command, provides a means for configuring one or more network interfaces using the Dynamic Host Configuration Protocol, BOOTP protocol, or if these protocols fail, by statically assigning an address.

FreeBSD renew ip command

The syntax is:

dhclient interface-name-here

dhclient [options] interface-name-here

The name of the interface must be specified on the command line. You must run this command as the root user.

How can I see the current IP address settings?

Type the following command:

ifconfig

ifconfig interface

ifconfig em0

ifconfig em0 | grep inet

Sample outputs:

Fig.01: FreeBSD Display Current IP Address, Netmask and Ethernet Options

How can I renew or release an IP in FreeBSD for em0 interface?

The syntax is:

$ sudo dhclient em0

 

#################################

OR first use  su –  and then type ##

#################################

# dhclient em0

Sample outputs:

Fig.02: Renew an IP address on FreeBSD using dhclient

Other options in FreeBSD to renew dhcp IP address

You can also use the following command to renew dhcp IP address for em0:

service dhclient restart em0

 

OR ##

/etc/rc.d/dhclient restart em0

Sample outputs:

Stopping dhclient.

Starting dhclient.

DHCPREQUEST on em0 to 255.255.255.255 port 67

DHCPACK from 192.168.1.254

bound to 192.168.1.142 — renewal in 43200 seconds.

dhclient log file

In order to keep track of leases across system reboots and server restarts, dhclient keeps a list of leases it has been assigned in the /var/db/dhclient.leases.IFNAME file. IFNAME represents the network interface of the DHCP client (e.g., em0), one for each interface:

tail -f /var/db/dhclient.leases.em0

OR

less /var/db/dhclient.leases.em0

Sample outputs:

lease {

interface  em0 ;

fixed-address 192.168.1.142;

next-server 192.168.1.254;

option subnet-mask 255.255.255.0;

option routers 192.168.1.254;

option domain-name-servers 192.168.1.254;

option host-name  freebsd10 ;

option broadcast-address 192.168.1.255;

option dhcp-lease-time 86400;

option dhcp-message-type 5;

option dhcp-server-identifier 192.168.1.254;

option dhcp-renewal-time 43200;

option dhcp-rebinding-time 75600;

renew 0 2015/2/1 21:38:04;

rebind 1 2015/2/2 06:38:04;

expire 1 2015/2/2 09:38:04;

}

lease {

interface  em0 ;

fixed-address 192.168.1.142;

next-server 192.168.1.254;

option subnet-mask 255.255.255.0;

option routers 192.168.1.254;

option domain-name-servers 192.168.1.254;

option host-name  freebsd10 ;

option broadcast-address 192.168.1.255;

option dhcp-lease-time 86400;

option dhcp-message-type 5;

option dhcp-server-identifier 192.168.1.254;

option dhcp-renewal-time 43200;

option dhcp-rebinding-time 75600;

renew 0 2015/2/1 21:44:47;

rebind 1 2015/2/2 06:44:47;

expire 1 2015/2/2 09:44:47;

}

References

See dhclient man page for more info on a FreeBSD server:

$ man dhclient

 

 

]]>
https://wiki.shopingserver.com/freebsd-force-dhcp-client-dhclient-renew-ip-address-get-new-lease/feed/ 0
FreeBSD Unix Show Mounted File Systems https://wiki.shopingserver.com/freebsd-unix-show-mounted-file-systems/ https://wiki.shopingserver.com/freebsd-unix-show-mounted-file-systems/#respond Fri, 05 Jan 2018 15:46:17 +0000 http://wiki.shopingserver.com/?p=18347 I

recently switched from MS-Windows server to a FreeBSD Unix server. How can I see list of mounted file systems on a FreeBSD based Unix server using command line options?

 

The command to view mounted files systems, to mount or add any local devices such USB,DVD/CD or remote file systems such asNFS, SAMBA shares or files is the mount command on a FreeBSD operating systems.

How can I list mounted local and remote file systems?

This will list mounted remote and local file systems, run:

$ mount

 

Sample outputs:

/dev/ada0p2 on / (ufs, local, journaled soft-updates)

devfs on /dev (devfs, local, multilabel)

192.168.1.10:/exports/nas01/data on /mnt/nfs (nfs)

The first field displays the special device such as /dev/ada0p2 or remote file system such as 192.168.1.10:/exports/nas01/data mounted on second field. The second field is the mount point for the file system displayed in the first field. Adding the -v flag will add IDs too:

$ mount -v

 

Sample outputs:

/dev/ada0p2 on / (ufs, local, journaled soft-updates, writes: sync 3 async 50, reads: sync 1193 async 10, fsid f64cdd52f9f387e7)

devfs on /dev (devfs, local, multilabel, fsid 00ff007171000000)

192.168.1.10:/exports/nas01/data on /mnt/nfs (nfs, fsid 01ff003a3a000000)

If you want to see only a specific file system you would use the -t flag. For example, only show a ufs based mounted file system, enter:

$ mount -t ufs

 

OR just show a nfs based mounted file system, type:

$ mount -t nfs

 

Sample outputs:

192.168.1.10:/exports/nas01/data on /mnt/nfs (nfs)

/etc/fstab file

The /etc/fstab contains descriptive information about the various file systems. fstab is only read by programs, and not written; it is the duty of the system administrator to properly create and maintain this file. To see this file, type:

more /etc/fstab

less /etc/fstab

column -t /etc/fstab

Sample outputs:

# Device Mountpoint FStype Options Dump Pass#

/dev/ada0p2 /  ufs rw 1 1

/dev/ada0p3 none  swap sw 0 0

md42     none     swap    sw,file=/root/swap1 0 0

More on column -t command

The column command formats its input into multiple columns. It is useful to display mounted file systems in a table format:

mount | column -t

Or try:

( printf  Device Mounted On (FileSystem_info)\n  ; mount ) | column -t

Sample outputs:

Fig.01: Freebsd Unix mount command and column -t to display output in a table format.

df command examples

The df command shows statistics about the amount of free disk space on a FreeBSD system:

df

 

Use 1024 byte (1 Kibibyte) blocks rather than the default. ##

df -k

 

Human-readable outputs ##

df -H

Sample outputs:

Filesystem                          Size    Used   Avail Capacity  Mounted on

/dev/ada0p2                          20G     11G    7.5G    59%    /

devfs                               1.0k    1.0k      0B   100%    /dev

192.168.1.10:/exports/nas01/data    1.6T    297G    1.2T    20%    /mnt/nfs

This quick tutorial was contributed by Wendy Michele. Editing by admin. You can too contribute to nixCraft.

 

 

]]>
https://wiki.shopingserver.com/freebsd-unix-show-mounted-file-systems/feed/ 0
FreeBSD Unix Find Out Which Programs Are Listening On a Given Port Number https://wiki.shopingserver.com/freebsd-unix-find-programs-listening-given-port-number/ https://wiki.shopingserver.com/freebsd-unix-find-programs-listening-given-port-number/#respond Fri, 05 Jan 2018 15:40:55 +0000 http://wiki.shopingserver.com/?p=18339 I

‘m a new FreeBSD Unix system user. How can I find out the process/programs names listing on a certain port on a FreeBSD Unix systems using command line? How do I lookup the process which is currently bound to the given network port on a FreeBSD server?

 

You can use any one of the following command-line tools that displays network connections, routing tables, and a number of network interface statistics on a FreeBSD operating systems.

netstat command – Use to see network status including open ports, tcp/udp connections, and more.

sockstat command – Show open sockets.

lsof command – List open files such as network sockets and files on disks.

FreeBSD has a command called sockstat and netstat tools. These are already on a standard FreeBSD install. You need to install the lsof tool from ports collection.

Find the process listening on a certain port using the sockstat command

An example of the netstat command with flags:

Show listening sockets ##

sockstat -l

 

Show listening sockets for IPv4 only ##

sockstat -4 -l

 

Show listening sockets for IPv6 only ##

sockstat -6 -l

Sample outputs:

Fig.01: FreeBSD sockstat command in action

 

Where,

USER : The user who owns and open the socket.

COMMAND : The command which is responsible for the socket.

PID : The process ID of the command which responsible/holds the socket.

FD : The file descriptor number of the socket.

PROTO : The transport protocol associated with the socket for Internet sockets, or the type of socket (stream or datagram) for UNIX sockets.

LOCAL ADDRESS : For Internet sockets, this is the address the local end of the socket is bound to. For bound UNIX sockets, it is the socket’s filename. For other UNIX sockets, it is a right arrow followed by the endpoint’s filename, or ‘??’ if the endpoint could not be determined.

FOREIGN ADDRESS : (Internet sockets only) The address the foreign end of the socket is bound to.

Find selected ports

You can use the grep command to select a certain ports. In this example, find out if port 22 and 80 is open or not:

sockstat -4 -l | grep :22

sockstat -4 -l | grep :80

Sample outputs:

root     sshd       642   4  tcp4   *:22                  *:*

Show connected sockets only

The syntax is:

sockstat -c

sockstat -c -4

sockstat -c -4 | grep ssh

sockstat -c -4 | grep 22

root     sshd       740   3  tcp4   192.168.1.142:22      192.168.1.4:55115

(192.168.1.4 == client IP and 192.168.1.142 == server IP for port 22)

netstat command example to find out open ports and their process

Here the equivalent of netstat:

netstat -a -n | grep LISTEN

netstat -a | egrep  LISTEN|Proto|Active

netstat -a | egrep  Proto|LISTEN

Sample outputs:

Active Internet connections (including servers)

Proto Recv-Q Send-Q Local Address          Foreign Address        (state)

tcp4       0      0 localhost.smtp         *.*                    LISTEN

tcp4       0      0 *.ssh                  *.*                    LISTEN

tcp6       0      0 *.ssh                  *.*                    LISTEN

Active UNIX domain sockets

Even though sockstat is thought to be more limited, it is nice to know because at times it can be more useful in gathering certain information. On a FreeBSD, you can get a listing of standard port associations by looking in the /etc/services. If you wanted to find out the purpose of port 631, you can use this command for example:

$ grep -w 631 /etc/services

ipp  631/tcp    #IPP (Internet Printing Protocol)

ipp  631/udp    #IPP (Internet Printing Protocol)

what the purpose of port 22 ?##

$ grep -w 22 /etc/services

ssh   22/sctp   #Secure Shell Login

ssh   22/tcp    #Secure Shell Login

ssh   22/udp    #Secure Shell Login

It’s handy if you don’t know about ports and are learning about it.

Use lsof command to determine the process/pid listening on a certain port

Some people who have migrated from Linux to BSD like lsof command. It isn’t standard like netstat and sockstat. You will have to install it. At this time there is no package.

To install it as root. So first, install the lsof command using the port:

# cd /usr/ports/sysutils/lsof/ && make install clean

 

Or use the pkg command (warning this may not work on the latest release 10.x):

# pkg install sysutils/lsof

 

Sample outputs:

Updating FreeBSD repository catalogue…

FreeBSD repository is up-to-date.

All repositories are up-to-date.

Checking integrity… done (0 conflicting)

The following 1 packages will be affected (of 0 checked):

 

New packages to be INSTALLED:

lsof: 4.89.c,8

 

The process will require 224 KiB more space.

 

Proceed with this action? [y/N]: y

[1/1] Installing lsof-4.89.c,8…

[1/1] Extracting lsof-4.89.c,8: 100%

To discover the process name, ppid, and other details you need to use the following syntax:

lsof -i :port

lsof -i tcp:portNumber

lsof -i udp:portNumber

For example, see which process is listening upon port 80 or 22 you can run:

lsof -i :80

OR

lsof -i :22

Sample outputs:

COMMAND PID USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME

sshd    642 root    3u  IPv6 0xfffff8000961a400      0t0  TCP *:ssh (LISTEN)

sshd    642 root    4u  IPv4 0xfffff8000961a000      0t0  TCP *:ssh (LISTEN)

sshd    740 root    3u  IPv4 0xfffff800094dec00      0t0  TCP 192.168.1.142:ssh->192.168.1.4:55115 (ESTABLISHED)

To list all open TCP process and their pids, enter:

lsof -iTCP -sTCP:LISTEN

lsof -iTCP -sTCP:LISTEN -P -n

lsof -n -P -i +c 15

Sample outputs:

Fig.02: Find out which process is listening upon a port using lsof utility

References

For information read sockstat command man page:


$ man sockstat

 

For information read netstat command man page:


$ man netstat

 

Not a fan of FreeBSD? See how to find out which process is listening upon a port on a Linux operating systems for more info.

This quick tutorial was contributed by Wendy Michele. Editing by admin. You can too contribute to nixCraft.

 

 

]]>
https://wiki.shopingserver.com/freebsd-unix-find-programs-listening-given-port-number/feed/ 0
How To Find Out FreeBSD Version and Patch Level Number https://wiki.shopingserver.com/find-freebsd-version-patch-level-number/ https://wiki.shopingserver.com/find-freebsd-version-patch-level-number/#respond Fri, 05 Jan 2018 15:05:20 +0000 http://wiki.shopingserver.com/?p=18296 H

ow do I find out my FreeBSD server version and patch level of the installed system using command line option?

 

You can use any one of the following command to display the FreeBSD operating system version and patch level:

a) freebsd-version command – Show the version and patch level of the installed system

b) uname command – Show information about the system

Say hello to freebsd-version command

The freebsd-version command appeared in FreeBSD version 10.0. To see the version and patch level of the installed kernel:

freebsd-version -k

 

To see the version and patch level of the installed userland:

freebsd-version -u

 

Sample outputs:

Fig.01: freebsd-version and other commands in action

 

You can see a system being repaired using a live CD:

mount -rt ufs /dev/ada0p2 /mnt

env ROOT=/mnt /mnt/bin/freebsd-version -ku

You can also use the following command to find out if FreeBSD kernel is running in 32bit or 64bit mode:

# getconf LONG_BIT

 

Sample outputs:

64

Old good uname command

Type the following command (it works on all versions of FreeBSD):

umame -a

uname -mrs

 

Outputs:

FreeBSD 10.1-RELEASE-p10 amd64

 

 

]]>
https://wiki.shopingserver.com/find-freebsd-version-patch-level-number/feed/ 0
FreeBSD Add a User To Wheel Group Command https://wiki.shopingserver.com/freebsd-add-user-wheel-group-command/ https://wiki.shopingserver.com/freebsd-add-user-wheel-group-command/#respond Fri, 05 Jan 2018 14:54:50 +0000 http://wiki.shopingserver.com/?p=18282 H

ow do I add a user to the wheel group in FreeBSD unix operating systems using command line options?

 

You need to use the pw command line utility for adding, modifying and removing users and groups on a FreeBSD operating systems. You must be root user to modify system configuration including pw command.

Add existing user called vivek to the wheel group

The syntax is:

pw group mod {GROUP-NAME-HERE} -m {USERNAME-HERE}

pw group mod wheel -m vivek

If the user named vivek already exists add her to the wheel group.

Add new user called sai while creating a new account

The syntax is:

pw user add {USERNAME-HERE} -G {GROUP-NAME-HERE}

pw user add sai -G wheel

The above command creates the sai primary group automatically, and add a user in the wheel group when her account is first created on a FreeBSD unix operating systems.

How do I verify new group membership on a FreeBSD?

The syntax is:

pw groupshow {GROUP-NAME-HERE}

pw groupshow wheel

pw groupshow sai

pw groupshow vivek

Determine Group Membership Of sai and vivek Users ##

id sai

id vivek

 

 

]]>
https://wiki.shopingserver.com/freebsd-add-user-wheel-group-command/feed/ 0