Wednesday, October 18, 2017
Using PDO MSSQL in PHP
This tutorial will guide you how to use PDO in order to access Microsoft SQL Server.
Step 1: Install Microsoft ODBC 11 driver for MSSQL
Link download :
https://www.microsoft.com/en-us/download/details.aspx?id=36434
Step 2: Download Microsoft Drivers for PHP for SQL Server
Link download :
https://www.microsoft.com/en-us/download/details.aspx?id=20098&e6b34bbe-475b-1abd-2c51-b5034bcdd6d2=True
Note: Download version 4.0 if you use PHP 7
Step 3: Config file PHP.ini
Note: if you use WAMP Server, you need to edit file php.ini inside the bin directory of apache
Add these lines into the php.ini file :
extension=php_pdo_sqlsrv_7_nts_x64.dll
extension=php_pdo_sqlsrv_7_ts_x64.dll
Step 4: Ensure Driver is install successfully
Can check via phpinfo() function, and search for sqlsrv services.
Step 5: Example for using with Slim Framework
// Declare config
$app = new \Slim\App($config);
$container = $app->getContainer();
// Config Database
$container['db'] = function () {
$odbc="odbc:Driver={SQL Server};Server=localhost;Database=OracleDB;";
return new PDO( $odbc , "username" , "password");
};
// Using
$query = "SELECT * FROM Users WHERE LoginName = 'lieubv' ";
$conn = $this->c->db;
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$stmt = $conn->query( $query );
echo "<pre>";
while ($row = $stmt->fetch(PDO::FETCH_ASSOC))
{
print_r($row);
}
echo "</pre>";
die();
Happy Coding!
Friday, October 13, 2017
VMware_lession_9
Date: 2017-10-13
Bài tập:
1. Dùng user AD login SSH / ESXi (Adduser / Group / Role)
2. Dùng user AD cài đặt SSO trên vCenter.
Hiện tại mới chỉ dùng được Administration với nhóm @vsphere.local
3. Cài đặt
DRS
HA
EVC
để cài EVC, thường gặp lỗi về chip, cần lấy cấu hình flag của một cluster đã bật EVC trước đó.
rồi add lại các con host.
Wednesday, October 11, 2017
VMware_lession_8
Date : 2017 - 10 - 11
Resouces Pool
Chú ý thông số: CPU Shares.
chỉ số này càng cao thì mức ưu tiên cao hơn, và được phép lấy tài nguyên của máy có mức ưu tiên thấp hơn. Và mức mà máy ưu tiên cao lấy ra phụ thuộc tỉ lệ CPU shares của 2 máy.
Mục tiêu tạo Cluster
là tạo một Resource pool chứa tối đa cho 64 host
Ngay sau đó các tính năng sau được bật :
DRS : Distributed Resource Schedule (Admission Control : 75% used, 25% empty)
Có chức năng phân phối lại tài nguyên, cho nên nó phải tự tính toán.
Mức độ tự động : Khi bật tính năng này, chọn Mức tự động là Fully Automated.
Mức độ di chuyển : có 3 cấp độ.
=> Để các chế độ cài đặt là mặc định.
HA : (Start / Stop VM)
Turn on HA
Turn on Proactive HA, thì khi có sự cố nó sẽ tiến hành chạy lại. (Khi làm cluster thì Proactive sẽ ở chế độ Manual).
Chú ý: các Guest VM mà ko có heartbeating thì không làm HA được.
để bật heartbeating thì cần cài VM Install Tools
Failure Response => chọn Disable
Proactive HA Failures and Response => Automation Level:
Adminssion Control:
=> Define host failover capacity by: (dùng cho trường hợp nhận lỗi).
Chọn Cluster resource percentage
Chọn check box Override, cpu 25%, ram 25%
=> Performance degradaton VMs tolerate: giữ nguyên100%
Heartbeat Datastores :
Cần đấu SAN mới nhìn thấy các thành phần để cấu hình.
EVC : Enhanced VMotion Compatibility
vSAN :
Ở tab Summary của Cluster, vào tab Vsphere DRS và xem thước đo.
+ lệch bên phải : thừa cpu, ram
+ lệch bên trái: khả năng thiếu cpu, ram
Install MongoDB on CentOS 7
How to install MongoDB - Enterprise on CentOS
1. Configure repository.
Create an
/etc/yum.repos.d/mongodb-enterprise.repo file so that you can install MongoDB enterprise directly, using yum.[mongodb-enterprise] name=MongoDB Enterprise Repository baseurl=https://repo.mongodb.com/yum/redhat/$releasever/mongodb-enterprise/3.4/$basearch/ gpgcheck=1 enabled=1 gpgkey=https://www.mongodb.org/static/pgp/server-3.4.asc
2. Install the MongoDB Enterprise packages and associated tools.
To install the latest stable version of MongoDB Enterprise, issue the following command:
sudo yum install -y mongodb-enterprise
3. Config SELinux
IMPORTANT
If you are using SELinux, you must configure SELinux to allow MongoDB to start on Red Hat Linux-based systems (Red Hat Enterprise Linux or CentOS Linux).
a
To configure SELinux, administrators have three options:
- If SELinux is in
enforcingmode, enable access to the relevant ports that the MongoDB deployment will use (e.g.27017). See Default MongoDB Port for more information on MongoDB’s default ports. For default settings, this can be accomplished by runningsemanage port -a -t mongod_port_t -p tcp 27017 - Disable SELinux by setting the
SELINUXsetting todisabledin/etc/selinux/config.SELINUX=disabled
You must reboot the system for the changes to take effect. - Set SELinux to
permissivemode in/etc/selinux/configby setting theSELINUXsetting topermissive.SELINUX=permissive
You must reboot the system for the changes to take effect.You can instead usesetenforceto change topermissivemode.setenforcedoes not require a reboot but is not persistent.
Alternatively, you can choose not to install the SELinux packages when you are installing your Linux operating system, or choose to remove the relevant packages. This option is the most invasive and is not recommended.
4. Config Database Options
4.1 Data Directories and Permissions
WARNING
On RHEL 7.0, if you change the data path, the default SELinux policies will prevent
mongod from having write access on the new data path if you do not change the security context.
The MongoDB instance stores its data files in
/var/lib/mongo and its log files in /var/log/mongodb by default, and runs using the mongod user account. You can specify alternate log and data file directories in /etc/mongod.conf. See systemLog.path and storage.dbPath for additional information.
If you change the user that runs the MongoDB process, you must modify the access control rights to the
/var/lib/mongo and /var/log/mongodb directories to give this user access to these directories.ulimit
Most Unix-like operating systems limit the system resources that a session may use. These limits may negatively impact MongoDB operation. See UNIX ulimit Settings for more information.
4.2 Database Directory
Note: if you already start the MongoDB before setting this, you need to change the storagePath to a new directory and do this step again.
If you want to store database into individual directory, you should put this key and value in to the config file in /etc/mongod.conf :
directoryPerDB : true
Then you start the MongoDB for first time.
5. Run the database
sudo systemctl restart mongod
6. Verifying Startup
Because a database-driven application cannot function without a database, we’ll make sure that the MongoDB daemon,
mongod, will start with the system.
Use the
systemctl utility to check its startup status:
- systemctl is-enabled mongod; echo $?
An output of zero confirms an enabled daemon, which we want. A one, however, confirms a disabled daemon that will not start.
Output
. . .
enabled
0
In the event of a disabled daemon, use the
systemctl utility to enable it:
- sudo systemctl enable mongod
We now have a running instance of MongoDB that will automatically start following a system reboot.
*****************
Finish!
Enjoy your DB !
Monday, October 9, 2017
VMware_lession_7
Bài tập:
Cho biết y/c hệ thống có 5 VMs.
Cấu hình cơ bản 1 VM: 40 cores, 16G RAM, 2TB
- Hỏi : dựa vào công thức nào để tính ra sẽ có bao nhiêu máy vật lý ?
Lời giải:
Phương pháp 1:
{ Socket x Core x HT } x Speed x 1000 (Mhz)
<-> {40} x 2.5 * 1000 = 100.000 Mhz
Phương pháp 2:
Chú ý tỉ lệ 75 / 25
5 x (40 vCPU) x 2.5 x 1000 x 125% = 625.000 Mhz
//
Access Control List: có một vài nhóm như sau
1. Local OS : root ( chỉ làm việc trên Appliance ở cổng 5480)
2. vsphere.local : đây là domain của vCenter -> Adminstrator@vsphere.local
3. AD-DC : đây là domain của vclass.local
Có 3 pp SSO
1. Window Authen
Nhược điểm: vCenter chỉ làm được 1 lần phương pháp này, vì nó thì không join dc > 1 domain.
2. Khai báo LDAP
Lúc này có thể join được nhiều con AD.
Chú ý đặt đúng tên.
Ví dụ: DC=vclass, DC=local
3. OpenLDAP
Chỉ dùng cho Linux, Không dùng được cho Window
Resource Management
Cluster : 2 loai cpu + ram va storage
Nên lưu trữ file .vswp cùng với file máy ảo.
SMP: SINGLE MACHINE PROCESSOR
Cho biết y/c hệ thống có 5 VMs.
Cấu hình cơ bản 1 VM: 40 cores, 16G RAM, 2TB
- Hỏi : dựa vào công thức nào để tính ra sẽ có bao nhiêu máy vật lý ?
Lời giải:
Phương pháp 1:
{ Socket x Core x HT } x Speed x 1000 (Mhz)
<-> {40} x 2.5 * 1000 = 100.000 Mhz
Phương pháp 2:
Chú ý tỉ lệ 75 / 25
5 x (40 vCPU) x 2.5 x 1000 x 125% = 625.000 Mhz
//
Access Control List: có một vài nhóm như sau
1. Local OS : root ( chỉ làm việc trên Appliance ở cổng 5480)
2. vsphere.local : đây là domain của vCenter -> Adminstrator@vsphere.local
3. AD-DC : đây là domain của vclass.local
Có 3 pp SSO
1. Window Authen
Nhược điểm: vCenter chỉ làm được 1 lần phương pháp này, vì nó thì không join dc > 1 domain.
2. Khai báo LDAP
Lúc này có thể join được nhiều con AD.
Chú ý đặt đúng tên.
Ví dụ: DC=vclass, DC=local
3. OpenLDAP
Chỉ dùng cho Linux, Không dùng được cho Window
Resource Management
Cluster : 2 loai cpu + ram va storage
Nên lưu trữ file .vswp cùng với file máy ảo.
SMP: SINGLE MACHINE PROCESSOR
Saturday, October 7, 2017
How to install Nominatim on CentOS 7
Nominatim Installation
Update date: 2017/03/29
Contents
1.
Các thuật ngữ
-
OSM : Open Street Map
2.
Giới thiệu
-
Đây là công cụ dùng truy vấn dữ liệu của OSM, do
không có giới hạn về số request và làm việc trên database riêng nên nó phù hợp
để thay thế công cụ Geocoder của Google Map cho ứng dụng định vị
-
Nominatim cung cấp 2 API quan trọng:
o
Tìm kiếm tọa độ từ địa chỉ
VD:
o
Tìm kiếm địa chỉ từ tọa độ
VD:
-
2 web service này là cơ sở khá quan trọng để xử
lý vấn đề địa chỉ tồn đọng trong bài toán định vị của Việt Toàn Cầu
3.
Cài đặt Nominatim
3.1
Môi trường
-
Môi trường cài đặt chỉ dùng phần dữ liệu của
Vietnam. Phần dữ liệu của toàn trái đất khá nặng và yêu cầu cao hơn về phần cứng
-
Việc cài đặt sử dụng VPS cho bản đồ Vietnam với
môi trường phần cứng
o
CPU 4 core
o
Ram 4G
o
80G SSD
-
Hệ điều hành :
o
Centos 7.0.1406
o
Linux 3.10.0-123.4.2.el7.x86_64
o
Kiến trúc: x86-64
3.2
Cài các phần bổ trợ
3.2.1
Các thư viện
-
Các thư viện yêu cầu bởi Nominatim
-
yum install epel-release
-
yum install postgresql-server postgresql-contrib
postgresql-devel postgis postgis-utils
-
yum install git make automake gcc gcc-c++
libtool policycoreutils-python
-
yum install php-pgsql php php-pear php-pear-DB
libpqxx-devel proj-epsg
-
yum install bzip2-devel proj-devel geos-devel
libxml2-devel boost-devel expat-devel zlib-devel
-
yum install bzip2
-
yum install wget
-
yum install php-fpm
3.2.2
Cài Java
-
Cài đặt:
sudo yum install java-1.7.0-openjdk
3.2.3
Cài Apache
-
Cài PHP 5 ( PHP 7 sẽ không chạy )
-
Cần thiết lập timezone cho php.ini
(/etc/php.ini)
date.timezone =
"Asia/Ho_Chi_Minh"
-
Cài đặt Apache:
o
sudo yum install httpd
-
Cấu hình httpd.cnf
-
Mở tường lửa cho Apache
o
sudo firewall-cmd --permanent --add-port=80/tcp
o
sudo firewall-cmd --permanent --add-port=443/tcp
o
sudo firewall-cmd –reload
-
Thiết lập service cho apache
o
sudo systemctl start httpd
o
sudo systemctl enable httpd
o
sudo systemctl status httpd
3.3
Cài đặt database
3.3.1
Cấu hình Postgres
-
Khi thực hiện 3.2.1 ta sẽ cài đặt sẵn Postgres bản
9.2. Ở phần này ta chỉ thực hiện cấu hình cần thiết
-
Thiết lập postgres chạy dạng service
o
postgresql-setup initdb
o
systemctl enable postgresql
o
systemctl start postgresql
-
Cấu hình Postgres file “/var/lib/pgsql/data/postgresql.conf”
o
Đây là các thông số được đề xuất
shared_buffers (2GB)
maintenance_work_mem (10GB)
work_mem (50MB)
effective_cache_size (24GB)
synchronous_commit = off
checkpoint_segments = 100 (only
for PostgreSQL <= 9.4)
checkpoint_timeout = 10min
checkpoint_completion_target = 0.9
o
Tuy nhiên do hạn chế phần cứng RAM VPS ta cấu
hình như sau
shared_buffers (2GB)
maintenance_work_mem (3GB)
work_mem (50MB)
effective_cache_size (3GB)
synchronous_commit = off
checkpoint_segments = 100 (only
for PostgreSQL <= 9.4)
checkpoint_timeout = 10min
checkpoint_completion_target = 0.9
o
Cấu hình sau chỉ sử dụng khi import dữ liệu OSM
sau khi import xong cần trả lại
fsync = off
full_page_writes =
off
-
Khởi động lại postgres
systemctl restart postgresql
3.3.2
Tạo người dùng Postgres
-
Cần tạo ra các người dùng sau
o
nominatim
o
apache
-
Lệnh thực hiện ( reference create user : https://www.postgresql.org/docs/8.4/static/app-createuser.html
)
o
sudo su - postgres
o
createuser -sdRe nominatim
o
createuser -sdRe root
o
createuser -SDRe apache
3.4
Cài Nominatim
3.4.1
Tạo người dùng OS
-
Cần tạo 1 tài khoản riêng ( không dùng root để
cài đặt Nominatim )
-
Tạo người dùng ( dùng tài khoản root để tạo )
o
adduser nominatim
-
Thiết lập pass
o
passwd nominatim
-
Phân quyền sudo
o
usermod -aG wheel nominatim
3.4.2
Tải và build Nominatim
-
Dùng tài khoản root
cd /srv
wget
http://www.nominatim.org/release/Nominatim-2.5.1.tar.bz2
tar xvf Nominatim-2.5.1.tar.bz2
mv Nominatim-2.5.1 nominatim
./configure
make
3.4.3
Cấu hình Nominatim
-
Cấu hình file
/srv/nominatim/settings/settings.php
@define('CONST_Database_Web_User',
'apache');
@define('CONST_Postgresql_Version',
'9.2');
@define('CONST_Postgis_Version',
'2.0');
@define('CONST_Website_BaseURL',
'http://localhost/nominatim/');
-
Cấu hình sau được dự đoán sẽ tăng performance của
hệ thống bằng việc loại bỏ ghi log
@define('CONST_Log_DB', false);
@define('CONST_Log_File', false);
3.4.4
Tải dữ liệu OSM của Vietnam
-
Dùng tài khoản root thực hiện từ thư mục hiện
hành /srv/Nominatim
wget
--output-document=data/wikipedia_article.sql.bin
http://www.nominatim.org/data/wikipedia_article.sql.bin
wget
--output-document=data/wikipedia_redirect.sql.bin
http://www.nominatim.org/data/wikipedia_redirect.sql.bin
wget --output-document=data/vi.osm.pbf
http://download.geofabrik.de/asia/vietnam-latest.osm.pbf
-
Tạo thêm 1 số dữ liệu bổ sung
./utils/specialphrases.php
--countries > specialphrases_countries.sql
./utils/specialphrases.php
--wiki-import > specialphrases.sql
3.4.5
Thiết lập SELinux và 1 số quyền hạn
-
Dùng tài khoản root thiết lập selinux
semanage fcontext -a -t
httpd_sys_content_t "/srv/nominatim/(website|lib|settings)(/.*)?"
semanage fcontext -a -t lib_t
"/srv/nominatim/module/nominatim.so"
restorecon -R -v /srv/nominatim
-
Thiết lập quyền hạn dùng root
chown -R nominatim /srv/nominatim
sudo su nominatim
chmod -R 755 /srv/nominatim
3.4.6
Cài đặt Nominatim
-
Chuyển sang người dùng nominatim bằng lệnh sudo
su nominatim
-
Cài đặt
mkdir -m 755
/var/www/html/nominatim
sudo chown nominatim
/var/www/html/nominatim
cd /srv/nominatim
./utils/setup.php --create-website
/var/www/html/nominatim
3.4.7
Cài dữ liệu OSM
-
Dùng tài khoản nominatim. Quá trình này với dữ
liệu Vietnam có thể kéo dài khoản 1h, với dữ liệu lớn hơn có thể lâu hơn nên
hay chú ý
-
Các lệnh thực hiện
sudo su nominatim
cd /srv/nominatim
./utils/setup.php --osm-file
/srv/nominatim/data/vi.osm.pbf --all 2>&1 | tee setup.log
-
Trả lại cấu hình postgres “/var/lib/pgsql/data/postgresql.conf”
fsync = on
full_page_writes =
on
3.4.8
Cấu hình apache hoàn thành cài đặt
-
Sửa file “/etc/httpd/conf.d/welcome.conf” xóa hết
nội dung cũ chỉ để
<Directory
"/var/www/html/nominatim/">
Options FollowSymLinks MultiViews
AddType text/html .php
</Directory>
-
Khởi động lại Apache
systemctl restart httpd
-
Kiểm tra web: [link]/nominatim
-
Tạo robots.txt chặn search engine cho web này
4.
Cập nhật dữ liệu OSM
4.1
Cài osmosis
-
Dùng tài khoản root
cd /usr/local/bin
wget
http://bretth.dev.openstreetmap.org/osmosis-build/osmosis-latest.tgz
mkdir osmosis
mv osmosis-latest.tgz osmosis
cd osmosis
tar xvfz osmosis-latest.tgz
rm osmosis-latest.tgz
chmod a+x bin/osmosis
4.2
Cấu hình Nominatim update dữ liệu vietnam
-
Cấu hình file
/srv/nominatim/settings/settings.php
@define('CONST_Osmosis_Binary',
'/usr/local/bin/osmosis/bin/osmosis');
@define('CONST_Replication_Url',
'http://download.geofabrik.de/asia/vietnam-updates/');
@define('CONST_Replication_MaxInterval',
'40000');
@define('CONST_Replication_Update_Interval',
'86400');
@define('CONST_Replication_Recheck_Interval',
'900');
4.3
Cài đặt update
-
Chuyển sang người dùng nominatim và vào thư mục
nominatim
sudo su nominatim
cd /srv/nominatim
-
Thực hiện
./utils/setup.php --osmosis-init
./utils/setup.php
--create-functions --enable-diff-updates
4.4
Cập nhật OSM
-
Chuyển sang người dùng nominatim và vào thư mục
nominatim
sudo su nominatim
cd /srv/nominatim
-
Cập nhật OSM
./utils/update.php
--import-osmosis-all --no-npi
Subscribe to:
Comments (Atom)
Sublime Text 3 Usage
1. Download and install sublime 2. Install some essential packages: - Seti.sublime-theme : theme beautiful - HTML-CSS-JS Prettify (nee...
-
This tutorial will guide you how to use PDO in order to access Microsoft SQL Server. Step 1: Install Microsoft ODBC 11 driver for MSSQL ...
-
How to install MongoDB - Enterprise on CentOS 1. Configure repository. Create an /etc/yum.repos.d/mongodb-enterprise.repo file so t...
-
Nominatim Installation Update date: 2017/03/29 Contents 1. Các thuật ngữ . 5 2. Giới thiệu . 5 3. ...