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

Tuesday, December 17, 2019

Python3 connect to Microsof SQL Server

1. sudo apt-get install python3-pip
2. pip3 install pyodbc
3. sudo apt-get install unixodbc-dev
4. follow the Microsoft's documentations (ref: https://docs.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server?view=sql-server-ver15 )
4.a
sudo su
curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - 4.b curl https://packages.microsoft.com/config/ubuntu/18.04/prod.list > /etc/apt/sources.list.d/mssql-release.list
4.c sudo apt-get update
4.d sudo apt-get install msodbcsql17


Test connection with this code:
import pyodbcconn = pyodbc.connect("Driver={ODBC Driver 17 for SQL Server};" "Server=SERVER_IP;" "Database=DB_NAME;" "uid=DB_USERNAME;pwd=DB_PASSWORD;")conn.close()


Some error maybe occured:
> ModuleNotFoundError: No module named 'pyodbc' --> solution: pip3 install pyodbc

> pyodbc.Error: ('01000', "[01000] [unixODBC][Driver Manager]Can't open lib 'ODBC Driver 17 for SQL Server' : file not found (0) (SQLDriverConnect)") --> solution: sudo apt-get install msodbcsql17

* My machine ubuntu 18.04


Monday, December 16, 2019

How to start ubuntu in command line interface

I want to set my ubuntu PC to command line interface. I don't want to start the desktop manager.

1. Edit /etc/default/grub

2. Find this section:
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
GRUB_CMDLINE_LINUX=""
3. change to:
GRUB_CMDLINE_LINUX_DEFAULT="text"
GRUB_CMDLINE_LINUX="3"

 4. run: sudo update-grub

5. Done. Every time we start the PC, it doesn't start the desktop manager automatically. If we want to start the desktop manager, run: sudo init 5


* My machine ubuntu 18.04

Thursday, November 5, 2015

Linux command low level format

Warning!!! This command will destroy all data on your drive

This command is use to check bad sector on a hard disk.

dd if=/dev/zero of=/dev/sda1 bs=1024



Now we know that is a trouble at first 1 GB

Monday, June 29, 2015

Replacing hard disk on xenserver / linux software RAID

mark as failed disk :

    mdadm --manage /dev/md0 --fail /dev/sdb1 

remove the disk :

    mdadm --manage /dev/md0 --remove /dev/sdb1


change the physical drive, copy the partition, create the exact same partitioning as on/dev/sda :
    sfdisk -d /dev/sda | sfdisk /dev/sdb


add the new drive
    mdadm --manage /dev/md0 --add /dev/sdb1


done, check the progress :
    cat /etc/mdstat



references:

Sunday, June 28, 2015

Xenserver / linux software raid

I want my Storage Repository (SR) run under the software RAID (RAID1). My xenserver version 6.5. XenServer 6.5 do not load soft raid kernel modules on boot. To load soft raid manually run :

modprobe raid1

To load the soft raid module on boot, we can follow this steps : http://discussions.citrix.com/topic/360943-software-raid-mdadm-on-xenserver-65-unexpected-failure/?p=1855912

To build the RAID array :
 
mknod /dev/md1 b 9 1

mdadm --create /dev/md1 --level=1 --raid-devices=2 /dev/sdb1 /dev/sdc1


/dev/sdb1
and
/dev/sdc1
is using linux raid autodetect as the partition type. Use fdisk to create those partition.

To check the RAID building process :
cat /proc/mdstat

reference :