顯示具有 Redhat 6 標籤的文章。 顯示所有文章
顯示具有 Redhat 6 標籤的文章。 顯示所有文章

2016年4月6日 星期三

Linux scp rsync多網段管理

當MIS總是會管理到很多台主機
一台兩台還沒甚麼感覺,但是當數量變二十幾台後就相當有感

為此寫了支SSH與RSYNC組合應用的BASH檔作為管理上版與收集資訊用


#!/bin/bash
# Program:
#       SCP佈檔設定變更
# History:
# 2016/04/06 Edwin.Chen

#今天的日期
nowDate=`date +"%Y%m%d"`

#DMZ位置
dmzdir="/tmp/edwin/dmz/";
#資料來源
SOURCE="/tmp/edwin/source/";
#目的資料夾
REMOTEDIR="/tmp/edwin/";
#要執行的BASH
pullsh=mv.sh
#接收資料位置
collect="/tmp/edwin/collect/";

cd /tmp/edwin
test ! -d ${collect} && mkdir "collect"
test ! -d ${SOURCE} && echo "SOURCE資料夾不存在"
test ! -d ${dmzdir} && echo "DMZ資料夾不存在"
test ! -d ${dmzdir} && exit;
#檢查今日日期的目錄是否存在,如果不存在就建一個(!代表反面語意)
cd ${REMOTEDIR}

echo '1)DMZ1'
echo '2)DMZ2'
echo '3)DMZ3'
echo '4)DMZ4'
echo '5)TEST'
read -p "請輸入DMZ區段:" -t 30 dmz

#將DMZ檔案讀入陣列
READFILE=${dmzdir}dmz${dmz}.txt
while read line; do
      declare i=${i}+1
      host[$i]=${line}
done < ${READFILE}

#SCP佈檔
A=1;
declare -i MAX=${i}-1;
while [ ${A} -le ${MAX} ]; do
        #佈檔
        rsync -arvz --rsh=ssh ${SOURCE} ${host[$A]}:${REMOTEDIR}
        #遠端執行
        ssh ${host[$A]} 'bash -s' < ${SOURCE}${pullsh}
        #拉檔回傳
        rsync -arvz --rsh=ssh ${host[$A]}:${REMOTEDIR}/. ${collect}
        A=`expr ${A} + 1`;
        #exit為測試用註解,代表執行1迴圈即離開。
        #exit;
done;






2016年3月27日 星期日

Device eth0 does not seem to be present, delaying initialization.

  利用 ESXI 的 OVF 匯入功能,複製一台 Linux 虛擬主機,結果開機後發現網路卡未啟動,執行 ifup eth0 出現下列訊息。

 # ifup eth0
 
 Device eth0 does not seem to be present, delaying initialization.
  經查詢發現因為OVF匯入的虛擬機會變更新的 MAC Address,所以造成 Linux 判斷成另一張網卡,下列兩種方法任選一種就可以解決。

方法一:
 1) 我們可以先用下列指令查看系統目前抓到哪幾張網卡
 # cat /proc/net/dev
 Inter-|   Receive                                                |  Transmit
 face |bytes    packets errs drop fifo frame compressed multicast|bytes    packets errs drop fifo colls carrier compressed
    lo:       0        0    0    0    0     0          0         0        0        0    0    0    0     0       0          0
  eth1:     0        0    0    0    0     0          0         0        0        0    0    0    0     0       0          0
 這裡可以發現網卡代號已經變成 eth1

 2) 編輯 /etc/udev/rules.d/70-persistent-net.rules
 # vi /etc/udev/rules.d/70-persistent-net.rules
# PCI device 0x8086:0x100e (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="08:00:27:64:f9:37", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
# PCI device 0x8086:0x100e (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="08:00:27:64:f9:39", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"

 可以將 eth1 修改為 eth0,重新開機。


 3) 編輯 /etc/sysconfig/network-scripts/ifcfg-eth0
 # vi /etc/sysconfig/network-scripts/ifcfg-eth0
 將"HWADDR="參數修改成正確的 MAC Address,或刪除此參數,若沒有這個參數應該在上一個步驟重新開機後會自動啟動網卡。

 4) 修改完成後,就可以順利啟動網卡。
 # ifup eth0


方法二:
 1) 我們可以先用下列指令查看系統目前抓到哪幾張網卡
 # cat /proc/net/dev
 Inter-| Receive | Transmit
face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed
lo: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
eth1: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
 這裡可以發現網卡代號已經變成 eth1

 2) 編輯 /etc/sysconfig/network-scripts/ifcfg-eth0
 # vi /etc/sysconfig/network-scripts/ifcfg-eth0
 DEVICE=eth0 -> 修改為 DEVICE=eth1
 HWADDR= -> 刪除或修改成正確的 MAC Address

 3) 因為裝置名稱已變更,所以 ifcfg-eth0 也要跟著更名
 # mv ifcfg-eth0 ifcfg-eth1

 4) 修改完成後,就可以順利啟動網卡。
 # ifup eth1

2016年3月19日 星期六

Linux CentOS/Redhat SCP

當網管在一堆SERVER之間遊走時操作時,
會有遠端COPY檔案的需求
此時便是SCP的出現


除了遠端連線(SSH)之外

也可提供檔案傳輸的指令


scp 來源 目的

將檔案從遠端傳到本機
遠端-->本機
scp username@tohostname:/remotefile /newlocalfile



將檔案從本機傳到遠端
本機 -->遠端

scp localfile username@tohostname:/newfilename

2016年2月14日 星期日

Redhat "Resource temporarily unavailable"

最近遇到的一些問題
其中一個為

"Resource temporarily unavailable"

遠端連線時出現訊息為:

利用SU切換帳號則會出現:
"cannot set user id: Resource temporarily unavailable" while trying to login or su as a local user in



"cannot set user id: Resource temporarily unavailable" while trying to login or su as a local user in


Normal user is unable to login on the system with an error "fork: Resource temporarily unavailable"



這個問題來自於用戶的執行程序數量抵達該用戶的上限所致
但,需要釐清其原因是因有需求程式還是應程式的錯誤迴圈導致其資源被用盡。
查看使用程序的數量:

 # ps -u testuser -L | wc -l
    103

將找到的程序刪除
 $  killall xxxx



過陣子再查看是否有清除期程序:

 $ ps ux | wc -l

若是需調整其資源限制則為:
/etc/security/limits.d/90-nproc.conf
增加或修改上限

查看限制
 $ ulimit -u

並可從安全紀錄查看變更記錄
/var/log/secure:



Red Hat Enterprise Linux
https://access.redhat.com/solutions/30316


2015年11月4日 星期三

rsync

在Linux 環境的檔案傳輸通常會使用CP

但當在丟到USB隨身碟時會有檔案複製不確定是否完成的疑慮

之前便是使用sync 藉由此指令來確認檔案是否寫入完成

後來找了找發現了rsync這套指令
似乎也不錯用


rsync --progress 顯示檔案傳輸的進度

參考網址說是給無聊的人用的
但我就是那個有需要這東西的無聊人士QAQ





====
參考網址
http://blog.xuite.net/jyoutw/xtech/20025390-rsync%E5%8F%83%E6%95%B8%E8%A9%B3%E8%A7%A3--990209

http://ericbbs.blogspot.tw/2009/08/rsync.html

2015年10月21日 星期三

Linux 使用者帳號管理

事情太多了,讓人的腦子只能是下三個月的記憶能力
以前覺得理所當然的事情都會忘光
只好不得不打一打紀錄一下

指令

帳號管理: groupadd, groupdel, useradd, userdel, chsh, chfn, userconf
密碼管理與設定:passwd,
使用者身份切換:su, sudo, visudo
使用者查詢: id, finger, groups


剩下的之後再補
======================
用法
由於通用就不特別打試用版本了
※{}內包含符號本身都是可修改

加入user

useradd {user}

EX:useradd edwin

加入多個user

EX:useradd edwin yami neko


更改使用者密碼
passwd {user}

EX: passwd edwin



Tips: 查看user屬於那一個group


傳統的方法是透過/etc/group的文檔來查看user屬於哪一些group。
[root@centos6 ~]# cat /etc/group | grep root
root:x:0:root
bin:x:1:root,bin,daemon
daemon:x:2:root,bin,daemon
sys:x:3:root,bin,adm
adm:x:4:root,adm,daemon
disk:x:6:root
wheel:x:10:root

其實可以透過groups指令來查詢的。
[root@centos6 ~]# groups root
root : root bin daemon sys adm disk wheel
此篇的主要目的是當創建sudo 權限帳號時
增加副Group的指令



usermod -G wheel edwin.chen

==========================
有時要做root的事
sudo su -

因為系統檔案不允許root身分之外的帳號執行,故直接切換身分為root
無須輸入root密碼。
==========================
其實最重要的在這裡,安裝完後該做的就是建置帳號、密碼、群組,權限設定。
而如何輕鬆地複製貼上或是寫成SH一鍵執行做設定就看這了,以下做兩個帳號設定的示範。


#add user
groupadd mis

useradd edwin.chen
useradd user02

usermod -G mis user02
usermod -G mis edwin.chen

#set password
echo "123456" | passwd --stdin edwin.chen
echo "Password" | passwd --stdin user02

#visudo 設定sudo權限,直接寫入sudoers

echo -e "%mis       ALL=(ALL)       NOPASSWD: ALL" >>/etc/sudoers

#清除歷史紀錄
history -c











==========================

參考資料
鳥哥
http://linux.vbird.org/linux_basic/0410accountmanager/0410accountmanager-fc4.php#users_adduser
瘋狂帽客
http://go-linux.blogspot.tw/2011/11/tips-usergroup.html

2015年9月15日 星期二

Redhat 6.4 install Oracle 11G

環境:REDHAT 6.4 + GUI

依參考網址的步驟安裝
http://techblog.forink.net/2014/01/centos-6-5-oracle-database-11gr2-apex-%E5%AE%89%E8%A3%9D%E8%A8%98%E9%8C%84/

至23步止便安裝完成無須後面設定

只要添加防火牆規則開放1521PORT即可連線


以下皆可不需觀看
=====================================

1.安裝設置JAVA

詳情請見:
Redhat/CentOS java環境設置
看不懂沒關係看結論!
不用做任何事
Redhat 已預設安裝JAVA

2. 安裝相關套件

yum -y install compat-libstdc++* gcc-c++* glibc* libaio* libstdc++* unixODBC* elfutils-libelf-devel*

YUM詳情請見REDHAT yum offline

3. 預先建立oracle帳號,並建立oinstall、dba、oper群組,並指定給oracle (主群組設定為oinstall)

groupadd oinstall
groupadd dba
groupadd oper
groupadd asmdba
groupadd asmoper
groupadd asmadmin
useradd --gid oinstall --groups dba,oper,asmdba,asmoper,asmadmin oracle
passwd oracle


4. 預先建立Oracle安裝路徑,並設定所在路徑的擁有者為oracle

mkdir -p /opt/oracle/product/11.2.0/dbhome_1
chown -R oracle:oinstall /opt

5. 設定系統參數,編輯/etc/profile,新增以下段落,
vim /etc/profile

# Oracle
TMP=/tmp
TMPDIR=$TMP
ORACLE_BASE=/opt/oracle
ORACLE_HOME=$ORACLE_BASE/product/11.2.0/dbhome_1
ORACLE_SID=orcl
export TMP TMPDIR ORACLE_BASE ORACLE_HOME ORACLE_SID

以Oracle
在  Oracle帳號的PATH變數中新增$ORACLE_HOME/bin

cd ~
vim .bash_profile
PATH=$PATH:$HOME/bin:$ORACLE_HOME/bin

6. 修改 /etc/security/limits.conf,在最下方加入下列內容 ( 若跟原有資料重複的話,請記得刪除舊值 ):
vim /etc/security/limits.conf

#oracle
oracle              soft    nproc   2047
oracle              hard    nproc   16384
oracle              soft    nofile  1024
oracle              hard    nofile  65536
oracle              soft    stack   10240






8.  解壓縮
unzip -oq "linux.x64_11gR2_database*.zip"




Inventory
資料夾擁有者需要與安裝帳號相同



9. 設定環境變數,若CentOS為非英文版,沒做這一步,安裝畫面會出現方框亂碼

[oracle@localhost database]$ export LANG=en_US.UTF-8
[oracle@localhost database]$ export LC_ALL=en_US.UTF-8


10.用oracle 帳號登入桌面執行安裝
終端機
sh /tmp/Oracle_install/database/runInsraller

至這一步起若前面設定皆有成功

若有出現

./runInstaller

Checking Temp space: must be greater than 120 MB. Actual 6820 MB Passed
Checking swap space: must be greater than 150 MB. Actual 1965 MB Passed
Checking monitor: must be configured to display at least 256 colors
Could not execute auto check for display colors using command /usr/bin/xdpyinfo. Check if the DISPLAY variable is set. Failed <<<<

則為登入的桌面使用者非Oracle帳號
請更換為Oracle帳號登入



就可以操作畫面安裝點選下一步

直至檢查畫面
接下來依指示以ROOT權限執行SH檔修正即可

※沒意外的話是執行以下兩行
sh /opt/oraInventory/orainstRoot.sh
sh /opt/oracle/product/11.2.0/dbhome_1/root.sh


11. 檢查相依的Library,可以先點選中間的 "Fix & Check Again" 按鈕查看驗證結果,
並依其指示進行修正。

※錯誤訊息 ins-20802

vi /etc/sysconfig/ntpd

添加 -x

OPTIONS="-u ntp:ntp -p /var/run/ntpd.pid -g"
OPTIONS="-x -u ntp:ntp -p /var/run/ntpd.pid -g"


12.
防火牆開啟 1521

iptables-save > /root/iptables
vim /root/iptables

添加

-A INPUT -p tcp -m state --state NEW -m tcp --dport 1521 -j ACCEPT

13.設定
$ORACLE_HOME/network/admin/listener.ora

修改以下內容,若HOST設定為127.0.0.1,記得要改成localhost或固定IP,
避免無法監聽Client端的連線的問題。
1
2
3
4
5
6
7
8
9
10
11
# listener.ora Network Configuration File: /opt/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora
# Generated by Oracle configuration tools.

LISTENER = (DESCRIPTION_LIST = (DESCRIPTION = (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521)) (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521)) ) ) ADR_BASE_LISTENER = /opt/oracle


14.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
[root@localhost ~]# su oracle -
[oracle@localhost root]$ lsnrctl start
LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 07-JAN-2014 17:03:33
Copyright (c) 1991, 2009, Oracle.  All rights reserved.
Starting /opt/oracle/product/11.2.0/dbhome_1/bin/tnslsnr: please wait...
TNSLSNR for Linux: Version 11.2.0.1.0 - Production
System parameter file is /opt/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora
Log messages written to /opt/oracle/diag/tnslsnr/localhost/listener/alert/log.xml
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost.localdomain)(PORT=1521)))
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 11.2.0.1.0 - Production
Start Date                07-JAN-2014 17:03:35
Uptime                    0 days 0 hr. 0 min. 0 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /opt/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora
Listener Log File         /opt/oracle/diag/tnslsnr/localhost/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost.localdomain)(PORT=1521)))
The listener supports no services
The command completed successfully

====================================
14.Oracle Enterprise Manager

至此可以透過網頁工具操作

Web版的管理工具 Oracle Enterprise Manager 的網址預設為 https://localhost:1158/em
不過在啟動前還需要做一些設定,不然是看不到的


連接資料庫
sqlplus / as sysdba






=========
參考資料

https://oracle-base.com/articles/11g/oracle-db-11gr2-installation-on-oracle-linux-7
https://oracle-base.com/articles/11g/oracle-db-11gr2-installation-on-oracle-linux-6
http://techblog.forink.net/2014/01/centos-6-5-oracle-database-11gr2-apex-%E5%AE%89%E8%A3%9D%E8%A8%98%E9%8C%84/
http://figaro.neo-info.net/?cat=243

Inventory
資料夾擁有者需要與安裝帳號相同
oracle create database script