Fixing ethernet network connection

Issue: When plugin in the Ethernet cable to computer would be not have a connection.
Reason: Ethernet driver is not installed, corrupted or out of date.
motherboard: Asus z97-AR
Intel CPU: Intel Core i7-4790K
operating system: Window 7

Fix:
Go to device manager.
Under ‘Other devices’ the Ethernet Controller has a warning icon

donwload then extract ‘Turbo LAN V1.04.01 for Windows 7/8/8.1 32bit & 64bit.’ driver from asus site

In device manager right click on ‘Ethernet Controller’ then ‘Update Driver Software’ then ‘browse my computer for driver software’
Browse to the extracted folder ‘Intel_LAN_Win7-8-8-1_VER191510’ then click next

Restart computer

Mount usb linux command line

# ways to find flash drive
dmesg | tail
sudo fdisk -l
lsusb
ls /dev/sd*

# make a directory to mount the usb
sudo mkdir /media/usb

# mount usb
# to grant permission to all when mounting add umask flag. For only root omit flag.
sudo mount -o umask=000 /dev/sda1 /media/usb

# if error mount: unknown filesystem type 'exfat'
sudo apt-get install exfat-fuse exfat-utils

# mount on every boot
# determine the partition/filesystem type for proc column
sudo blkid /dev/sda*

# edit file
sudo nano /etc/fstab

proc            /proc           proc    defaults          0       0
/dev/mmcblk0p1  /boot           vfat    defaults          0       2
/dev/mmcblk0p2  /               ext4    defaults,noatime  0       1
/dev/sda1       /media/usb      exfat   defaults
# a swapfile is not a swap partition, no line here
#   use  dphys-swapfile swap[on|off]  for that

# unmount
sudo umount /dev/sda1

# resources
How to Mount USB Drive on the Raspberry Pi

# tags
ntfs fat32 ext4

Samba Installation

Installing samba
$ sudo apt-get update
$ sudo apt-get install samba samba-common-bin
$ sudo nano /etc/samba/smb.conf

Configuration example

[global]
	netbios name = PI
	server string = The Pi File Center
	workgroup = WORKGROUP
	hosts allow =
	socket options = TCP_NODELAY IPTOS_LOWDELAY SO_RCVBUF=65536 SO_SNDBUF=65536
	remote announce =
	remote browse sync =

[homepi]
	path = /home/pi
	comment = No comment
	browsable = yes
	read only = no
	valid users =
	writable = yes
	guest ok = yes
	public = yes
	create mask = 0777
	directory mask = 0777
	force user = root
	force create mode = 0777
	force directory mode = 0777
	hosts allow =

# password protected
[fsq]
	comment = fsq
	path = /var/fsq
	browseable = Yes
	writeable = Yes
	only guest = no
	create mask = 0777
	directory mask = 0777
	public = no

Creating Samba User:
$ sudo smbpasswd -a pi
type password, press enter

Restart Samba Service:
$ sudo service smbd restart

Resources:

Sync server time

sudo service ntp stop
sudo ntpd -gq
sudo service ntp start

sources:
http://askubuntu.com/questions/254826/how-to-force-a-clock-update-using-ntp#answer-256004
https://www.digitalocean.com/community/tutorials/how-to-set-up-timezone-and-ntp-synchronization-on-ubuntu-14-04-quickstart
https://help.ubuntu.com/lts/serverguide/NTP.html

create git:// protocol

$ sudo apt-get install xinetd
$ sudo nano /etc/xinetd.d/git

# where highlighted if incorrect the service may not start

service git
{
        disable = no
        type            = UNLISTED
        port            = 9418
        socket_type     = stream
        wait            = no
        user            = nobody
        server          = /usr/bin/git
        server_args     = daemon --inetd --export-all --base-path=/var/fsq
        log_on_failure  += USERID
}

$ sudo /etc/init.d/xinetd restart
$ sudo /etc/init.d/xinetd status

# view the number of active services

active_services = 2
available_services = 2
descriptors_free = 1014
running_servers = 0
Logging service = enabled

# Now, all git repositories beneath /var/fsq will be available to anyone who asks.
# git clone git://[hostname]/my-repo.git
$ git clone git://baligena.com/my-repo.git

# sources
http://stackoverflow.com/questions/2538015/why-wont-git-daemon-serve-my-repository#answer-2539138

Installing Gitlab

Raspberry Pi

# login as root
$ sudo su

# follow gitlab installation for specified operating system
$ apt-get install gitlab-ce

# install web server
$ apt-get install nginx

# check log for errors. Port conflicts will be notified
$ cat /var/log/nginx/error.log

# change port if desired
$ nano /etc/nginx/sites-enabled/default

server {
        listen 81 default_server;
        listen [::]:81 default_server;

        # SSL configuration

# reconfigure gitlab
$ gitlab-ctl reconfigure

# change gitlab port to match nginx port
$ nano /opt/gitlab/embedded/service/gitlab-rails/config/gitlab.yml

  ## GitLab settings
  gitlab:
    ## Web server settings (note: host is the FQDN, do not include http://)
    host: gitlab.example.com
    port: 81
    https: false

.......

test:
  <<: *base
  gravatar:
    enabled: true
  gitlab:
    host: localhost
    port: 81

# change gitlab port to match nginx port
$ nano /etc/gitlab/gitlab.rb

## Url on which GitLab will be reachable.
## For more details on configuring external_url see:
## https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/doc/settings/configuration.md#configuring-the-external-url-for-gitlab
external_url 'http://gitlab.com.local:81/'

........

## Advanced settings
# unicorn['listen'] = '127.0.0.1'
# unicorn['port'] = 8081
# unicorn['socket'] = '/var/opt/gitlab/gitlab-rails/sockets/gitlab.socket'
# unicorn['pidfile'] = '/opt/gitlab/var/unicorn/unicorn.pid'

# reconfigure gitlab
$ gitlab-ctl reconfigure

# restart gitlab
$ sudo gitlab-ctl restart

# restart server
$ sudo reboot

# restart nginx
$ /etc/init.d/nginx restart

# check if listen to port
$ nmap -sS 192.168.0.14

# navigate to page. Be careful with browser cache (especially firefox)
http://192.168.0.14:81/

sources

http://www.thecfguy.com/blog/how-to-change-default-port-for-gitlab/

troubleshooting

# Reconfigure freezes at ruby_block[supervise_redis_sleep] action run
https://gitlab.com/gitlab-org/omnibus-gitlab/issues/430#note_1308607
http://stackoverflow.com/questions/22328923/impossible-to-install-gitlab-on-ubuntu-12-04#answer-25785708

when accessing the file tab there was an ajax request that was loading a 500 error page.
Looked into the log by running
$ sudo gitlab-ctl tail
and found this error message

Errno::ENOMEM (Cannot allocate memory - /opt/gitlab/embedded/bin/git):
.......

Found out that not enough memory was being allocate. May be because its a raspberry pi and it has limited memory.
The solution was to reduce unicorn worker processes thus reducing the memory consumption.
$ nano /etc/gitlab/gitlab.rb

##################
# GitLab Unicorn #
##################
## Tweak unicorn settings.

# unicorn['worker_timeout'] = 60
unicorn['worker_processes'] = 1

# Deleting branches and committing changes (edit file) using GitLab hangs it
error: proxyRoundTripper: POST " failed with: "EOF"

The corresponding unicorn worker waits for the git hook to complete and can not serve other requests during this time. The hook uses the GitLab web API to check if the user is allowed to execute the requested git operation. Because I had unicorn running with only one worker, no other worker was available to serve the API request, thus resulting in a deadlock.
https://gitlab.com/gitlab-org/gitlab-ce/issues/13947

$ nano /etc/gitlab/gitlab.rb

unicorn['worker_processes'] = 2

# remove GitLab
$ apt-get purge gitlab-ce

# remove nginx
$ apt-get purge nginx nginx-common nginx-full

Use apache server instead of nginx

followed these these steps

# Additional
Before running 'gitlab-ctl reconfigure', first run 'gitlab-ctl start postgresql', else there will be an error that postgresql is not running.

# enable apache modules
# http://stackoverflow.com/questions/25785903/gitlab-7-2-1-with-apache-server-instead-of-nginx#comment-65475363
# http://askubuntu.com/questions/64454/how-do-i-enable-the-mod-rewrite-apache-module-for-ubuntu-11-04#answer-64460
$ sudo a2enmod rewrite
$ sudo a2enmod proxy_http

If you get permission errors like "You don't have permission to access /assets/logo-white-0b53cd4ea06811d79b3acd486384e047.png on this server." then you need "Require all granted" in the <Location> in your apache vhost configuration file

# sources
http://stackoverflow.com/questions/25785903/gitlab-7-2-1-with-apache-server-instead-of-nginx#answer-25809733

Winscp notes

Setting the Putty path

View->Preferences->Applications->Putty/Terminal client path

for putty in programs folder

%PROGRAMFILES%\PuTTY\putty.exe -t -m "%TEMP%\putty.txt" !`cmd.exe /c echo cd "!/" ; /bin/bash -login > "%TEMP%\putty.txt"`

for putty in quicklaunch folder with ability to change the window size on open

"%appdata%\Microsoft\Internet Explorer\Quick Launch\putty.exe - Shortcut.lnk" -t -m "%TEMP%\putty.txt" !`cmd.exe /c echo cd "!/" ; /bin/bash -login > "%TEMP%\putty.txt"`

Setting Master Slave Mysql Replication

Configuration and Setup

On Master and Slave

edit /etc/mysql/my.cnf
# http://stackoverflow.com/questions/8605318/mysql-replication-slave-server-on-one-database#answer-8606998
# http://forums.mysql.com/read.php?35,369191,370003
# if you only want to replicate a specified database you need to add line to my.cnf
# !!! IMPORTANT in selecting the correct database name or replication will run without errors but nothing will be updated

replicate-do-db=dbname

# name reported to the master during slave registration

report_host=hostname

# give a server id

server-id=1323

# give bin log file location

log_bin=/var/log/mysql/mysql-bin.log

master server configuration file changes

# restart database

$ sudo /etc/init.d/mysql restart

# add the user the slave will use

mysql> CREATE USER 'repl'@'%' IDENTIFIED BY 'slavepassword'; 
mysql> GRANT REPLICATION SLAVE ON *.* TO 'repl'@'%';

On master

Dump mysql databases WITH compression

# all databases

$ mysqldump -uUSERNAME -pPASSWORD --all-databases --master-data | gzip > master_dbname_dump.sql.gz

# individual database

$ mysqldump -uUSERNAME -pPASSWORD --databases dbname --master-data | gzip > master_dbname_dump.sql.gz
Dump mysql databases WITHOUT compression

# individual database

$ mysqldump -uUSERNAME -pPASSWORD --databases dbname --master-data > master_dbname_dump.sql

# View Master information in the file dumped that will set the slave.

$ grep CHANGE *sql | head -1

# show slaves that are connected

mysql> SHOW SLAVE HOSTS;

# send file to slave server

$ scp master_dbname_dump.sql username@address.com:

On Slave

edit /etc/mysql/my.cnf
the slave server has a ‘read-only’ variable because that is its purpose. (Do not use this in master-master replication)
http://dba.stackexchange.com/questions/30128/should-a-mysql-replication-slave-be-set-to-read-only#answer-30129

read_only=ON

# The purpose of the import is because both the master and slave database must be the equal at point where the binlog started recording the replication.
# import the dump.

$ mysql -uroot < master_dbname_dump.sql

# Set the slave user

mysql> CHANGE MASTER TO MASTER_HOST='192.168.1.3', MASTER_USER='repl', MASTER_PASSWORD='slavepassword';

# Set a user that will only have an read ability.
# This is a safeguard and repetitive because setting the 'read-only' variable in my.cnf would prevent slave writing. Slave should not have writing permissions.

mysql> CREATE USER 'read_user'@'%' IDENTIFIED BY 'password';
mysql> GRANT SELECT ON *.* TO 'read_user'@'%';

# start slave

mysql> START SLAVE;
mysql> SHOW SLAVE STATUS \G 

Notes

The location of either the master or slave logs are located in /var/log/mysql.
Its a binary(.bin) file contain the queries ran to sync the slave.

# view what inside the bin, mysql view queries logs

$ mysqlbinlog /var/log/mysql/mysql-bin.000001

# show the bin name

mysql> SHOW MASTER STATUS;
mysql> SHOW BINARY LOGS;

# dba.stackexchange.com/questions/47046/why-do-the-mysql-bin-log-files-still-exist-after-a-purge-or-flush#answer-47048
# to reset all the queries and purge all binary logs. This will also do the same in the slave.

mysql> RESET MASTER;

# Sometimes there's errors in the 'slave status' you can skip queries but more error may lie ahead. This is not a permanent fix.
# https://www.howtoforge.com/how-to-repair-mysql-replication

mysql> SET GLOBAL SQL_SLAVE_SKIP_COUNTER = 1;

# the slave is working when you see this in the status

Slave_IO_Running: Yes
Slave_SQL_Running: Yes

# To detect a Master and Slave being out of sync
# Pick any table and run CHECKSUM TABLE against a table on the Master and the Slave's copy of the same table.
# If the values do not come back the same, then something is out-of-sync.

mysql> CHECKSUM TABLE dbname.table;

Reset everything

On master when changing the replicate user password there was an error on the slave. Then the slave needed to be reset.

On Master

$ mysqldump -uUSERNAME -pPASSWORD --databases dbname --master-data | gzip > master_dbname_dump.sql.gz

# will clear/delete/purge all bin log. Be careful this may cause issues if there's mulitple slave to this master.

mysql> RESET MASTER;

On Slave

mysql> STOP SLAVE;
mysql> RESET SLAVE ALL;
mysql> RESET MASTER;  # will clear/delete/purge all bin log.

if this error 'ERROR 1186 (HY000): Binlog closed, cannot RESET MASTER' is because 'log_bin' was not specified in mysql configuration file my.cnf

# import the dump

$ mysql -uroot < master_dbname_dump.sql
mysql> CHANGE MASTER TO MASTER_HOST='192.168.1.3', MASTER_USER='repl', MASTER_PASSWORD='slavepassword';
mysql> START SLAVE;
mysql> SHOW SLAVE STATUS;

the slave is working when you see in the status

Slave_IO_Running: Yes
Slave_SQL_Running: Yes

Master to master replication

# simply make master a slave as well.
# https://www.digitalocean.com/community/tutorials/how-to-set-up-mysql-master-master-replication

mysql> CHANGE MASTER TO MASTER_HOST='hostname', MASTER_USER='repl', MASTER_PASSWORD='slavepassword';

# values need to be equal where the colors match
master-master relationship

Miscellaneous

# http://stackoverflow.com/questions/2366018/how-to-re-sync-the-mysql-db-if-master-and-slave-have-different-database-incase-o#answer-3229580
# an option to reset the slave position

mysql> CHANGE MASTER TO MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS=98;