zondag 26 augustus 2018

install .net core on ubuntu

sudo sh -c 'echo "deb [arch=amd64] https://apt-mo.trafficmanager.net/repos/dotnet-release/ xenial main" > /etc/apt/sources.list.d/dotnetdev.list' 
sudo apt-key adv --keyserver apt-mo.trafficmanager.net --recv-keys 417A0893 
sudo apt-get update 
sudo apt-get install dotnet-dev-1.0.0-preview2-003131

cd ~/ 
mkdir SqlServerSample 
cd SqlServerSample 
dotnet new

add lines to .json file
"dependencies": { 
"System.Data.SqlClient": "4.3.0"

edit program.cs
using System;
using System.Text;
using System.Data.SqlClient;
namespace SqlServerSample
{
class Program
{
static void Main(string[] args)
{
try
{
// Build connection string
SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();
builder.DataSource = "localhost"; // update me
builder.UserID = "sa"; // update me
builder.Password = "your_password"; // update me
builder.InitialCatalog = "master";
// Connect to SQL
Console.Write("Connecting to SQL Server ... ");
using (SqlConnection connection = new SqlConnection(builder.ConnectionString))
{
connection.Open();
Console.WriteLine("Done.");
}
}
catch (SqlException e)
{
Console.WriteLine(e.ToString());
}
Console.WriteLine("All done. Press any key to finish...");
Console.ReadKey(true);
}
}
}

dotnet restore
dotnet run

Centos samba integration AD

the ad server: WIndows Server 2012r2
The linux server : centos 7

nano /etc/samba/smb.conf
[global]
workgroup = NETBIOSNAME 
realm = FQDN.DOMAIN.COM
security = ads
idmap uid = 100000-200000
idmap gid = 100000-200000
template homedir = /home/%U
template shell = /bin/bash
winbind use default domain = yes
winbind offline logon = false
winbind enum users = yes
winbind enum groups = yes
[userdata]
path = /user-data
browseable = yes
writeable = yes
valid users = +software
Create Sharemkdir /software
chcon -t samba_share_t /software
Enable run serviceschkconfig smb on
chkconfig nmb on
chkconfig winbind on
Firewall rulesfirewall-cmd --zone=public --add-port=139/tcp --permanent
firewall-cmd --zone=public --add-port=445/tcp --permanent
firewall-cmd --reload
Edit Kerbos
nano /etc/krb.conf
[logging] 
default = FILE:/var/log/krb5libs.log
kdc = FILE:/var/log/krb5kdc.log
admin_server = FILE:/var/log/kadmind.log
[libdefaults]
default_realm = FQDN.DOMAIN.COM
dns_lookup_realm = false
dns_lookup_kdc = false
ticket_lifetime = 24h
renew_lifetime = 7d
forwardable = true
[realms]
BIOPACK.BE = {
kdc = dcf.biopack.be
admin_server = dcf.biopack.be
}
[domain_realm]
.domain.com = FQDN.DOMAIN.COM
domain.com= FQDN.DOMAIN.COM
restart samba
join your domain : net join ads -u administrator@domain.com -S dc.domain.com
Edit ns switchnano etc/nsswitch.conf
and add :
passwd: files winbind
shadow: files winbind
group: files winbind
service winbind restart
test: wbinfo -u
getent users
chown roont:software/user-data

Reset MYSQL root password on Centos


Stop MYSQL
systemctl stop mysqld

Set mysql env options
systemctl set-enviroment MYSQLD_OPTS ="--skip-grant-tables"

Start MYSQL
systemctl start mysqld

Update password using query
mysql -u root
UPDATE mysql.user SET authentication_string = PASSWORD('ENTER NEW PASSWORD') WHERE User='root' AND host = 'localhost';
FLUSH PRIVILEGES;
QUIT

Stop mysqld
systemctl stop mysqld

Unset enviroment
systemctl unset-enviroment MYSQLD_OPTS
systemctl start mysqld


pnp4nagios installation

Install PNP4NAGIOS

System: Centos7
Installed: APACHE,NAGIOS,PHP

Base knowledge: You have to know how to install php and manage your way around the centos file system.

Download packages:
my download location of default is /opt

wget https://downloads.sourceforge.net/project/pnp4nagios/PNP-0.6/pnp4nagios-0.6.26.tar.gz
./configure
make
make all
make fullinstall

chkconfig --add npcd && chkconfig --level 35 npcd on
systemctl reload httpd

mv /usr/local/pnp4nagios/share/install.php /usr/local/pnp4nagios/share/install.php-ori

edit nagios.cfg
nano /usr/local/nagios/etc/nagios.cfg

add / edit:
# Bulk / NPCD mode
process_performance_data=1
service_perfdata_file=/usr/local/pnp4nagios/var/service-perfdata
service_perfdata_file_template=DATATYPE::SERVICEPERFDATA\tTIMET::$TIMET$\tHOSTNAME::$HOSTNAME$\tSERVICEDESC::$SERVICEDESC$\tSERVICEPERFDATA::$SERVICEPERFDATA$\tSERVICECH$
service_perfdata_file_mode=a
service_perfdata_file_processing_interval=15
service_perfdata_file_processing_command=process-service-perfdata-filehost_perfdata_file=/usr/local/pnp4nagios/var/host-perfdata
host_perfdata_file_template=DATATYPE::HOSTPERFDATA\tTIMET::$TIMET$\tHOSTNAME::$HOSTNAME$\tHOSTPERFDATA::$HOSTPERFDATA$\tHOSTCHECKCOMMAND::$HOSTCHECKCOMMAND$\tHOSTSTATE::$
host_perfdata_file_mode=a
host_perfdata_file_processing_interval=15
host_perfdata_file_processing_command=process-host-perfdata-file
Edit commands.cfg
# 'process-host-perfdata' command definition
define command{
command_name process-host-perfdata
command_line /usr/bin/printf "%b" "$LASTHOSTCHECK$\t$HOSTNAME$\t$HOSTSTATE$\t$HOSTATTEMPT$\t$HOSTSTATETYPE$\t$HOSTEXECUTIONTIME$\t$HOSTOUTPUT$\t$HOSTPERFDATA$$
}
# 'process-service-perfdata' command definition
define command{
command_name process-service-perfdata
command_line /usr/bin/printf "%b" "$LASTSERVICECHECK$\t$HOSTNAME$\t$SERVICEDESC$\t$SERVICESTATE$\t$SERVICEATTEMPT$\t$SERVICESTATETYPE$\t$SERVICEEXECUTIONTIME$$
}
define command{
command_name process-service-perfdata-file
command_line /bin/mv /usr/local/pnp4nagios/var/service-perfdata /usr/local/pnp4nagios/var/spool/service-perfdata.$TIMET$
}
define command{
command_name process-host-perfdata-file
command_line /bin/mv /usr/local/pnp4nagios/var/host-perfdata /usr/local/pnp4nagios/var/spool/host-perfdata.$TIMET$
}
Edit templates
define host {
name host-pnp
action_url /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=_HOST_' class='tips' rel='/pnp4nagios/index.php/popup?host=$HOSTNAME$&srv=_HOST_
register 0
}
define service {
name srv-pnp
action_url /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=$SERVICEDESC$' class='tips' rel='/pnp4nagios/index.php/popup?host=$HOSTNAME$&srv=$SERVICEDESC$
register 0
}
edit an example host
the host-pnp is the host directive, the srv-pnp is the service directive.
define host{
use linux-server,host-pnp}
define service {
use linux-server,srv-pnp
}
restart services:
systemctl restart npcd
systemctl restart httpd
systemctl restart nagios
after 10 - 20 minutes host pnp will start showing results.

installation nagios ql

Nagios ql is a management tool for nagios this will make configuation very easy.
base knowledge : know to handle the centos filesystem, installation of php mysql and apache.

you need to have the following installed:

Nagios,PHP,httpd and MYSQL

Verify php version
check if your php version is at least 5.4
php -v

Update php
yum-config-manager --enable remi-php70
yum install php php-mcrypt php-cli php-gd php-curl php-mysql php-ldap php-zip php-fileinfoyum install php-pear gcc curl-devel pcre-devel php-devel php zlib-devel libssh2 libssh2-devel mariadb-server php-mysql
pecl install ssh2
pear install HTML_Template_IT

get nagiosql
since the orignal repo is taken offline we will clone a repo from gitlab for this action is git required (yum install git or yum group install "Development Tools")
git clone https://gitlab.com/wizonet/nagiosql.git
add ssh2.so to php and edit time zone
nano /etc/php.ini
extension=ssh2.so
date.timezone = Europe/Brussels
Copy nagiosqlcp -vprf nagiosql /usr/local/nagios/share

Acces rights and create directorys
cd /etc/nagiosql
chown -R nagios.apache /etc/nagiosql 
mkdir -p /usr/local/nagios/etc/import 
systemctl restart mariadb 
systemctl enable mariadb 
systemctl restart httpd 
systemctl enable httpd

Configure MYSQL
mysql -u root -p
CREATE DATABASE nagios;

exit;

Web install
go to http://YOUR_IP/nagios/nagiosql

Set post install rights
 apache.nagios /etc/nagiosql;chown apache.nagios /etc/nagiosql/hosts;chown apache.nagios /etc/nagiosql/services;chown apache.nagios /etc/nagiosql/backup;chown apache.nagios /etc/nagiosql/backup/hosts;chown apache.nagios /etc/nagiosql/backup/services;chown nagios.apache /usr/local/nagios/var/rw/nagios.cmd;chown nagios.apache /usr/local/nagios/etc/nagios.cfg;chown nagios.apache /usr/local/nagios/etc/cgi.cfg; 
chown nagios.apache /usr/local/nagios/etc/resource.cfg;chown nagios.apache /usr/local/nagios/var/spool/checkresults;chown nagios:apache /usr/local/nagios/bin/nagios;chmod 6755 /etc/nagiosql;chmod 6755 /etc/nagiosql/hosts;chmod 6755 /etc/nagiosql/services;chmod 6755 /etc/nagiosql/backup;chmod 6755 /etc/nagiosql/backup/hosts;chmod 6755 /etc/nagiosql/backup/services;chmod 660 /usr/local/nagios/var/rw/nagios.cmd; 
chmod 775 /usr/local/nagios/etc/;chmod 664 /usr/local/nagios/etc/nagios.cfg;chmod 664 /usr/local/nagios/etc/cgi.cfg;chmod 750 /usr/local/nagios/bin/nagios;chmod g+x /usr/local/nagios/var/rw/;chown nagios.apache /usr/local/nagios/bin/nagios;chgrp apache /usr/local/nagios/etc/;chgrp apache /usr/local/nagios/etc/nagios.cfg;chgrp apache /usr/local/nagios/etc/cgi.cfg;chmod 775 /usr/local/nagios/etc/ 
touch /usr/local/nagios/var/nagios.lock 
chmod 664 /usr/local/nagios/var/nagios.lock 
chown nagios:nagios /usr/local/nagios/var/nagios.lock

NAGIOSQL config:
goto Administratorion -> Config targets -> modify --> config targets
adjust:
base directory = /usr/local/nagios/etc
import dir = /usr/local/nagios/etc/import
cmd file = /usr/local/nagios/var/rw/nagios.cmd
bin file = /usr/local/nagios/bin/nagios
nagios process file = /usr/local/nagios/var/nagios.local
config file = /usr/local/nagios/etc/nagios.cfg
now go to Tools--> nagios config
uncomment previous settins like (commands.cfg,contacts.cfg...)
add one line : cfg_dir=/etc/nagiosql
restart the services:
Tools-->Nagios config and click all the buttons. Restarting the service by ssh is faster (systemctl restart nagios)
Tools--> Data import --> and import your command like contacts,commands and other config files.
Note if you have exisiting host config files do not import them recreate them.