donderdag 14 december 2017

wget and curl tips

Imagine you want to download all files under http://www.example.com/2013/downloads, and not files under http://www.example.com/2013 except for directory 'downloads', then you can do this:
wget -r --level 100 -nd --no-proxy --no-parent --reject "index.htm*" --reject "*gif" 'http://www.example.com/2013/downloads/' #--level 100 is large enough, as I've seen no site has more than 100 levels of sub-directories so far.
wget -p -k --no-proxy --no-check-certificate --post-data 'id=username&passwd=password' <url> -O output.html
wget --no-proxy --no-check-certificate --save-cookies cookies.txt <url>
wget --no-proxy --no-check-certificate --load-cookies cookies.txt <url>
curl -k -u 'username:password' <url>
curl -k -L -d id=username -d passwd=password <url>
curl --data "loginform:id=username&loginform:passwd=password" -k -L <url>
curl -i -u username:password -H X-Oracle-UserId:myname@example.com -H X-Oracle-IdentityDomain:domainname -X GET "https://login.example.com:443/api/v1/users?userLogin"
Here's one curl example to get SSL certs info on LTM:
#!/bin/bash
path="/var/tmp"
path_root="/var/tmp"
agent="Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; InfoPath.2)"
curl -v -L -k -A "$agent" -c ${path}/cookie "https://ltm-url/tmui/login.jsp?msgcode=1&"
curl -v -L -k -A "$agent" -b ${path}/cookie -c ${path}/cookie -e "https://ltm-url/tmui/login.jsp?msgcode=1&" -d "username=myusername&passwd=mypassword" "https://ltm-url/tmui/logmein.html?msgcode=1&"
curl -v -L -k -A "$agent" -b ${path}/cookie -c ${path}/cookie -o ${path_root}/certs-env.html "https://ltm-url/tmui/Control/jspmap/tmui/locallb/ssl_certificate/list.jsp?&startListIndex=0&showAll=true"
Now you can have a check of /var/tmp/certs-env.html for SSL certs info of Big IP VIPs.
PS:
To use private CA/public cert/private key, you should use below in curl:
curl -v --cacert your-root-ca.crt --cert your-public-cert.crt --key your-private.key --pass mypass -u "username:password" https://url
In this command, your-public-cert.crt is the public cert that you have trusted,your-private.key is the private RSA key portion of the cert that is used to sign the request, and “username:password” should be replaced with the correct username and password.
Also, if you’re using an intermediate cert, you can provide it in one command like so:
curl -v --cacert your-root-ca.crt --cert <(cat your-public-cert.crt  intermediate.crt ) --key your-private.key --pass mypass -u “username:password" https://url

MySql Tips

log in:
mysql -h localhost -u root -pyourpassword
set password:
set password for 'root'@'localhost' = password('123456');
create db:
CREATE DATABASE `newone` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
add privileges:
CREATE USER 'root'@'192.168.0.0.1';
GRANT ALL PRIVILEGES ON * . * TO 'root'@'192.168.0.0.1' WITH GRANT OPTION MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0 ;
flush privileges;
add user:
CREATE USER 'hello'@'192.168.0.2' IDENTIFIED BY '***';
GRANT ALL PRIVILEGES ON * . * TO 'hello'@'192.168.0.2' IDENTIFIED BY '***' WITH GRANT OPTION MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0 ;
flush privileges;
check user:
mysql> select Host,User from mysql.user;
export db(or you can use mysql enterprise backup<mysqlbackuphot/warm/cold>):
mysqldump -u root -pyourpassword --no-data --default-character-set=utf8 test>aaa.sql #--no-data export only structures
import db:
mysql -h localhost -u root -pyourpassword dbname</root/db.sql
show storage engine of specified table
SELECT `ENGINE` FROM `information_schema`.`TABLES` WHERE `TABLE_SCHEMA`='ovs' AND `TABLE_NAME`='Mgr_NetworkFileServer';
SQL:
create table wp_posts_bak as select * from wp_posts;
select post_title,post_status,post_name from wp_posts where post_content like "%<pre>%";
update wp_posts set post_content=replace(post_content,'<blockquote>','<br /><i>');
DELIMITER // #when you need define some functions and met error "ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'END' at line 1". You'll also need type END// instead of END;. Switch delimiter back to ; using DELIMITER ;
select length(post_content),char_length(post_content) from wp_posts;
PS:
  1. Below are comparision about mysql storage engine MyISAM & InnoDB - https://www.pureweber.com/article/myisam-vs-innodb/ & http://coolshell.cn/articles/652.html
  2. Here is about binlog format(row based/statement based/mixed, on slave it's relay logs) - http://dev.mysql.com/doc/refman/5.7/en/binary-log-setting.html
  3. We can use mysql proxy to make read/write separation. And we can use Mysql cluster for distributed HA/High redundant topology(shared nothing, need high bandwidth, RAC is shared disk architecture). For Oracle DB, we can use different service names for read/write separation.

dinsdag 12 december 2017

Install berkeley 4.8 db libs on Ubuntu 16.04

  1. sudo add-apt-repository ppa:bitcoin/bitcoin
  2. sudo apt-get update
  3. sudo apt-get install libdb4.8-dev libdb4.8++-dev
or

  1. wget http://download.oracle.com/berkeley-db/db-4.8.30.zip
  2. unzip db-4.8.30.zip
  3. cd db-4.8.30
  4. cd build_unix/
  5. ../dist/configure --prefix=/usr/local --enable-cxx
  6. make
  7. make install
or

  1. BITCOIN_ROOT=$(pwd)
  2. # Pick some path to install BDB to, here we create a directory within the bitcoin directory
  3. BDB_PREFIX="${BITCOIN_ROOT}/db4"
  4. mkdir -p $BDB_PREFIX
  5. # Fetch the source and verify that it is not tampered with
  6. wget 'http://download.oracle.com/berkeley-db/db-4.8.30.NC.tar.gz'
  7. echo '12edc0df75bf9abd7f82f821795bcee50f42cb2e5f76a6a281b85732798364ef db-4.8.30.NC.tar.gz' | sha256sum -c
  8. # -> db-4.8.30.NC.tar.gz: OK
  9. tar -xzvf db-4.8.30.NC.tar.gz
  10. # Build the library and install to our prefix
  11. cd db-4.8.30.NC/build_unix/
  12. # Note: Do a static build so that it can be embedded into the executable, instead of having to find a .so at runtime
  13. ../dist/configure --enable-cxx --disable-shared --with-pic --prefix=$BDB_PREFIX
  14. make install
  15. # Configure Bitcoin Core to use our own-built instance of BDB
  16. cd $BITCOIN_ROOT
  17. ./autogen.sh
  18. ./configure LDFLAGS="-L${BDB_PREFIX}/lib/" CPPFLAGS="-I${BDB_PREFIX}/include/" # (other args...)


VNCServer setup on OEL7 Linux

#more info about vncserver on OEL7 is here

#disable firewalld
systemctl stop firewalld
systemctl disable firewalld

yum groupinstall "server with gui" -y
yum install tigervnc-server -y
yum install gnome-terminal gnome-session -y

su - root
vncpasswd

vi ~/.vnc/xstartup

    #!/bin/sh
    [ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
    [ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
    xsetroot -solid grey
    vncconfig -iconic &
    gnome-terminal &
    gnome-session &


su - oracle
vncpasswd

vi ~/.vnc/xstartup

    #!/bin/sh
    [ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
    [ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
    xsetroot -solid grey
    vncconfig -iconic &
    gnome-terminal &
    gnome-session &

chmod 755 ~/.vnc ; chmod 600 ~/.vnc/passwd ; chmod 755 ~/.vnc/xstartup
chmod 755 ~oracle/.vnc ; chmod 600 ~oracle/.vnc/passwd ; chmod 755 ~oracle/.vnc/xstartup

cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver-root@\:1.service
cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver-oracle@\:2.service

vi /etc/systemd/system/vncserver-root@\:1.service

    [Unit]
    Description=Remote desktop service (VNC)
    After=syslog.target network.target

    [Service]
    Type=forking
    User=root

    # Clean any existing files in /tmp/.X11-unix environment
    ExecStartPre=-/usr/bin/vncserver -kill %i
    ExecStart=/usr/bin/vncserver %i
    PIDFile=/root/.vnc/%H%i.pid
    ExecStop=-/usr/bin/vncserver -kill %i

    [Install]
    WantedBy=multi-user.target


vi /etc/systemd/system/vncserver-oracle@\:2.service

    [Unit]
    Description=Remote desktop service (VNC)
    After=syslog.target network.target

    [Service]
    Type=forking
    User=oracle

    # Clean any existing files in /tmp/.X11-unix environment
    ExecStartPre=-/usr/bin/vncserver -kill %i
    ExecStart=/usr/bin/vncserver %i
    PIDFile=/home/oracle/.vnc/%H%i.pid
    ExecStop=-/usr/bin/vncserver -kill %i

    [Install]
    WantedBy=multi-user.target

#Optionally, you can add command-line arguments for the VNC server 
    (only accepts connections from localhost, and change size of the window)

    ExecStart=/sbin/runuser -l vncuser -c "/usr/bin/vncserver %i -localhost -geometry 640x480"


systemctl daemon-reload

systemctl start vncserver-root@\:1.service
systemctl start vncserver-oracle@\:2.service

systemctl enable vncserver-root@\:1.service
systemctl enable vncserver-oracle@\:2.service

systemctl get-default #make sure it's multi-user.target