Linux SSL Trouble Shooting


cannot load certificate key "/home/SSL/201810/key.pem": PEM_read_bio_PrivateKey() failed 

(SSL: error:0906406D:PEM routines:PEM_def_callback:problems getting password error:0906A068:PEM routines:PEM_do_header:bad password read)



openssl rsa -in [기존인증서파일].key -out [새로운인증서파일].key

openssl 로 접근하게 되면 key에 대한 pass-phrase 를 물어본다. 이 경우 비밀번호를 넣었을 때 복호화에 성공하면 새로운 키를 -out 으로 생성하게 된다.

블로그 이미지



댓글을 달아 주세요

How To Optimize WordPress Performance With MySQL Replication On Ubuntu 14.04


In this tutorial, we will teach you how to scale up your WordPress MySQL database server setup using master-slave database replication and the HyperDB plugin for WordPress. Adding more database servers to your environment in this manner allows your WordPress application to read from multiple database servers, increasing read performance.

MySQL replication reaps the most performance benefits for a system that processes frequent reads and infrequent writes, like most WordPress installations. By using a single-master with multiple-slave setup, you can add more slaves to scale your system, until you run out of network bandwidth or your master cannot handle the update load. If you wish, you can add more than one slaves by repeating the “slave” portions of the replication sections of this tutorial.

We are assuming that your setup includes two load balanced WordPress application servers that connect to a separate MySQL database server (see the prerequisites for a tutorial on how to set that up). It is not strictly necessary to have load balanced application servers to follow this tutorial, but your MySQL database server should be separate from your application servers.


Before continuing with this tutorial, you should have completed two tutorials or have a similar environment:

After following those tutorials, to set up WordPress with two load balanced web application servers and a separate database server, you should have four VPSs. Because we will be dealing with several VPSs, for reference purposes, we will call your four existing VPSs the following:

  • haproxy-www: Your HAProxy server for layer 4 load balancing your WordPress web application servers. This is the entry point into your website
  • wordpress-1: Your first WordPress web application server
  • wordpress-2: Your second WordPress web application server
  • mysql-1: Your MySQL server for WordPress

That is, your environment should look something like this:



In addition to your current environment, we will require one additional VPS during this tutorial. We will call it:

  • mysql-2: Your slave MySQL database server

Our Goal

When we are finished with this tutorial, you will have two database servers will be replicating in a master-slave configuration. Your WordPress servers will selectively write to your master and read from both your master and slave databases, by use of the HyperDB WordPress plugin. Your final environment should look something like this:



Keep in mind that you do not need to have load balanced application servers (wordpress-1/wordpress-2) to follow this tutorial, and that you can add more slave databases if you want.

Set Up MySQL Master-Slave Replication

Before we can configure our WordPress application to read from multiple database servers, we need to set up our MySQL replication.

Create MySQL Slave VPS, mysql-2

You will want to create a new VPS that will act as the MySQL slave server–for reference purposes, we will call this server mysql-2. The slave will be configured to replicate all of the databases of your master MySQL server, including your WordPress database.

On mysql-2, install the MySQL software:

sudo apt-get update sudo apt-get install mysql-server

Enter a root password for your MySQL installation. Next we will configure on our MySQL master server.

Configure Existing MySQL Server as a Master

The first step is to set up your existing MySQL database server, mysql-1, with a replication master configuration.

On mysql-1, edit the MySQL configuration file:

sudo vi /etc/mysql/my.cnf

Search for the following three lines:

bind-address = <span class=“highlight”>mysql1private_IP</span>

server-id = 1

log_bin = /var/log/mysql/mysql-bin.log


  • bind-address: the IP address that MySQL will listen on. This should already be set to mysql-1’s private IP address from your original setup
  • server-id: the unique server ID. Since this is the master server, we will want to leave the value as “1” and uncomment this line
  • log_bin: the location of the binary log file. The binary log is used to send data changes from the master to its slave for replication. Uncomment this line

The three lines should look like this (be sure to substitute the highlighted with database server’s private IP address):

bind-address = <span class=“highlight”>mysql1privateIP</span>
server-id = 1
logbin = /var/log/mysql/mysql-bin.log

Optionally, if you want to restrict the replication to the wordpress database, specifically, add the following line to your configuration (substituting the highlighted with your desired database name):

binlogdodb = <span class=“highlight”>wordpress</span>

Save and quit. To put these changes into effect, restart mysql with the following command:

sudo service mysql restart

Connect to to the MySQL console with the following command, then enter the password when prompted:

mysql -u root -p

Create a user that will be used by our slave MySQL servers for replication purposes. We will call this user repl. Be sure to replace the repl_password with your own, strong password. The % specifies that the source IP for this user can be anything, but you may substitute the % with the private IP address of your slave MySQL server, mysql-2, to restrict connections with this user to that particular server:

CREATE USER ‘repl’@’<span class=“highlight”>%</span>’ IDENTIFIED BY ’<span class=“highlight”>repl_password</span>’;

Do not exit the MySQL console yet!

Export a Backup Of MySQL Master

Next, we will want to export a backup of the MySQL master database, to import into our slave database so it will be identical before we start replication. We need to lock the database so we can do a data dump. In your MySQL console on mysql-1, run this:


Now, from your command shell, run the following command to export a backup of the databases on your master MySQL server to a file called masterdump.sql:

mysqldump --lock-all-tables -u root -p --all-databases > masterdump.sql

Copy your masterdump.sql file to your slave server, mysql-2, using scp:

scp masterdump.sql <span class=“highlight”>user</span>@<span class=“highlight”>mysql2private_IP</span>:/tmp

Enter mysql-1’s MySQL console once again:

mysql -u root -p

At the MySQL prompt, unlock your database:


Now run this statement to print out information that you will need to configure your MySQL slave:

</pre> <pre> Output: +——————+———-+————–+——————+ | File | Position | BinlogDoDB | BinlogIgnoreDB |
| <span class=“highlight”>mysql-bin.000001</span> | <span class=“highlight”>408</span> | | | +——————+———-+————–+——————+ 1 row in set (0.00 sec) </pre>

Take a note of the values of File and Position, as you will need them when configuring your slave server. Let’s switch over to mysql-2 now.

Configure MySQL Slave

Now we will want to import the master database into our slave to synchronize them in preparation for replication.

On mysql-2, run this command to import the masterdump.sql file:

mysql -u root -p < /tmp/masterdump.sql

Next, we will set up mysql-2 as a replication slave. On mysql-2, edit the MySQL configuration file:

sudo vi /etc/mysql/my.cnf

Search for the following two lines:

bind-address =

server-id = 1


  • bind-address: the IP address that MySQL will listen on. Set to mysql-2’s private IP address
  • server-id: the unique server ID. Since this is the master server, change this value to 2 and uncomment this line

The two lines should look like this (be sure to substitute the highlighted with database server’s private IP address):

bind-address = <span class=“highlight”>mysql2private_IP</span>
server-id = 2

Save and quit. Restart MySQL to put the changes into effect:

sudo service mysql restart

Enter the MySQL console:

mysql -u root -p

Next, we will connect the slave to the master. The five following values are required:

  • MASTER_HOST: set to mysql-1’s private IP
  • MASTER_USER: set to the replication user that we created on the master, repl
  • MASTER_PASSWORD: set to repl’s password, which should be substituted with your own password
  • MASTERLOGFILE: set to the “File” listed when you ran SHOW MASTER STATUS; on your master MySQL server
  • MASTERLOGPOS: set to the “Position” listed when you ran SHOW MASTER STATUS; on your master MySQL server

The following statement connects your slave to your master server, and it requires that you substitute all of the highlighted fields with the appropriate values:

MASTERHOST=’<span class=“highlight”>mysql1privateIP</span>’,
MASTERPASSWORD=’<span class=“highlight”>replpassword</span>’,
MASTERLOGFILE=’<span class=“highlight”>mysql-bin.000001</span>’,
MASTERLOG_POS=<span class=“highlight”>408</span>;

If that statement ran properly, run this command to initiate the slave connection:


Your mysql-2 server should be connected as a slave now! Run the following command to check that the replication is working:


Revoke Write Privileges From Slave Users

This is optional because the HyperDB plugin can be configured to only read from your slave database server, but you may want revoke the write privileges from your wordpressuser database users on your slave database (because updates to your slave will not be replicated to your master, if you accidentally update your slave somehow).

On mysql-2, from your MySQL console run the following statement to list your database users:

SELECT user,host FROM mysql.user;
</pre> <pre> Output: +——————+—————-+ | user | host | +——————+—————-+ | repl | % | | wordpressuser | <span class=“highlight”>wordpress1IP</span> |
| wordpressuser | <span class=“highlight”>wordpress2IP</span> |


You should see output similar to the above code block. You may view privileges for each user with the following command:

SHOW GRANTS FOR <span class=“highlight”>wordpressuser</span>@<span class=“highlight”>wordpress1IP</span>;

In this example, we have one wordpressuser for each WordPress server, so we will revoke the insert, update, and delete privileges from each of them (“wordpress” is the name of our database in this example):

REVOKE INSERT, UPDATE, DELETE ON <span class=“highlight”>wordpress</span>.* FROM ’<span class=“highlight”>wordpressuser</span>’@’<span class=“highlight”>wordpress1privateIP</span>’;
REVOKE INSERT, UPDATE, DELETE ON <span class=“highlight”>wordpress</span>.* FROM ’<span class=“highlight”>wordpressuser</span>’@’<span class=“highlight”>wordpress2privateIP</span>’;

Now your MySQL replication setup is complete. Let’s move on to setting up WordPress to use both database servers properly.

Install and Configure HyperDB

We will use HyperDB to determine where to send updates (your master database) and read requests (your master and slave). Let’s download it to your home directory from the WordPress Plugin Directory (also install zip/unzip to unarchive it):

cd ~; wget sudo apt-get install zip unzip

It should be unarchived to a directory called “hyperdb”, in your home directory. Copy the sample configuration file to your WordPress installation (substitute the highlighted with your WordPress installation path), and open it for editing:

cp ~/hyperdb/db-config.php <span class=“highlight”>/var/www/</span>/
vi <span class=“highlight”>/var/www/</span>/db-config.php </pre>

Look for the second occurrence of DB_HOST, which should be directly after some comments that describe setting up a slave and it should look exactly like the following:

'host’ => <span class=“highlight”>DBHOST</span>, // If port is other than 3306, use host:port.
'user’ => DBUSER,
'password’ => DBPASSWORD,
'name’ => DB_NAME,
'write’ => 0, 'read’ => 1, 'dataset’ => 'global’, 'timeout’ => 0.2, )); </pre>

The first occurrence of DBHOST defines the master database server, and the second occurrence defines the slave database server (denoted by the 'write' => 0,). Replace the second occurrence of `DBHOSTwithDBSLAVE1`:

'host’ => <span class=“highlight”>DBSLAVE1</span>, // If port is other than 3306, use host:port.

Save and exit. Next you will want to define DB_SLAVE_1 in your wp-config.php, which HyperDB will use as a slave database host. Open wp-config.php for editing:

vi <span class=“highlight”>/var/www/</span>/wp-config.php

Find the line that defines DB_HOST and add the following line under it, substituting your slave’s private IP address (mysql-2):

define('DBSLAVE1’, ’<span class=“highlight”>mysql2private_IP</span>’);

Then save and exit.

Finish the HyperDB installation by copying the db.php file to the wp-content directory in your WordPress installation, then disabling write access to it:

cp ~/hyperdb/db.php <span class=“highlight”>/var/www/</span>/wp-content/</span>
sudo chmod a-w <span class=“highlight”>/var/www/</span>/wp-content/db.php </pre>

Then update the ownership of your wordpress files to their appropriate values (in this tutorial, we have been using www-data for the user/group ownership):

sudo chown -R www-data:www-data <span class=“highlight”>/var/www/</span>/

Now your WordPress read requests will be served by both your master and slave databases, while updates will be sent to your master (which will then be replicated to your slave).


Now that you have completed your MySQL replication and HyperDB setup, your database environment will be able to handle increased read traffic i.e. more concurrent users! Remember that you can add more MySQL slaves if you want to scale your database serving capacity even more.

<div class=“author”>By Mitchell Anicas</div>

블로그 이미지



댓글을 달아 주세요

you can use

fuser -n tcp -k 9001

see more details in wikipedia


fuser (Unix) - Wikipedia

The Unix command fuser is used to show which processes are using a specified computer file, file system, or Unix socket. Example[edit] For example, to check process IDs and users accessing a USB drive: $ fuser -m -u /mnt/usb1 /mnt/usb1: 1347c(root) 1348c(g



fuser library 는 CentOS 에서는 이름이 다르다. 없다면 psmisc 로 package 를 설치하자

블로그 이미지



댓글을 달아 주세요

Use "sshpass" non-interactive ssh password provider utility

On Ubuntu

 sudo apt-get install sshpass

Command to rsync

/usr/bin/rsync -ratlz --rsh="/usr/bin/sshpass -p password ssh -o StrictHostKeyChecking=no -l username" src_path  dest_path

블로그 이미지



댓글을 달아 주세요

* 이 포스팅은 네이버 블로그에서 작성(2013.04.01)한 내용을 옮겨온 것입니다.

오늘은 리눅스 크론탭에 대해 알아볼까 합니다. 음, 윈도우에서는 스케줄러와 비슷하다고 보면 되겠네요.

"특정 시간에 특정 작업을 해야한다."

라고 한다면 크론탭을 사용해 편하게 리눅스를 사용하실 수 있습니다.

1. 크론탭 기본 (crontab basic)

일단 기본이 되는 크론탭 사용법을 한 번 볼까요. 리눅스 쉘에서 다음처럼 입력합니다.

$ crontab -e

그러면 뭔가 편집할 수 있는 곳이 로딩됩니다. 이곳이 바로 크론탭을 설정할 수 있는 장소이죠. 여기에 각종 크론탭 명령어를 입력후 콜론(:) 입력 후에 wq 를 입력해 크론탭을 갱신시킵시다.

반대로 현재 크론탭에 어떤 내용이 들어있는지 보려면 다음처럼 입력하세요.

$ crontab -l

그러면 cat 명령어로 파일을 읽어들인 것처럼 표준 출력으로 크론탭 내용이 나오게 됩니다. 그런데 만약(거의 없겠지만) 크론탭을 지우고 싶다면?

리눅스 쉘에 다음처럼 입력합니다.

$ crontab -r

이렇게까지 하면 크론탭의 기본 설정 및 확인, 삭제에 대해 배운 것입니다. 그러면 실제로 크론탭에 크론 하나를 예제로 등록 해봅시다.

다음처럼 crontab -e 입력 후 다음과 같은 내용을 입력합시다. 저장은 vi 처럼 콜론 (:) 입력 후 wq 로 갱신시켜주면 됩니다.

* * * * * ls -al

별이 다섯개나 있습니다. 그리고 뒤에는 명령어가 적혀 있네요. 이게 기본 사용법입니다. 물론 쉘스크립트 뿐만 아니라 리눅스 커맨드도 사용할 수 있습니다.여기서는 쉘스크립트를 사용하는 방법으로 설명하고 있습니다.

별이 다섯개 있는 경우엔 "매분마다 실행" 하는겁니다. 별이 지칭하는 것이 무엇인지 자세히 살펴봅시다. * 그 전에 위에 입력했던 크론잡은 다시 지우시기 바랍니다.

2. 주기 결정

*      *      *      *      * 분(0-59)  시간(0-23)  일(1-31)  월(1-12)   요일(0-7)

각 별 위치에 따라 주기를 다르게 설정 할 수 있습니다. 순서대로 분-시간-일-월-요일 순입니다. 그리고 괄호 안의 숫자 범위 내로 별 대신 입력 할 수 있습니다.

요일에서 0과 7은 일요일입니다. 1부터 월요일이고 6이 토요일입니다.

3. 주기별 예제

3.1. 매분 실행

# 매분 실행 * * * * * /home/script/

3.2. 특정 시간 실행

# 매주 금요일 오전 5시 45분에 를 실행 45 5 * * 5 /home/script/

3.3. 반복 실행

# 매일 매시간 0분, 20분, 40분에 를 실행 0,20,40 * * * * /home/script/

3.4. 범위 실행

# 매일 1시 0분부터 30분까지 매분 를 실행 0-30 1 * * * /home/script/

3.5. 간격 실행

# 매 10분마다 를 실행 */10 * * * * /home/script/

3.6. 조금 복잡하게 실행

# 5일에서 6일까지 2시,3시,4시에 매 10분마다 를 실행 */10 2,3,4 5-6 * * /home/script/

 주기 입력 방법엔 * , - / 을 이용하는 방법이 있습니다. 위에서 보셨듯이 각각의 특수기호가 하는 기능이 다르고 조합을 어떻게 하느냐에 따라 입맛대로 주기를 설정 할 수 있습니다.

4. 크론 사용 팁

4.1. 한 줄에 하나의 명령만 씁시다.

# 잘못된 예 * * * 5 5 /home/script/ # 잘된 예 * * * 5 5 /home/script/

4.2. 주석을 달아봅시다.

# 주석 # #--------------------# # 이것은 주석입니다. # #--------------------#

# 을 입력해서 그 뒤로 나오는 모든 문자를 주석 처리할 수 있습니다.

5. 크론 로깅 (cron logging)

크론탭을 사용해서 정기적으로 작업을 처리하는 것은 좋은데, 해당 처리 내역에 대해 로그를 남기고 싶을 때가 있을겁니다. 그럴때 다음처럼 한번 써봅시다.

* * * * * /home/script/ > /home/script/ 2>&1


위처럼 작성하면 매분마다 파일이 갱신 되어 작업 내용이 어떻게 처리 되었는지 알 수 있습니다. 만약 2>&1 을 제거하면 쉘스크립트에서 표준 출력 내용만 나옵니다. 2>&1은 이곳에서 확인합시다.

그런데, 이게 너무 자주 실행 되고 또한 지속적으로 로깅이 되야 해서 로그를 계속 남겨둬야 한다면 다음처럼 입력합니다.

* * * * * /home/script/ >> /home/script/ 2>&1

그러면 계속 로그가 누적이 되는 것을 확인 할 수 있을겁니다. 대신 로그가 과도하게 쌓이면 리눅스 퍼포먼스에 영향을 주므로 가끔씩 비워주거나 파일을 새로 만들어주는 센스가 필요합니다.

반대로 로그는 필요 없는 크론을 위해선 다음처럼 입력합니다.

* * * * * /home/script/ > /dev/null 2>&1

6. 크론탭 백업 (crontab backup)

자, 혹시라도 crontab -r 를 쓰거나 실수로 crontab 디렉토리를 날려버려서 기존 크론 내역들이 날아갔을때, 정말 황망할거 같은데 말이죠. 그러니 주기적으로 크론탭을 백업해 둡시다. 백업은 다음처럼 하는 방법이 있습니다.

crontab -l > /home/bak/crontab_bak.txt

크론탭 내용을 txt 파일로 만들어 저장해두는겁니다. 자, 이것도 자동화가 될 수 있을까요?

50 23 * * * crontab -l > /home/bak/crontab_bak.txt

처럼 하면 되겠죠? 매일 오후 11시 50분에 크론탭을 백업해두는 크론 명령어입니다. :)

간단하게 크론탭에 대해 알아봤습니다. 혹시 추가해야 될 내용이나 실제와 다른 부분이 있다면 댓글 부탁드립니다.

블로그 이미지



댓글을 달아 주세요

블로그 이미지



댓글을 달아 주세요



CentOS 7 Light Package no included in fuser library package. 


# yum -y install psmisc
# fuser -k 80/tcp

fuser 로 Nginx 에서 기본적으로 잡고있던 80과 443을 다 죽이고 난 후에 

nginx 를 restart 하면 trouble shooting 완료




[emerg]: bind() to failed (98: Address already in use)


If you get following error, when you try to start nginx…

[emerg]: bind() to failed (98: Address already in use)

Then it means nginx or some other process is already using port 80.


You can kill it using:


sudo fuser -k 80/tcp


And then try restarting nginx again:


service nginx start

블로그 이미지



댓글을 달아 주세요



Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.


Want to improve this question? Update the question so it's on-topic for Stack Overflow.

Closed 6 years ago.

Improve this question

I am having trouble copying files from a remote server using SSH. Using PuTTY I log in to the server using SSH. Once I find the file I would like to copy over to my computer, I use the command:

scp \local\dir\

It looks like it was successful, but it only ends up creating a new folder labeled 'localdir' in the remote directory /dir/of/.

How can I copy the file to my local computer over SSH?



Improve this question


edited Oct 5 '18 at 18:04


17k20 gold badges95 silver badges175 bronze badges

asked May 31 '15 at 3:07


1,0432 gold badges8 silver badges6 bronze badges

Add a comment

5 Answers




It depends on what your local OS is.

If your local OS is Unix-like, then try:

scp username@remoteHost:/remote/dir/file.txt /local/dir/

If your local OS is Windows ,then you should use pscp.exe utility. For example, below command will download file.txt from remote to D: disk of local machine.

pscp.exe username@remoteHost:/remote/dir/file.txt d:\

It seems your Local OS is Unix, so try the former one.

For those who don't know what pscp.exe is and don't know where it is, you can always go to putty official website to download it. And then open a CMD prompt, go to the pscp.exe directory where you put it. Then execute the command as provided above


Improve this answer


edited May 31 '15 at 4:15


answered May 31 '15 at 3:23


15.8k11 gold badges43 silver badges63 bronze badges

  • My local OS is Windows. I downloaded the pscp.exe from the putty website. I tried opening it up and nothing came up. Also, I tried the command you listed above and was given: pscp.exe comman not found. Also tried it without the .exe and resulted in the same error. – Vincent May 31 '15 at 3:57 
  • 2
  • Open a CMD prompt, and go to the pscp.exe directory where you put it. Then execute the command as provided above. – mainframer May 31 '15 at 4:01 
  • 1
  • using scp on a mac has to be provided ./ parameter to signify that the file has to be downloaded in the current folder on mac machine. – Sarang Manjrekar Jul 2 '18 at 11:11
  • 2
  • With Windows Subsystem for Linux (WSL, basically Ubuntu on Windows) you can now also open up Bash if your Local OS is Windows, and just use scp. Pro-tip: you can access your Windows file system from WSL. It's under /mnt/c. So you can do something like this: scp username@remoteHost:/remote/dir/file.txt /mnt/c – gijswijs Apr 25 '19 at 3:42 
  • 3
  • As of the 2018 Autumn update, Windows 10 now comes with OpenSSH and is on PATH. This means you can use the scp command on Windows 10, too. – jaunt Sep 23 '19 at 20:45

Show 1 more comment

블로그 이미지



댓글을 달아 주세요