2018年1月8日 星期一

ntp server , centos7

https://www.phpini.com/linux/rhel-centos-7-setup-ntp-sync-time

https://www.server-world.info/en/note?os=CentOS_7&p=ntp

root@dlp ~]# 
yum -y install ntp
[root@dlp ~]# 
vi /etc/ntp.conf
# line 18: add the network range you allow to receive requests

restrict 10.0.0.0 mask 255.255.255.0 nomodify notrap
# change servers for synchronization

#
server 0.centos.pool.ntp.org iburst #這邊改成自己的上游
#
server 1.centos.pool.ntp.org iburst
#
server 2.centos.pool.ntp.org iburst
#
server 3.centos.pool.ntp.org iburst
server ntp1.jst.mfeed.ad.jp iburst
server ntp2.jst.mfeed.ad.jp iburst
server ntp3.jst.mfeed.ad.jp iburst
[root@dlp ~]# 
systemctl start ntpd 

[root@dlp ~]# 
systemctl enable ntpd 


[root@dlp ~]# 
firewall-cmd --add-service=ntp --permanent 

success
[root@dlp ~]# 
firewall-cmd --reload 

success

Verify it works normally like follows.
[root@dlp ~]# 
ntpq -p

     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
+ntp1.jst.mfeed. 172.29.1.100     2 u   29   64    1   18.826   -0.126   0.000
+ntp2.jst.mfeed. 172.29.2.50      2 u   28   64    1   21.592    0.018   0.000
*ntp3.jst.mfeed. 133.243.236.18   2 u   28   64    1   22.666   -1.033   0.000

可以用 ntpstat 看同步了沒  不然會有 尚未時間同步之伺服器不被信任!!
網路斷掉要 retry 幾次才會上同步




2018年1月5日 星期五

Centos7 關閉 udev



-------------------------------------

https://www.phpini.com/linux/centos-7-network-interface-name

CentOS 7 修改網卡名稱 Eno* 成 Eth0

在 RHEL 及 CentOS 7 開始, 網卡的預設名稱由以往的 Ethx 改成 Enox, 以下文章會介紹將 CentOS 7 網卡名稱修改, 用回 Eth0 的方法。
首先開啟檔案 “/etc/sysconfig/grub” 修改設定:
# vi /etc/sysconfig/grub
內容大概是這樣:
裡面其中一行是 GRUB_CMDLINE_LINUX, 在這行結尾的雙引號前加上這句:
net.ifnames=0 biosdevname=0
要留意, 加上以上一行資料前, 要先加上一個空格, 整行修改後是這樣:

然後用 grub2-mkconfig 指令重新建立 GRUB 的設定檔:
# grub2-mkconfig -o /boot/grub2/grub.cfg
接著要將 Eno 網卡的設定檔用 mv 改名為 eth0:
# mv /etc/sysconfig/network-scripts/ifcfg-eno16777736 /etc/sysconfig/network-scripts/ifcfg-eth0
編輯 /etc/sysconfig/network-scripts/ifcfg-eth0 檔案, 找到 “Name” 的一行, 改成 eth0, 全句是這樣:
NAME=eth0
​最後重新啟動系統便會生效, 要確認修改成功, 可以用 ifconfig 指令確認。
--------------------------------

2017年12月29日 星期五

centos6.2 , tomcat6 , LetsEncrypt


wget https://dl.eff.org/certbot-auto

chmod a+x certbot-auto

certbot-auto certonly --webroot -w /var/lib/tomcat6/webapps -d {DomainName} -m {E-Mail}


cd /etc/letsencrypt/live/{DomainName}

--openssl pkcs12 -export -out bundle.pfx -inkey privkey.pem -in cert.pem -certfile chain.pem -password pass:{PASSWORD}


openssl pkcs12 -export -out /etc/letsencrypt/live/www.vghtc.gov.tw/fullchain_and_key.p12     -in /etc/letsencrypt/live/www.vghtc.gov.tw/fullchain.pem     -inkey /etc/letsencrypt/live/www.vghtc.gov.tw/privkey.pem     -name tomcat


最後真的有效的
openssl pkcs12 -export -in fullchain.pem -inkey privkey.pem -out keystore.p12 -name tomcat -CAfile chain.pem -caname root  //看看能不能上password

keytool -importkeystore -deststorepass cc3fvghtc -destkeypass cc3fvghtc -srckeystore keystore.p12 -destkeystore www.vghtc.gov.tw.jks -srcstoretype pkcs12 -srcstorepass cc3fvghtc -alias tomcat



1202  cp /etc/letsencrypt/live/www.vghtc.gov.tw/www.vghtc.gov.tw.jks /var/lib/tomcat6/


 1232  iptables -I PREROUTING -t nat -p tcp --dport 443 -j REDIRECT --to-port 8443
 1233  iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 443 -j ACCEPT
 1234  iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 8443 -j ACCEPT
 1242  iptables-save



-------------------------------------
強制改走 https

http://adalf0722.blogspot.tw/2010/12/tomcathttp-80https-443.html

0.先備份web.xml與servel.xml

1.編輯Tomcat安裝目錄conf下的web.xml
  在</welcome-file-list>與</web-app>之間,加入如下的code,然後存檔

<security-constraint>
 <web-resource-collection>
 <web-resource-name>Protected Context</web-resource-name>
 <url-pattern>/*</url-pattern>
 </web-resource-collection>
 <user-data-constraint>
 <transport-guarantee>CONFIDENTIAL</transport-guarantee>
 </user-data-constraint>
 </security-constraint>
2.同樣編輯目錄下的server.xml,確認一下redirectPort是不是已經是443
    <Connector port="80" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="443" />
3.完成,重啟Tomcat一下,就可以試試看囉


https://www.journaldev.com/160/steps-to-configure-ssl-on-tomcat-and-setup-auto-redirect-from-http-to-https


Tomcat Redirect HTTP to HTTPS

So we can access any web application on both HTTP and HTTPS ports. We can set up tomcat to redirect all HTTP request to HTTPS port with some configurations.
  1. In ~TomcatInstallation/conf/server.xml
    For HTTP Connector, set the redirect port to the HTTPS connector port. It will look somewhat like this:
    <!-- Define a non-SSL HTTP/1.1 Connector on port 8080 -->
        <Connector port="8090" maxHttpHeaderSize="8192"
                   maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
                   enableLookups="false" redirectPort="8443" acceptCount="100"
                   connectionTimeout="20000" disableUploadTimeout="true" />
  2. In ~TomcatInstallation/conf/web.xml
    Add below configuration but make sure to add it after all the servlet mapping tags.
    <!-- added by Pankaj for automatic redirect from HTTP to HTTPS -->
    <security-constraint>
    <web-resource-collection>
    <web-resource-name>Entire Application</web-resource-name>
    <url-pattern>/*</url-pattern>
    </web-resource-collection>
    <user-data-constraint>
    <transport-guarantee>CONFIDENTIAL</transport-guarantee>
    </user-data-constraint>
    </security-constraint>
Restart the tomcat now and all the HTTP requests will automatically be redirected to HTTPS i.e http://localhost:8080/axis2 will be automatically redirected to https://localhost:8443/axis2
Note: If you don’t want to provide ports in the URLs, then use 80 for HTTP and 443 for HTTPS and in this case you can skip the first step to automatic redirect HTTP requests to HTTPS because it will automatically pick the default port 443.
-------------------------------------
Failed to load keystore type JKS with path jks due to (Permission denied)

把 keystore 搬到 tomcat 家目錄底下(好像在/etc下會看不到 可能是沒有從 root 開始開 read 的關係)

-------------------------------------
https://teddysun.com/153.html

安装完运行yum报错:
Error: Cannot retrieve metalink for repository: epel. Please verify its path and try again
解决办法:
vi /etc/yum.repos.d/epel.repo
编辑[epel]下的baseurl前的#号去掉,mirrorlist前添加#号。正确配置如下:
[epel]
name=Extra Packages for Enterprise Linux 6 - $basearch
baseurl=http://download.fedoraproject.org/pub/epel/6/$basearch
#mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearch
failovermethod=priority
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6

-------------------------------------
http://acman.bluenest.net/wordpress/archives/96

2017年12月11日 星期一

CentOS7 架 OpenLDAP 來源 Source 測試 3



用 hostnamectl 改 hostname  

ref : https://www.phpini.com/linux/redhat-centos-7-change-hostname

hostnamectl set-hostname openldapdev03


準備等下要用的安裝包

#掛 nfs 準備抄資料用的
yum install nfs-utils wget

# compile openldap / BDB 需要用的
yum install -y libtool-ltdl libtool-ltdl-devel openssl-devel openssl gcc

#跑 SASL 需要用的
yum install cyrus-sasl cyrus-sasl-devel

# check crc32 用的
yum install zlib-devel -y

#total
yum install nfs-utils wget  libtool-ltdl libtool-ltdl-devel openssl-devel openssl gcc cyrus-sasl cyrus-sasl-devel zlib-devel -y


準備 source file
check-4.3-src.tgz  db-4.6.21.tar.gz  openldap-2.4.45.tgz

解壓
   tar zxvf openldap-2.4.45.tgz
   tar zxvf db-4.6.21.tar.gz
   tar xvf check-4.3-src.tgz

編 CHECK


gcc -O3 -Wall -DUSE_ZLIB -I/usr/include -o check check.c -L/usr/lib64 -lz

編BDB


cd db-4.6.21/
cd build_unix/
../dist/configure
#這邊要指定安裝地點的話可以用 ../dist/configure --prefix=/usr/local/BDB
make
make install
echo "/usr/local/BerkeleyDB.4.6/lib" > /etc/ld.so.conf.d/bdb.conf
ln -sv /usr/local/BerkeleyDB.4.6/include /usr/include/bdb

編openldap

cd openldap-2.4.45

ldconfig -v

./configure --with-cyrus-sasl --with-tls=openssl \
                CPPFLAGS="-I/usr/local/BerkeleyDB.4.6/include" \
                LDFLAGS="-L/usr/local/BerkeleyDB.4.6/lib"

make depend

make

make test

make install

echo "/usr/local/lib/" > /etc/ld.so.conf.d/ldap.conf
ln -sv /usr/local/openldap2.4/include /usr/include/ldap2.4
ldconfig -v



啟動的方式

/usr/local/libexec/slapd -h "ldap:/// ldaps:/// ldapi:///"--要加 Ldapi 才能改 config

錯誤訊息 : ldap user can't add entry: Insufficient access (no write access to parent)

ACL問題
改config
在 database 裡加上
Access to *
by dn.base="gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth" manage
by * none
-->這邊要改成 by * auth ,因為 m2 會用自己的 DN 做 AUTH 看看會不會過
-->目前先開成 read 可能試看看降到 auth 可不可以

ACL說明
http://www.openldap.org/doc/admin24/access-control.html


啟動的檢查:
netstat -lan | grep 389

config 的檢查(ACL要先OK)
ldapsearch -Y EXTERNAL -H ldapi:/// -D {RootDN} -w {RootPW} -b cn=config objectClass=*


** Monitor 的問題
在 slapd.conf 裡加上

database monitor
access to dn.subtree="cn=Monitor"
    by dn.exact="cn=root,o=XXXXX,c=XX" write
    by users read
    by * none

查詢
ldapsearch -x -D 'cn=root,o=XXXXX,c=XX' -w XXXXXX -b 'cn=Monitor' '(objectClass=*)' '*' '+'


** uid 跟 userid 的問題
https://tools.ietf.org/html/rfc4519#section-2.39
https://tools.ietf.org/html/rfc1274

userid 可能在 inetOrgPerson 或 cosine.schema 裡面 , 如果是標準的 schema, userid 只是 uid 的 alias ,進去還是會變成 sid
可以到 /etc/openldap/schema 裡面找看看userid 定義在哪裡 //在schema_prep.c
這個問題應該跟 ldap 本身的 aclentry 無關
改完之後 make test 會炸掉 因為丟進去 uid 回來的是 userid

所以到

openldap-2.4.45/tests/data
openldap-2.4.45/testrun

底下各下一次

find . -type f -exec sed -i.bak 's/uid:/userid:/g' {} \;
find . -type f -exec sed -i.bak 's/uid=/userid=/g' {} \;

應該測試就可以過了 應該啦

todo替換 rootDN //在slapd.conf裡可以壓過去
todo 替換 suffix //在slapd.conf裡可以壓過去
todo 加schema //在slapd.conf裡可以壓過去,但自己家的schema要提供
todo 加 有 userid 的schema //失敗, userid是 uid 的 alias

todo 匯入資料
//isAccountEnabled 要改 T/F
//description 空的要抓掉
//直接匯出的要用 dos2unix 轉格式

todo 看 monitor
todo 開 log
todo 開 Firewalld




啟動 log 的方式
openldap 會把東西丟到 syslog 的 LOCAL4
 (currently logged to the syslogd(8) LOG_LOCAL4 facility).
http://www.openldap.org/doc/admin24/slapdconf2.html

mkdir /var/log/ldap

在 /etc/rsyslog.d/ 裡面加一個檔案 (例如 slapd.conf )
裡面寫

local4.*                        /var/log/ldap/ldap.log

然後  service rsyslog restart

然後在 slapd.conf 裡面加

loglevel -1

(詳細數字意義看說明。然後其實應該也可以用 ldapmodify 改)

然後用 slapd.conf 重長 slapd.d

--TODO: 長太快了 用 logrotate 切掉

在 /etc/logrotate.d/ 加入一個檔案 slapd 內容是

vim /etc/logrotate.d/slapd

/var/log/ldap/ldap.log
{
rotate 31
daily
  dateext
        missingok
        notifempty
        compress
        delaycompress
        sharedscripts
        postrotate
                /bin/systemctl restart rsyslog.service >/dev/null 2>&1 || true
        endscript
}

加完可以
 service rsyslog restart
/usr/sbin/logrotate -f /etc/logrotate.conf  試看看

--> postrotate 要把 rsyslog 重啟 不然會一直寫在舊的檔案上

參考
https://blog.gtwang.org/linux/openldap-log-rsyslog/

olclogfile 這個好像是在 windows 版本用的(? 在2.4的說明裡沒有看到

參考 logrotate
https://ihower.tw/blog/archives/3565
https://blog.gtwang.org/linux/openldap-log-rsyslog/


改用 systemd 取代  service {start|stop}

參考 https://ssorc.tw/6064
 /usr/lib/systemd/system/slapd.service
 /etc/sysconfig/slapd

到 /usr/lib/systemd/system/ 找 slapd.service
[root@localhost schema]# cat /usr/lib/systemd/system/slapd.service
[Unit]
Description=OpenLDAP Server Daemon
After=syslog.target network-online.target
Documentation=man:slapd
Documentation=man:slapd-config
Documentation=man:slapd-hdb
Documentation=man:slapd-mdb
Documentation=file:///usr/share/doc/openldap-servers/guide.html

[Service]
Type=forking
PIDFile=/var/run/openldap/slapd.pid
Environment="SLAPD_URLS=ldap:/// ldapi:///" "SLAPD_OPTIONS="
EnvironmentFile=/etc/sysconfig/slapd
ExecStartPre=/usr/libexec/openldap/check-config.sh
ExecStart=/usr/sbin/slapd -u ldap -h ${SLAPD_URLS} $SLAPD_OPTIONS

[Install]
WantedBy=multi-user.target


[root@localhost schema]# cat /etc/sysconfig/slapd
# OpenLDAP server configuration
# see 'man slapd' for additional information
# Where the server will run (-h option)
# - ldapi:/// is required for on-the-fly configuration using client tools
# (use SASL with EXTERNAL mechanism for authentication)
# - default: ldapi:/// ldap:///
# - example: ldapi:/// ldap://127.0.0.1/ ldap://10.0.0.1:1389/ ldaps:///
SLAPD_URLS="ldapi:/// ldap:///"
# Any custom options
#SLAPD_OPTIONS=""
# Keytab location for GSSAPI Kerberos authentication
#KRB5_KTNAME="FILE:/etc/openldap/ldap.keytab"

----------------------
leapsearch的用法

1) enable the monitor backend at configure:configure --enable-monitor
2) activate the monitor database in the slapd.conf(5) file:database monitor
3) add ACLs as detailed in slapd.access(5) to control access to the database, e.g.:

access to dn.subtree="cn=Monitor"
by dn.exact="uid=Admin,dc=my,dc=org" write
by users read
by * none

4) ensure that the core.schema file is loaded.The monitor backend relies on some standard track attributeTypes that must be already defined when the backend is started.


索引的參考資料
http://www.zytrax.com/books/ldap/apa/indeces.html


BDB/HDB 參考資料
https://www.openldap.org/doc/admin24/slapdconf2.html
https://www.openldap.org/doc/admin24/slapdconf2.html#BDB and HDB Database Directives


userid / uid 問題

RFC1274  這時候還是 userid  https://tools.ietf.org/html/rfc1274
RFC4514 建議要往 short name 方向走  https://tools.ietf.org/html/rfc4514
RFC4519 這時候 userid 已經變成 uid 的別名  https://tools.ietf.org/html/rfc4519#section-2.39


DB_CONFIG 的問題  bdb_db_open: warning - no DB_CONFIG file found in directory 
DB_CONFIG 應該放在 db 所在的位置下 (ex . ?)
http://godleon.blogspot.tw/2007/04/openldap-bdbdbopen-warning-no-dbconfig.html

雜項討論
http://bbs.chinaunix.net/archiver/?tid-387214-page-6.html   写给所有OpenLDAP不能正常启动的人

其他在 CentOS7 下的討論
http://blog.ilc.edu.tw/blog/index.php?op=printView&articleId=688049&blogId=25793
https://www.server-world.info/en/note?os=CentOS_7&p=openldap
http://jamyy.us.to/blog/2016/07/8245.html

CentOS6
http://www.centoscn.com/image-text/config/2015/0714/5862.html

TCP Wrapper
http://www.weithenn.org/2011/12/rhce-day21-tcp-wrappers.html
https://www.server-world.info/en/note?os=CentOS_7&p=tcp_wrapper



2017年12月1日 星期五

DPIMP做到一半死掉


https://shanojkumar.wordpress.com/2013/05/29/ora-31626-job-does-not-exist-and-how-to-cleanup-orphaned-datapump-jobs-in-dba_datapump_jobs/

http://blog.oracle48.nl/wordpress/killing-and-resuming-datapump-expdp-and-impdp-jobs/

https://dbatricksworld.com/how-to-kill-oracle-datapump-export-job/

SQL> DECLARE
h1 NUMBER;
BEGIN
h1:=DBMS_DATAPUMP.ATTACH(‘SYS_EXPORT_FULL_01‘,’SYSTEM‘);
DBMS_DATAPUMP.STOP_JOB (h1,1,0);
END;
/

試著 attach 回去然後再stop / start

如果一直吐 ORA-31626:  Job does not exist 那就只能幹掉他

看還有沒有在跑
select * from dba_datapump_jobs;

找MAIN TABLE 然後 DROP掉
--SELECT o.status, o.object_id, o.object_type,
--o.owner||'.'||object_name "OWNER.OBJECT"
--FROM dba_objects o, dba_datapump_jobs j
--WHERE o.owner=j.owner_name AND o.object_name=j.job_name
--AND j.job_name NOT LIKE 'BIN$%' ORDER BY 4,2;

然後清除轉一半的東西重做

select object_type,count(object_type) as c from sys.all_objects where owner='{SCHEMA_NAME}' group by objecT_type order by 2