顯示具有 Linux教學 標籤的文章。 顯示所有文章
顯示具有 Linux教學 標籤的文章。 顯示所有文章

2020/06/11

Published 6月 11, 2020 by with 0 comment

Linux帳號控管-By IP

一.  ;新增帳號
1、    帳號新增
類別
帳號名
Group
Home directory
Default shell
個人帳號
u卡號
例:u123456
useracc
Linux:
/home/<username>
bash(linux) ksh


2、    Group建立:(第一次需建立)
groupadd -g 1000 useracc

3、    帳號建立(執行異動前請先備份passwd/shadow 檔案)
使用useradd 指令新增帳號
#useradd -g <group> -d <home_dir> -s <shell> -m <username>

設定初始密碼
#passwd <username>

登入之後必需要修改初始密碼
Linux:
#chage -d 0 <username>

二.  SSH連線設定(Linux)
1、修改/etc/ssh/sshd_config : 改用AllowGroups (取代AllowUsers)
AllowGroups root wheel useracc
Sshd reload :
#service sshd reload
2、修改/etc/pam.d/sshd 加入:
account    required  pam_access.so accessfile=/etc/security/sshd_access.conf

3、修改/etc/pam.d/su 加入
    auth            required        pam_wheel.so  root_only  use_uid

Sshd reload :
#service sshd reload


4、編輯 /etc/security/sshd_access.conf 加入:

帳號設定範例
帳號 SAM , SAM-TEST  IP 限制方式
SAM   允許以下 IP 連線 22.22.22.22 22.22.22.23 10.0.0.0/8
SAM-TEST允許以下 IP 連線 10.0.0.0/8
# vim /etc/security/sshd_access.conf
- : SAM : ALL EXCEPT  22.22.22.22 22.22.22.23 10.0.0.0/8
- : SAM-TEST : ALL EXCEPT 10.0.0.0/8





Read More

2020/01/30

Published 1月 30, 2020 by with 0 comment

RHEL7 Oracle開機啟動/關閉設定方式

RHEL7 Oracle開機啟動/關閉設定方式:

使用Systemctl start/stop dbora

Read More

2019/08/18

Published 8月 18, 2019 by

vmstat命令 -性能監測與優化

vmstat命令 -性能監測與優化

vmstat命令的含義為顯示虛擬內存狀態("Virtual Memory Statistics"),但是它可以報告關於進程、內存、I/O等系統整體運行狀態。

Read More

2017/04/30

Published 4月 30, 2017 by

Linux下PHP連線MSSQL

OS:RHEL 6.7 64bit
PHP: PHP 5.3.3

說明:
透過ODBC連結MSSQL DB


安裝步驟:
1.   FreeTDS and unixODBC.

可透過yum或下載RPM安裝:
#yum install unixODBC freetds

[root@test tmp]# rpm -qa | grep freetds
freetds-doc-0.91-2.el6.x86_64
freetds-0.91-2.el6.x86_64

[root@test tmp]# rpm -qa | grep unixODBC
unixODBC-devel-2.2.14-14.el6.x86_64
unixODBC-2.2.14-14.el6.x86_64


2.     Registering the ODBC driver with freeTDS

[root@test tmp]#  ldconfig -p | grep libtdsodbc
libtdsodbc.so.0 (libc6,x86-64) => /usr/lib64/libtdsodbc.so.0

3.     Create and edit files /etc/odbcinst.ini and /etc/odbc.ini with following contents:
[root@test tmp]# cat /etc/odbcinst.ini
[FreeTDS]
Description = Freetds v 0.95
Driver =/usr/lib64/libtdsodbc.so.0

[root@test tmp]# cat /etc/odbc.ini
[MESDB1]
Driver = FreeTDS
Description = Any description
Trace = No
Server = 10.3.2.1
Port = 1433
TDS version = 0.95
Database = db_ControlManager

4.     Testing MSSQL connection via command line
#isql -v dw364 account password

5.     Creating symlinks to the .ini files
# ln -s /etc/odbc.ini /usr/local/zend/etc/odbc.ini
# ln -s /etc/odbcinst.ini /usr/local/zend/etc/odbcinst.ini

6.     Testing MSSQL connection via PHP
<?php

// Replace the value's of these variables with your own data:
$dsn = "Driver=FreeTDS;DSN=MESDB1"; // Data Source Name (DSN) from the file /usr/local/zend/etc/odbc.ini
$user = "nacadm"; // MSSQL database user
$password = "abcNAC"; // MSSQL user password

$conn = odbc_connect($dsn, $user, $password);
if ($conn) {
    echo "Connection established.";
} else {
    die("Connection could not be established.");
}


$sql = "select EI_DomainName as Domain ,EI_OS_MachineName as Host_Name, EI_IPAddressList as IP, EI_UserAccount as login_name from dbo.tb_EntityInfo where EI_state=100 and EI_IPAddressList like '10.2.23%' or EI_IPAddressList like '10.2.3%'order by  Domain";

$rs=odbc_exec($conn,$sql);
while (odbc_fetch_row($rs))
{
  $compname=odbc_result($rs,"Domain");
  $conname=odbc_result($rs,"Host_Name");
  echo "<tr><td>$compname</td>";
  echo "<td>$conname</td></tr>";
}
odbc_close($conn);
?>

參考資料:
https://support.zend.com/hc/en-us/articles/218197897-Configuring-a-Linux-Server-to-Connect-to-an-MSSQL-Database-Using-ODBC


Read More

2016/09/05

Published 9月 05, 2016 by

備份及回存Linux的權限及Owner

備份及回存Linux的權限及Owner

備份權限及Owner:
find * -depth -exec stat --format '%a %u %g %n' {} &#43; >/tmp/save-the-list

回存權限及Owner:
 while read PERMS OWNER GROUP FILE 
 do 
     chmod "$PERMS" "$FILE" 
     chown "${OWNER}:${GROUP}" "$FILE" 
 done </tmp/save-the-list 

保存的檔案內容如下(以相對目錄存放)
目前權限 Owner Group Directory/file
775 2001 2001 test_file/old_version
644 2001 2001 tester_file/direct.sh
644 0 0 tes_file/123.sh
644 2001 2001 test_file/update.sh
755 2001 2001 test_file

Reference:


Read More

2016/09/04

Published 9月 04, 2016 by

Linux Script 二進位編碼 加密


Linux Script編碼

gzexe(gzip executable) 
功能說明:壓縮執行文件。

語  法:
編碼:gzexe [執行文件]à產生二進位檔,一般人看不懂裡面內容
反解:gzexe [-d][執行文件]

補充說明:gzexe是用來壓縮執行文件的程序。當您去執行被壓縮過的執行文件時,該文件會自動解壓然後繼續執行,和使用一般的執行文件相同。

參  數:
 -d  解開壓縮文件。


shc方法
shc是一個加密shell腳本的工具.它的作用是把shell腳本轉換爲一個可執行的二進制文件
shc 安裝方式:
# tar -xzf shc-3.8.7.tgz
# cd shc-3.8.7
# make
# ./shc -v -f match

使用以上的方式編譯 Shell,只能在相同的作業系統上執行,若要在不同的作業系統上也能執行,則要以 static library 方式,指令如下
export CFLAGS=-static && ./shc -r -f myshell
如果要設定期限
export CFLAGS=-static && ./shc -e 19/10/2011 -r -f PIAF-install-ec2.sh
如何檢查執行檔是 static dynamic library
file myshell.x
如果yum不能安裝,請移步官方下載rpm
http://pkgs.repoforge.org/shc/
http://www.datsi.fi.upm.es/~frosal/sources/

Reference:
SHC說明:

文章說明:

Read More

2016/08/30

Published 8月 30, 2016 by

VNC Server架設

VNC Server架設
環境:RHEL 6.4 64bit
Vncserver:內建, libvncserver-0.9.7-4.el6.x86_64

Server端:
輸入VNCServer
[root@test1 ~]# vncserver

You will require a password to access your desktops.

Password:ß輸入密碼
Verify: ß輸入密碼

New 'test1:1 (root)' desktop is test1:1

Creating default startup script /root/.vnc/xstartup
Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/test1:1.logßlog file


Check VNC Status:


[root@test1 ~]# vncserver -list

TigerVNC server sessions:

X DISPLAY #     PROCESS ID
:1              43468

Client:
主機名稱:test1
Port:5901


Read More
Published 8月 30, 2016 by

Iperf網路測試軟體

iperf網路測試軟體

需安裝Client & Server
Server:
iperf3 -s

Client:
iperf3 -c 192.12.1.2  -t 10 -i 5 -M 1500
#-c : server IP
#-t : 測量時間間隔為10
#-i : 每隔 5 秒將測量結果顯示出來,最後再算出平均值.
#-w :測試的檔案大小
#-R :反相測試
#-M :設定TCP資料封包的最大mtu
#-p :指定伺服端使用的port或客戶端所連接的port
#-u :使用udp協議

通用參數

-f [k|m|K|M] 分別表示以Kbits, Mbits, KBytes, MBytes顯示報告,預設以Mbits為單位,eg:iperf -c 192.12.1.2 -f K
-i sec 以秒為單位顯示報告間隔,eg:iperf -c 192.12.1.2 -i 2
-l 緩衝區大小,預設是8KB,eg:iperf -c 192.12.1.2 -l 16
-m 顯示tcp最大mtu
-o 將報告和錯誤信息輸出到檔案eg:iperf -c 192.12.1.2 -oc:\iperflog.txt
-p 指定服務器端使用的端口或客戶端所連接的端口eg:iperf -s -p 9999;iperf -c 192.12.1.2 -p 9999
-u 使用udp協議
-w 指定TCP窗口大小,預設是8KB
-B 綁定一個主機地址或通訊埠(當主機有多個地址或通訊埠時使用該參數)
-C 兼容舊版本(當server端和client端版本不一樣時使用)
-M 設定TCP資料封包的最大mtu
-N 設定TCP不延時
-V 傳輸ipv6資料封包

Reference:
教學
http://benjr.tw/462
Download
https://iperf.fr/iperf-download.php#source
Read More

2016/05/13

Published 5月 13, 2016 by

新增User出現41-digit hexadecimal加密問題

新增User出現41-digit hexadecimal加密問題

說明:
Windows新的版本,使用新的加密方式,必需要更改新的加密方式:
old_passwords=0àoff

Linux版本,是使用舊的加密方式。

Q1:Create User出現Password hash should be a 41-digit hexadecimal number

mysql> CREATE USER 'testaccount'@'127.0.0.1' IDENTIFIED BY PASSWORD 'asdf';
ERROR 1372 (HY000): Password hash should be a 41-digit hexadecimal number


A:
查看old_passwords,Default ON,代表可以使用舊的加密方式
mysql> SHOW variables like '%old_password%';

# old_passwords=0àoff
# old_passwords=1àon

mysql> set old_passwords=0;

查看加密完的密碼:

重新設定密碼:
mysql> SET PASSWORD FOR 'testaccount'@'127.0.0.1' = ' *7F0C90A004C46C64A0EB9DDDCE5DE0DC437A635C ';


Reference:




Read More

2016/02/21

Published 2月 21, 2016 by

限制User使用sftp在家目錄,並加入log file

限制User使用sftp在家目錄,並加入log file
一、環境說明:
Red Hat Enterprise Linux Server release 6.7 (Santiago)
# sshd -v
sshd: illegal option -- v
OpenSSH_5.3p1, OpenSSL 1.0.1e-fips 11 Feb 2013
rsyslog-5.8.10

二、設置ssh 設定
1.針對user設置:
# vi /etc/ssh/sshd_config 
Subsystem       sftp    internal-sftp -f AUTHPRIV -l VERBOSE -u 0002 -f LOCAL6
Match user schuang
    ChrootDirectory /home/sftpuser
    X11Forwarding no
    AllowTcpForwarding no
   ForceCommand internal-sftp -u 0002 -l VERBOSE -f LOCAL6

設置(針對Group設置)
# vi /etc/ssh/sshd_config 
Subsystem       sftp    internal-sftp -f AUTHPRIV -l VERBOSE -u 0002 -f LOCAL6
Match group sftponly
         ChrootDirectory /home/%u
         X11Forwarding no
         AllowTcpForwarding no
         ForceCommand internal-sftp

三、修正使用者帳戶的家目錄權限
家目錄必需是要root,且最大的權限為755(為了不給user切換到另一目錄)
#chown root.root /home/sftpuser
#chmod 755 /home/sftpuser

. 在使用者目錄下建立允許上傳檔案的目錄
建立可上傳目錄,並賦予適當的目錄權限
#cd /home/sftpuser
#mkdir upload
#chown sftpuser.sftpuser upload
五、建立登入log file
#cd /home/sftpuser
#mkdir dev

# vi /etc/rsyslog.conf 
local6.*                                                /var/log/sftp.log
$AddUnixListenSocket /home/sftpuser/dev/log

# service rsyslog restart
#service sshd restart
#tail -f /var/log/sftp.log


Error message:
fatal: bad ownership or modes for chroot directory
因沒有加入到root群組
請做第三步驟。

參考檔案:
Sftp Install 1:
Sftp Install 2:
Sftp log:  
http://gdcsy.blog.163.com/blog/static/12734360920145632946993/

Read More
Published 2月 21, 2016 by

Linux online IOscan - Fiber LUN Volumn Scan

#for i in /sys/class/fc_host/host*; do (cd $i; echo -e "$(echo $i)\t$(cat port_name)\t$(cat port_state)\t$(cat speed)"); done

/sys/class/fc_host/host3        0x5001438021e1c508      Online  8 Gbit
/sys/class/fc_host/host4        0x5001438021e1c50a      Linkdown        unknown
/sys/class/fc_host/host5        0x5001438021e1c3e0      Online  8 Gbit
/sys/class/fc_host/host6        0x5001438021e1c3e2      Linkdown        unknown

可以看出host3host5Onlie

重新掃瞄:
echo "1" > /sys/class/fc_host/host3/issue_lip
echo "1" > /sys/class/fc_host/host5/issue_lip

查看StorageLun
#fdisk -l

Read More

2015/12/14

Published 12月 14, 2015 by

Linux VI 及 目錄變更顏色

vi變更顏色:
設定在個人家目錄:
[root@ap811 ~]#cat .bashrc
# .bashrc
alias vi='vim'

##設定套件顏色
[root@ap811 ~]#cat .vimrc
:color desert


目錄變更顏色:
先確認是使用那一個file
[root@ap811 ~]# set | grep DIR
COLORS=/etc/DIR_COLORS.xterm

尋找DIR參數,變更後面的參
vi /etc/DIR_COLORS.xterm
# Below are the color init strings for the basic file types. A color init
# string consists of one or more of the following numeric codes:
# Attribute codes:
# 00=none 01=bold 04=underscore 05=blink 07=reverse 08=concealed
# Text color codes:
# 30=black 31=red 32=green 33=yellow 34=blue 35=magenta 36=cyan 37=white
# Background color codes:
# 40=black 41=red 42=green 43=yellow 44=blue 45=magenta 46=cyan 47=white
NORMAL 00       # global default, although everything should be something.
FILE 00         # normal file
DIR 00;33       # directory
…..

若是要設定在個人,設定方式如下:
[schuang@ap811 ~]#cp /etc/DIR_COLORS /userap/schuang/DIR_COLORS

變更DIR欄位顏色
[schuang@ap811 ~]#vi /userap/schuang/DIR_COLORS
DIR 00;33       # directory

登錄自動登錄,新增以下這一段:
[schuang@ap811 ~]#vi .bashrc
eval `dircolors --sh /userap/schuang/DIR_COLORS`

Read More
Published 12月 14, 2015 by

SAR-系統效能判斷

系統效能判斷:

要判斷系統瓶頸問題,有時需幾個 sar 命令選項結合起來;
懷疑CPU存在瓶頸,可用 sar -u sar -q 等來查看
懷疑記憶體存在瓶頸,可用sar -Bsar -r sar -W 等來查看
懷疑I/O存在瓶頸,可用 sar -bsar -u sar -d 等來查看
使用方式:
#sar -u 1 100(1秒執行一次,執行100)


-A     等價於 -bBcdqrRuvwWy -I SUM -I XALL -n ALL -P ALL
-b     顯示I/O和傳送速率的統計資訊
-B     輸出記憶體頁面的統計資訊
-c     輸出進程統計資訊,每秒創建的進程數
-d     輸出每一個塊設備的活動資訊
-i interval        指定間隔時長,單位為秒
-p     顯示友好設備名字,以方便查看,也可以和-d -n 參數結合使用,比如 -dp -np
-q     輸出進程佇列長度和平均負載狀態統計資訊
-r     輸出記憶體和交換空間的統計資訊
-R     輸出記憶體頁面的統計資訊
-t      讀取 /var/log/sa/saDD 的資料時顯示其中記錄的原始時間,如果沒有這個參數使用用戶的本地時間
-u     輸出CPU使用情況的統計資訊
-v     輸出inode、檔和其他內核表的統計資訊
-V     輸出版本號資訊
-w    輸出系統交換活動資訊
-W   輸出系統交換的統計資訊
-y     輸出TTY設備的活動資訊
-n {DEV|EDEV|NFS|NFSD|SOCK|ALL}    分析輸出網路設備狀態統計資訊。
DEV 報告網路設備的統計資訊
EDEV       報告網路設備的錯誤統計資訊
NFS  報告 NFS 用戶端的活動統計資訊
NFSD        報告 NFS 伺服器的活動統計資訊
SOCK       報告網路通訊端(sockets)的使用統計資訊
ALL  報告所有類型的網路活動統計資訊
-x {pid|SELF|ALL}    輸出指定進程的統計資訊。
pid   pid 指定特定的進程
SELF 表示 sar 自身
ALL  表示所有進程
-X {pid|SELF|ALL}    輸出指定進程的子進程的統計資訊
-I {irq|SUM|ALL|XALL}   輸出指定中斷的統計資訊。
irq    指定中斷號
SUM        指定輸出每秒接收到的中斷總數
ALL  指定輸出前16個中斷
XALL        指定輸出全部的中斷資訊
-P {cpu|ALL}    輸出指定 CPU 的統計資訊
-o filename     將輸出資訊保存到檔 filename
-f filename      從檔 filename 讀取資料資訊。filename 是使用-o 選項時生成的檔。
-s hh:mm:ss     指定輸出統計資料的起始時間
-e hh:mm:ss    指定輸出統計資料的截至時間,預設為18:00:00


參考資料:http://linuxtools-rst.readthedocs.org/zh_CN/latest/tool/sar.html

Read More
Published 12月 14, 2015 by

Install NetBackup Client Linux/Unix From Master Server


一、系統環境說明
1.      NBU Server Path:/usr/openv/netbackup/client/Linux/RedHat2.6.18
2.      Client OS version:RHEL, kernel:2.6.18
3.      aptestb原本nbu client為7.5,升級為7.6.03

二、透過SSH Login Install
1.      先建立免密碼的ssh key
2.      執行安裝:


[root@nbuserver /usr/openv/netbackup/client/Linux/RedHat2.6.18]# ./ssh_to_client aptestb
installpbx                           100%   53KB  53.2KB/s   00:00
PBX.tar.gz                           100% 9062KB   8.9MB/s   00:00
pdinstall                            100%   27KB  27.1KB/s   00:00
pddeagent.tar.gz                     100%   34MB  33.7MB/s   00:01
JRE.tar.gz                           100%   44MB  43.9MB/s   00:00
.sizes_JRE                           100%    6     0.0KB/s   00:00
NB-Java.tar.gz                       100%  199MB  66.3MB/s   00:03
.sizes_NB-Java                       100%    7     0.0KB/s   00:00
JAVAnbj.conf.aptestb.16318            100%  668     0.7KB/s   00:00
cp_to_client                         100%   90KB  89.9KB/s   00:00
extract_java                         100%   22KB  22.3KB/s   00:00
install_client                       100%   31KB  30.7KB/s   00:00
nbcheck                              100%   11MB  11.2MB/s   00:00
version                              100%   31     0.0KB/s   00:00
tar                                  100%  370KB 369.6KB/s   00:00
.sizes                               100%   15     0.0KB/s   00:00
.sizes_client_bin                    100%    7     0.0KB/s   00:00
client_config                        100%  100KB  99.5KB/s   00:00
aptestb_bin_net.tar.16318             100%   10KB  10.0KB/s   00:00
client_bin.tar.gz                    100%  158MB  79.1MB/s   00:02
Checking for SYMCpddea package...
   Package SYMCpddea found.

NetBackup Deduplication software is installed.

NetBackup Deduplication is not yet configured.


Checking for required system conditions...


Checking for recommended system conditions...

ok nb_7603_hotfix_auditor: No potential for regression of hotfixes or EEBs was detected.
Blocksize = 20 records
./
./bp_servers
./bp_client_name

Terminating NetBackup and/or Media Manager processes.

Saving pack history as /usr/openv/pack.7.5

Saving client binaries for Linux/RedHat2.6.18.

Installing PBX...
Please wait while installation is in progress...
Installation completed Successfully
Installation log located here: /var/tmp/installpbx-18177-120715140809.log


Unpacking SYMCnbclt package.
Checking for pre-existing SYMCnbclt package.
Removing pre-existing SYMCnbclt package.
Installing SYMCnbclt package.
Installation of SYMCnbclt was successful.
More details regarding SYMCnbclt can be found in file
/tmp/install_cltpkg_trace.17102 on aptest.

Terminating NetBackup and/or Media Manager processes.

Send a SIGHUP to (x)inetd so the (x)inetd.conf file will be reread.
Reloading configuration: [  OK  ]
Installing NB-Java.

Unpacking SYMCnbjava package.
Checking for pre-existing SYMCnbjava package.
Removing pre-existing SYMCnbjava package.
Installing SYMCnbjava package.
Installation of SYMCnbjava was successful.
More details regarding SYMCnbjava can be found in file
/tmp/install_javapkg_trace.19505 on aptest.

Unpacking SYMCnbjre package.
Checking for pre-existing SYMCnbjre package.
Removing pre-existing SYMCnbjre package.
Installing SYMCnbjre package.
Installation of SYMCnbjre was successful.
More details regarding SYMCnbjre can be found in file
/tmp/install_jrepkg_trace.19505 on aptest.

WARNING: Copying /usr/openv/netbackup/nblog.conf to
         /usr/openv/netbackup/nblog.conf.12-07-15.14:07:12
         for future reference.  Any local modifications to
         /usr/openv/netbackup/nblog.conf should be re-evaluated.


Migrating log files in /usr/openv/logs
Migration of log files complete.

Checking for SYMCpddea package...
   Package SYMCpddea found.
Removing SYMCpddea package...
   Package SYMCpddea removed.
Installing PDDE agent package (/tmp/bp.16318/openv/netbackup/client/Linux/RedHat2.6.18/pddeagent.tar.gz)...
Extracting package SYMCpddea in /tmp/pdde_pkg_dir_20076.
   Package SYMCpddea extracted to /tmp/pdde_pkg_dir_20076.
Installing package SYMCpddea.
   Package SYMCpddea installed.
PDDE install finished successfully.
Version now installed: 8.0003.0014.0530
Full PDDE installation log saved to: /var/log/puredisk/2015-12-07_14:08-pdde-install.log


WARNING: Copying /etc/rc.d/init.d/netbackup to
         /usr/openv/netbackup/bin/goodies/netbackup.12-07-15.14:07:12
         for future reference.  Any local modifications to
         /etc/rc.d/init.d/netbackup should be re-evaluated.


The following automatic startup and shutdown scripts (respectively)
have been installed.  They will cause the NetBackup daemons to be
automatically shut down and restarted each time the system boots.

/etc/rc.d/rc2.d/S77netbackup
/etc/rc.d/rc3.d/S77netbackup
/etc/rc.d/rc5.d/S77netbackup
/etc/rc.d/rc0.d/K01netbackup
/etc/rc.d/rc1.d/K01netbackup
/etc/rc.d/rc6.d/K01netbackup


Successfully updated the session cache parameters.
Starting vnetd...
Starting bpcd...
Starting nbftclnt...
Starting nbdisco...
Starting mtstrmd...
Starting bmrbd...

Installation of Java LiveUpdate agent succeeded.  Refer to file
/tmp/JLU-Log/JavaLiveUpdate-Install.log on aptest
for installation details.


Checking LiveUpdate registration for the following products: CLT
This may take a few minutes.

Product CLT is installed and will be registered.

Updating LiveUpdate registration now...this may take some time.


Client install complete.

INF OTHER - EXIT STATUS = 0


三、確認版本及Client重啟
[root@aptest ~]# cat /usr/openv/netbackup/bin/version
[root@aptest ~]#/etc/init.d/netbackup stop/start

Read More