Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts

Tuesday, May 12, 2015

GlusterFS Configuration

Assume node1 is: 192.168.33.10
Assume node2 is: 192.168.33.11

Sources:
https://www.digitalocean.com/community/tutorials/how-to-create-a-redundant-storage-pool-using-glusterfs-on-ubuntu-servers
http://www.jamescoyle.net/how-to/457-glusterfs-firewall-rules


On BOTH nodes

# set hosts file entry (or configure DNS)
vim /etc/hosts
192.168.33.10 gluster1
192.168.33.11 gluster2

# On Ubuntu: install requirements 
sudo add-apt-repository ppa:semiosis/ubuntu-glusterfs-3.5
sudo apt-get update
sudo apt-get install glusterfs-server
sudo apt-get install glusterfs-client

# On Centos: install requirements
wget -P /etc/yum.repos.d http://download.gluster.org/pub/gluster/glusterfs/LATEST/RHEL/glusterfs-epel.repo
yum install glusterfs-server
yum install glusterfs-client

# make storage location for gluster data
sudo mkdir /gluster-storage

# make a mountpoint
sudo mkdir /mnt/media/

ON GLUSTER 1

# connect node 1 and node 2
sudo gluster peer probe gluster2
sudo gluster peer status

# create a Gluster replica volume
sudo gluster volume create volume1 replica 2 transport tcp \
      gluster1:/gluster-storage \
      gluster2:/gluster-storage force

# list volumes
sudo gluster volume list

# start the gluster volume
sudo gluster volume start volume1

# mount the volume
sudo mount -t glusterfs gluster1:/volume1 /mnt/media/

# only allow given ips
sudo gluster volume set volume1 auth.allow gluster1,gluster2

sudo gluster volume info
sudo gluster volume profile volume1 start
sudo gluster volume profile volume1 info
sudo gluster volume status

# stop the volume
sudo gluster volume stop volume1

FSTAB Entries

** ON Gluster 1
gluster1:/volume1 /mnt/media/ glusterfs defaults,_netdev,backupvolfile-server=gluster2 0 0

** ON Gluster 2
gluster2:/volume1 /mnt/media/ glusterfs defaults,_netdev,backupvolfile-server=gluster1 0 0

systemd quickstart


Source:
https://fedoraproject.org/wiki/SysVinit_to_Systemd_Cheatsheet
https://wiki.ubuntu.com/SystemdForUpstartUsers
http://wiki.nginx.org/FedoraSystemdServiceFile

Start/stop/reload a service:
service foo start   # or
systemctl start foo

service foo stop   # or 
systemctl stop foo

service foo restart   # or 
systemctl restart foo

Reload a service using reload signal:
service foo reload

See if service is running:
service foo status   # or 
systemctl status foo

See tree listing of all services:
systemctl status

See job log: 
sudo journalctl -u foo -f

Enable a service (to start on boot):
systemctl enable foo

Disable a service:
systemctl disable foo

Service Definition Directory:
/lib/systemd/system/

Example Nginx Service: /lib/systemd/system/nginx.service 
[Unit]
Description=The nginx HTTP and reverse proxy server
After=syslog.target network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t
ExecStart=/usr/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target


Links:
https://scottlinux.com/2014/12/08/how-to-create-a-systemd-service-in-linux-centos-7/

Saturday, May 09, 2015

Simple ClamAV Usage


Source: Nice Resource
http://askubuntu.com/questions/250290/how-do-i-scan-for-viruses-with-clamav

Install:
sudo apt-get install clamav

Refresh virus definition database:
sudo freshclam

Scan all files on computer showing each
clamscan -r /

Only display infected files and ring bell
clamscan -r --bell -i /

Scan all files and move them to infected dir
clamscan -r --move=/home/USER/VIRUS /home/USER

Scan all files and remove bad ones
clamscan -r --remove /home/USER

Monday, April 15, 2013

iptables

Listing Rules
# Rules are evaluated from top to bottom
# list the iptable rules
iptables -list
iptables -L

# list the rules with high verbosity 
iptables -L -v

# list the rules with high verbosity and line numbers
iptables -L -v --line-numbers

# list the rules with high verbosity and line numbers and show the raw IP addresses and ports
iptables -L -v --line-numbers -n

# list rules as a list of rules in the conf file.
iptables -S

Adding/Editing/Removing Rules 
# -I Option: Insert a rule at a specific point (to be the 4th rule). 
iptables -I INPUT 4 -p tcp  --dport 3306 -m state --state NEW,ESTABLISHED -j ACCEPT

# -A Option: Append a rule to the end of the rule list
iptables -A INPUT -p tcp  --dport 3306 -m state --state NEW,ESTABLISHED -j ACCEPT

# -D Option: Delete the INPUT rule at line 4
iptables -D INPUT 4

# -R Option: Replace a rule at 4th line
iptables -R INPUT 4 -p tcp  --dport 3306 -m state --state NEW,ESTABLISHED -j ACCEPT

Change the iptables policy

# Change the policy to drop all traffic if no rules matched.  
# Important: You'll want to setup an ssh rule before doing this
iptables -P INPUT DROP

# Change the policy to accept all traffic unless specific rules are matched
iptables -P INPUT ACCEPT

IPTables modules

# Modules are loaded using the -m flag
# Some common examples include: "-m tcp", "-m mac", and "-m state"
# Many are loaded by default. For example, if you specify "-p tcp --dport 22", I think it automatically loads the tcp module and assumes "-m tcp".

# List Loaded IPTables modules
cat /proc/net/ip_tables_matches

Jump option parameters (-j option) "jump to the specified target"
  ACCEPT - Accept the packet and stop processing rules
  REJECT - reject the packet and notify sender
  DROP - silently drop the packet and stop processing rules
  LOG - log the packet and continue processing

State option parameters (--cstate and --state options) 
   NEW - new connection that has not been seen
   RELATED - new connection but related to another connection
   ESTABLISHED - connection is already established
   INVALID - traffic couldn't be identified

Save the firewall rules on a RedHat system
/sbin/service iptables save

Clear rule statistics counters
iptables -Z

# good howto for Ubuntu
https://help.ubuntu.com/community/IptablesHowTo

# A good howto for Centos and DROP policy
http://wiki.centos.org/HowTos/Network/IPTables

Monday, March 25, 2013

Synergy Linux Setup

Install
sudo aptitude install synergy

Given the following computers:
computerA  (Synergy server)
computerB  (Synergy client)

And given: 
computerA is the name returned by the 'hostname' command on the server; ip is 192.168.0.102
computerB is an alias (setup in synergy.conf) to 192.168.0.101


Edit /etc/synergy.conf on the Synergy Server
section: screens
    computerA:
    computerB:
end

# we might not want to go through the effort of setting up DNS for computerB, so we can alias here instead.
section: aliases
    computerB:
        192.168.0.101
end

section: links
    computerA:
       right = computerB
    computerB:
       left = computerA
end

On the server, run the following: 
 synergys -f --config /etc/synergy.conf

On the client, run the following: 
synergyc -f 192.168.0.102


Friday, February 25, 2011

Find Open Ports

Find open ports on local Linux machine:
sudo netstat -lnptu

http://www.techrepublic.com/blog/security/list-open-ports-and-listening-services/443

Monday, August 30, 2010

Change Default Linux Shell

Needs sudo privileges: to change the default shell:
chsh

http://forums.devshed.com/unix-help-35/how-to-change-default-shell-52749.html

Saturday, August 09, 2008

Sound Card Info

Check what ALSA soundcards are available on a Linux system:
cat /proc/asound/cards

Check what features each ALSA card has:
cat /proc/asound/devices
# note that the left number column corresponds to a soundcard in the above list

List sound cards detected
aplay -l

Set the default sound card:
# Enter this into /etc/asound.conf or .asoundrc

pcm.!default {
type hw
card 1
}
ctl.!default {
type hw
card 1
}

Using alsamixer to select which sound card to affect:
alsamixer -c <sound_card_number_from_proc>
Using mplayer with a non-default sound device
mplayer -ao oss:/dev/dsp *.mp3 # device 0
mplayer -ao alsa:device=hw=0.0 *.mp3 # device 0
mplayer -ao oss:/dev/dsp1 *.mp3 # device 1
mplayer -ao alsa:device=how=1.0 *.mp3 # device 1


http://seehuhn.de/pages/alsa
http://ubuntuforums.org/showthread.php?t=747054