options = {
'auth_pass': nconf.get('redis_pass')[nodeEnv],
'no_ready_check': true,
};
redis-cli
๋๊ตฌ๋ฅผ ์ฌ์ฉํ์ฌ redis์ ์ฐ๊ฒฐํ๋ฉด ์ ๋๋ก ์๋ํ์ง๋ง ์ด๋ค ์ด์ ๋ก ์ธํด ์ด ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค.
29 Jun 2018 11:06:14.626136 <190>1 2018-06-29T18:06:14.346750+00:00 app web.1 - - ReplyError: NOAUTH Authentication required
at new Command (/app/node_modules/redis/lib/command.js:12:22)
at RedisClient.info (/app/node_modules/redis/lib/individualCommands.js:169:39)
at RedisClient.ready_check (/app/node_modules/redis/index.js:534:10)
at RedisClient.on_connect (/app/node_modules/redis/index.js:428:14)
at Socket.<anonymous> (/app/node_modules/redis/index.js:268:14)
at Object.onceWrapper (events.js:313:30)
at emitNone (events.js:111:20)
at Socket.emit (events.js:208:7)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1173:10)Exception
options
๊ฐ์ฒด๋ง์ผ๋ก๋ ๊ตฌ๋ถํ๊ธฐ ์ด๋ ต์ง๋ง ์ด๊ฒ์ ๊ฝค ํ์ค์ ์ด๊ณ ์ข์ ๊ฒ์ผ๋ก ์๋ ค์ ธ ์์ต๋๋ค. ๋น์ ์ด ์๋ชป๋ redis ์๋ฒ์ ์ฐ๊ฒฐํ๊ณ ์๊ฑฐ๋ nconf.get('redis_pass')[nodeEnv]
๊ฐ ์๋ชป๋ ๋น๋ฐ๋ฒํธ(๋๋ ์ ์๋์ง ์์)๋ฅผ ์ ๊ณตํ๊ณ ์์ ์ ์์ต๋๋ค.
๋ ๋ง์ ์ฝ๋๋ฅผ ์ ๊ณตํ ์ ์์ต๋๊น?
์๋ ํ์ธ์, ์ ๋ ๊ฐ์ ๋ฌธ์ ๊ฐ ์๊ณ ์ํธ๋ฅผ ์ผ๋ฐ ํ ์คํธ๋ก ์ ๋ฌํ๋๋ฐ ์ฌ์ ํ ๋์ผํ ์ค๋ฅ๊ฐ ํ์๋ฉ๋๋ค. ์ฌ์ค ๋ค์ ์ฝ๋์์ ๋ณผ ์ ์๋ฏ์ด ๊ธฐ๋ณธ redis.conf ํ์ผ์์ requirepass ๋ผ์ธ์ ์ฃผ์ ์ฒ๋ฆฌ๋ง ์ ๊ฑฐํฉ๋๋ค.
# use a very strong password otherwise it will be very easy to break.
#
requirepass foobared
# Command renaming.
ํ ์คํธ๋ฅผ ์ํด ๋ก์ปฌ ์ปดํจํฐ์์ ์ด ๊ตฌ์ฑ์ ์ํํ์ง๋ง ์ฌ์ ํ ๋์ผํ ์ค๋ฅ๊ฐ ๋ฐ์ํฉ๋๋ค.
events.js:160
throw er; // Unhandled 'error' event
^
ReplyError: Ready check failed: NOAUTH Authentication required.
at parseError (/home/mauricio/Documents/lisapp/pos_lisa/node_modules/redis/node_modules/redis-parser/lib/parser.js:193:12)
at parseType (/home/mauricio/Documents/lisapp/pos_lisa/node_modules/redis/node_modules/redis-parser/lib/parser.js:303:14)
๋ค์์ ๋ด nodejs ์๋ฒ์ ์ ์ฉํ ์ฝ๋์ ๋๋ค.
const redisPassword = "foobared" ;
const ClientRedisApi = redis.createClient({
host : '127.0.0.1',
no_ready_check: true,
auth_pass: redisPassword,
});
ClientRedisApi.on('connect', () => {
global.console.log("connected");
})
ClientRedisApi.on('error', err => {
global.console.log(err.message)
})
ClientRedisApi.set("foo", 'bar');
ClientRedisApi.get("foo", function (err, reply) {
global.console.log(reply.toString())
})
์ฌ๋ฏธ์๋ ์ ์ ์๋ฒ๋ฅผ ์์ํ ๋ "foo" ํค๊ฐ "bar" ๊ฐ์ผ๋ก redis ๋ฐ์ดํฐ๋ฒ ์ด์ค์ ์ ์ฅ๋์ง๋ง ์ฑ์ด ์ถฉ๋ํ๊ณ ์ํธ ์์ฉํ๊ธฐ ์ํด ์๋ฌด ๊ฒ๋ ํ ์ ์๋ค๋ ๊ฒ์ ๋๋ค.
์ฌ๊ธฐ ์๋ ๋ชจ๋ ์ฌ๋์๊ฒ. Linux ์์ ์ํธ ์์ฑ๊ธฐ์์ ์์ฑ๋ ๊ธด ์ํธ๋ฅผ ์ฌ์ฉํ๋ ค๊ณ ํ ๋๋ ๋์ผํ ๋ฌธ์ ๊ฐ ๋ฐ์ํ์ต๋๋ค. ์ํธ๋ฅผ ํจ์ฌ ๋ ์งง์ ๊ฒ์ผ๋ก ๋ณ๊ฒฝํ์ ๋ ๋ชจ๋ ๊ฒ์ด ์ ์๋ํ์ต๋๋ค. ์ด Node.JS ํจํค์ง ์์ฒด์ ๋ฌธ์ ๊ฐ ์์ ์ ์์ต๋๋ค. redis-cli ์ ๋ค์ด๊ฐ์ auth ๋ช ๋ น๊ณผ ํจ๊ป ์ฌ์ฉํ๋ฉด ๊ธด ์ํธ ๊ฐ ์๋ํ๊ธฐ ๋๋ฌธ์ ๋๋ค. ๊ทธ๋ฌ๋ ๋ด๊ฐ ์ฌ์ฉํ ๋ฉ์๋ ๋ณํ(์: ์ ์ฒด URL ๋๋ ์ต์ ๋ธ๋ก์ "auth_pass"/"password" ๋๋ redisClient.auth( ) ๋ฐฉ๋ฒ - ๊ธด ์ํธ๋ก ๋ชจ๋ ์คํจํ์ต๋๋ค).
์๋ ํ์ธ์ @roschler๋ , ์ฝ๋๋ฅผ ์ ๊ณตํด ์ฃผ์๊ฒ ์ต๋๊น? ์ฌ์ค์ ๊ทํ์ ์ ์์ ์๋ํ์ง๋ง '123'๊ณผ ๊ฐ์ ๋น๋ฐ๋ฒํธ๋ฅผ ์ฌ์ฉํ์ง ์์๋ ์ฌ์ ํ ๋์ผํ ๋ฌธ์ ๊ฐ ๋ฐ์ํ๋ค๋ ๊ฒ์ ๋๋ค. ๋๋ ๋ฌธ์์ ์๋ ๋ชจ๋ ๋ฐฉ๋ฒ์ ์๋ํ๊ณ ๋ค๋ฅธ ๊ฒ์ ์์ต๋๋ค. ์ด๊ฒ์ด ๋น์ ์ ๊ท์ฐฎ๊ฒ ํ ์ ์๋ค๋ ๊ฒ์ ์๊ณ ์์ง๋ง ์ฌ์ค์ ๋์๊ฒ ๋ค๋ฅธ ์ ํ์ ์ฌ์ง๊ฐ ์๋ค๋ ๊ฒ์ ๋๋ค. ๋ฏธ๋ฆฌ ๊ฐ์ฌ๋๋ฆฝ๋๋ค.
@maooricio ์ ๋ ์ด๊ฒ์ด ์๋ฒ ๋๋ ์๋ชป๋ ์๋ฒ์ ์๋ชป๋ ๊ตฌ์ฑ์ด๋ผ๊ณ 99.999% ํ์ ํฉ๋๋ค. 2018๋
10์์ ์ฝ๋๋ฅผ ๋ณด๋ฉด ๋ฌด์์๋ก ์์ฑ๋ ํค๋ฅผ ์ฌ์ฉํ๊ณ redis-cli
์์ MONITOR๋ก ์์ฝ๋ฅผ ์๋ํฉ๋๋ค.
@roschler ๋ ์์ ํ ๋ค๋ฅธ ๋ฌธ์ ๊ฐ ์๋ค๊ณ ์๊ฐํฉ๋๋ค(์ธ์ฉ?)
๋๋ ์ฌ์ ํ์ด ๋ฌธ์ ๊ฐ ๋ฐ์ํ์ต๋๋ค. redis db์ ์ฐ๊ฒฐํ๊ธฐ ์ํด ์ฌ๋ฌ ๊ฐ์ง ๋ค๋ฅธ ๋ฐฉ๋ฒ์ ์๋ํ์ง๋ง ์ฌ์ฉ์์ ๋ํ ์ํธ ์ธ์ฆ์ ์คํจํ์ต๋๋ค.
@nicolasmatheus ๋น์ ์ ์ค๋ฅ๋ ๋ฌด์์ ๋๊น?
๊ฐ์ ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค. ๋ชจ๋ ์ค์ ๋งค๊ฐ๋ณ์๊ฐ ์ ํํ๋ค๊ณ ํ์ ํฉ๋๋ค. ๋๋ 3 ๊ฐ์ง ๋ฐฉ๋ฒ์ ๋ชจ๋ ์๋ํ์ง๋ง ๋ชจ๋ ๋์ผํ ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค.
// First method
const client = redis.createClient(process.env.REDIS_PORT, process.env.REDIS_HOST);
client.auth(process.env.REDIS_PASSWORD);
// Second method
const client = redis.createClient(process.env.REDIS_PORT, process.env.REDIS_HOST, {
password: process.env.REDIS_PASSWORD
});
// Third method
const client = redis.createClient(uri)
NODE_DEBUG=redis
์ค์ ํ
[0] Sending auth to redis:6379 id 0
[0] Send redis:6379 id 0: *2
[0] $4
[0] auth
[0] $14
[0] mypassword
[0]
[0] Stream connected redis:6379 id 0
[0] Redis: CONNECTED // CUSTOM MESSAGE
[0] Checking server ready state...
[0] Send redis:6379 id 0: *1
[0] $4
[0] info
[0]
[0] Net read redis:6379 id 0
[0] Redis server ready.
[0] on_ready called redis:6379 id 0
[0] Redis: READY // CUSTOM MESSAGE
[0] Stream connected redis:6379 id 1
[0] Checking server ready state...
[0] Send redis:6379 id 1: *1
[0] $4
[0] info
[0]
[0] Net read redis:6379 id 1
[0]
[0] /app/node_modules/redis/lib/command.js:12
[0] this.error = new Error();
[0] ^
[0] ReplyError: NOAUTH Authentication required.
[0] at new Command (/app/node_modules/redis/lib/command.js:12:22)
[0] at RedisClient.info (/app/node_modules/redis/lib/individualCommands.js:169:39)
[0] at RedisClient.ready_check (/app/node_modules/redis/index.js:534:10)
[0] at RedisClient.on_connect (/app/node_modules/redis/index.js:428:14)
[0] at Socket.<anonymous> (/app/node_modules/redis/index.js:268:14)
[0] at Object.onceWrapper (events.js:299:28)
[0] at Socket.emit (events.js:215:7)
[0] at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1115:10)
[0] npm ERR! code ELIFECYCLE
๋์ปค ์์ฑ์ ์ฌ์ฉํ๊ณ ์์ต๋๋ค
redis:
container_name: redis
image: redis:5.0.3-alpine
restart: always
env_file: .env
command: ["redis-server", "--appendonly", "yes", "--requirepass", "${REDIS_PASSWORD}"]
hostname: ${REDIS_HOST}
volumes:
- ~/.mydata/redis:/data
ports:
- ${REDIS_PORT}:6379
networks:
- my-network
cli redis-cli -h 127.0.0.1 -p 6379 -a 'mypassword'
๋ฅผ ์ฌ์ฉํ์ฌ redis์ ์ก์ธ์คํ ์ ์์ต๋๋ค.
@thellimist ํนํ ๋ ๋ฒ์งธ ๋ฐฉ๋ฒ์ผ๋ก redis-cli
๋ฐ MONITOR
์์ ๋ฌด์จ ์ผ์ด ์ผ์ด๋๊ณ ์๋์ง ํ์ธํ์ญ์์ค.
@stockholmux
export default class Cache {
static client: any
static init(): Promise<any> {
if (Cache.client) {
logger.error("Client already exists")
return new Promise((resolve, reject) => { reject() });
}
const client = redis.createClient(process.env.REDIS_PORT, process.env.REDIS_HOST, {
password: process.env.REDIS_PASSWORD
});
Cache.client = asyncRedis.decorate(client);
Cache.client.monitor(function (err, res) {
logger.info("Entering monitoring mode.");
});
Cache.client.set('foo', 'bar');
Cache.client.on("ready", (e: any) => {
logger.info(`ready ${e}`);
});
Cache.client.on("reconnecting", (e: any) => {
logger.info(`reconnecting ${e}`);
});
Cache.client.on("end", (e: any) => {
logger.info(`end ${e}`);
});
Cache.client.on("warning", (e: any) => {
logger.info(`warning ${e}`);
});
Cache.client.on("monitor", (e: any, res: any) => {
logger.error(`monitor err: ${e}`);
logger.info(`monitor res: ${res}`);
});
Cache.client.on("connect", () => {
logger.info("connected");
});
Cache.client.on("error", (e: any) => {
logger.error(`Error: :${e}`);
});
return new Promise((resolve, reject) => { resolve() }
}
await Cache.init()
์ ํธ์ถํฉ๋๋ค. ์๋ต์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
[0] Sending auth to redis:6379 id 0
[0] Send redis:6379 id 0: *2
[0] $4
[0] auth
[0] $14
[0] mypassword
[0]
[0] Queueing monitor for next server connection.
[0] Queueing set for next server connection.
[0] Stream connected redis:6379 id 0
[0] 2019-12-17 06:49:48 error [server.ts]: connected
[0] Checking server ready state...
[0] Send redis:6379 id 0: *1
[0] $4
[0] info
[0]
[0] Net read redis:6379 id 0
[0] Redis server ready.
[0] on_ready called redis:6379 id 0
[0] Sending offline command: monitor
[0] Send redis:6379 id 0: *1
[0] $7
[0] monitor
[0]
[0] Sending offline command: set
[0] Send redis:6379 id 0: *3
[0] $3
[0] set
[0] $3
[0] foo
[0] $3
[0] bar
[0]
[0] 2019-12-17 06:49:48 info [server.ts]: ready undefined
[0] Net read redis:6379 id 0
[0] 2019-12-17 06:49:48 info [server.ts]: Entering monitoring mode.
[0] 2019-12-17 06:49:48 error [server.ts]: monitor err: 1576565388.385183
[0] 2019-12-17 06:49:48 info [server.ts]: monitor res: set,foo,bar
[0] Stream connected redis:6379 id 1
[0] Checking server ready state...
[0] Send redis:6379 id 1: *1
[0] $4
[0] info
[0]
[0] Net read redis:6379 id 1
[0]
[0] /app/node_modules/redis/lib/command.js:12
[0] this.error = new Error();
[0] ^
[0] ReplyError: NOAUTH Authentication required.
[0] at new Command (/app/node_modules/redis/lib/command.js:12:22)
[0] at RedisClient.info (/app/node_modules/redis/lib/individualCommands.js:169:39)
[0] at RedisClient.ready_check (/app/node_modules/redis/index.js:534:10)
[0] at RedisClient.on_connect (/app/node_modules/redis/index.js:428:14)
[0] at Socket.<anonymous> (/app/node_modules/redis/index.js:268:14)
[0] at Object.onceWrapper (events.js:299:28)
[0] at Socket.emit (events.js:215:7)
[0] at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1115:10)
๋ํ key/val "foo: bar"๊ฐ redis์ ์ถ๊ฐ๋ฉ๋๋ค. ๋ฐ๋ผ์ ์ฒ์์๋ ์ฌ๋ฐ๋ฅด๊ฒ ์ฐ๊ฒฐํ ๋ค์ ์ด๋ค ์ด์ ๋ก ๋ค์ ์ฐ๊ฒฐ์ ์๋ํ์ง๋ง ์คํจํฉ๋๋ค. ๋๋ Express server.listen์์ await Cache.init()
๋ฅผ ํ ๋ฒ๋ง ํธ์ถํฉ๋๋ค.
@thellimist ๋๋ ๋น์ ์ด ์๋ชป ์ดํดํ๊ณ ์๋ค๊ณ ์๊ฐํฉ๋๋ค. ์ด๋ฌํ ๋ฌธ์ ๋ฅผ ์ฌ๋ฐ๋ฅด๊ฒ ์ง๋จํ๋ ค๋ฉด MONITOR
_from_ redis-cli
์ ์คํํด์ผ ํฉ๋๋ค. ์์ ๊ฐ์ด ์ ํ๋ฆฌ์ผ์ด์
๋ด์์ ์คํํ๋ฉด ์ธ์ฆ์ ์บก์ฒํ์ง ์์ต๋๋ค(๋ชจ๋ํฐ ์ด์ ์ ๋ฐ์ํ๊ธฐ ๋๋ฌธ์). ๋๋ ๋ํ ์์ ํ ํ๋ฌ์ ๋ DB์์ ์คํํ ๊ฒ์
๋๋ค.
์ด์จ๋ , ์ฝ๋๋ฅผ ๋ณด๋ฉด(์ค๋ํซ์ด๋ผ๊ณ ๊ฐ์ ํจ) ์ฝ๋์ ๋ค๋ฅธ ๊ณณ์์ ์ ์ ํ ์ํธ ์์ด redis.createClient
๋ฅผ ํธ์ถํ๋ ๊ฒ์ฒ๋ผ ๋ณด์
๋๋ค(๋ค๋ฅธ ๋ชจ๋์ผ ์๋ ์์). ์ฌ์ฐ๊ฒฐ์ ๋ํ ๋๋ฒ๊ทธ ๋ก๊ทธ๊ฐ ํ์๋์ง ์๊ณ id 1
์ ๋ค๋ฅธ ๋คํธ์ํฌ ์คํธ๋ฆผ์์ ์์
์ค์ด๋ผ๊ณ ํ์๋ฉ๋๋ค.
@stockholmux
๋ฌธ์ ๋ ๋น์ ์ด ๋งํ๋ฏ์ด ๊ฐ๋จํ์ต๋๋ค. ๋๋ typeorm ํจํค์ง๋ฅผ ์ฌ์ฉํ๊ณ ์์๊ณ js/ts ํ์ผ์ ์๋ ๋ค๋ฅธ ๊ตฌ์ฑ ํ์ผ์ ๊ฐ์ง๊ณ ์์์ต๋๋ค. Node Redis ๋ก๊ทธ๊ฐ ํธ์ถ๋ ์์น๋ฅผ ์๋ ค์ฃผ์ง ์์ ์ฐพ๊ธฐ๊ฐ ์ด๋ ค์ ์ต๋๋ค.
๊ฐ์ฌ ํด์.
Docker๋ฅผ ์ฌ์ฉํ๋ ๊ฒฝ์ฐ redis.conf์ ํ์ผ ๋คํธ์ํฌ ์ค์ ์ ํธ์งํฉ๋๋ค.
bind 0.0.0.0
๊ทธ๊ฒ์ ๋๋ฅผ ์ํด ๊ทธ๊ฒ์ ๊ณ ์ณค๋ค.
@mariothedev ๋ ๊ทธ๊ฒ์ ๋ํด ๋งค์ฐ ์กฐ์ฌํ์ญ์์ค. ์ ์ ํ ๋ฐฉํ๋ฒฝ์ด ์์ผ๋ฉด ํด๋น bind
์ค์ ์ ์ฌ์ฉํ์ฌ redis๊ฐ ํ์ง ์ด๋ฆฝ๋๋ค.
@stockholmux - ์๋ ค์ฃผ์ ์ ๊ฐ์ฌํฉ๋๋ค :)
๋๋ ๋ํ ์ฌ๊ธฐ์์ด ๋ฌธ์ ๊ฐ ์์ต๋๋ค.
์ค๋ฅ ๋ฉ์์ง: ReplyError: NOAUTH Authentication required.
๋ฒ์ : ๋ ธ๋ Redis 3.0.0 / Redis 5.0.8
๊ฐ์ ๋ฌธ์ ์ ๋ํ ๋ต์ ์ฐพ๊ธฐ ์ํด ์ด ์ค๋ ๋๋ฅผ ์ฐพ์์ต๋๋ค. ์ด์ ๋ํ ํด๊ฒฐ์ฑ ์ด ๋ฌด์์ธ์ง ๊ถ๊ธํฉ๋๋ค.
๋ชฉ๋ก์ ์ถ๊ฐํ ์ ์๋ ํด๊ฒฐ ๋ฐฉ๋ฒ์ด ํ๋ ๋ ์์ต๋๋ค. ์ด ์ค๋ฅ๊ฐ ๋ฐ์ํ๊ณ Redis ๊ธฐ๋ฐ ๋๊ธฐ์ด์ธ Bull ์ ์ฌ์ฉํ๊ณ ์์์ ๊ธฐ์ตํ๋ ๋ฐ ์ฐฝํผํ ์ ๋๋ก ์ค๋ ์๊ฐ์ด ๊ฑธ๋ ธ์ต๋๋ค. ๋ํ ์ฐ๊ฒฐ ์ ๋ณด๋ฅผ ์ ๋ฌํ์ง๋ง Bull์ ๋ํด ์์ด๋ฒ๋ ธ๊ณ ์ฝ์์์ ์ ํํ ์ด๋ฌํ ์ค๋ฅ๊ฐ ๋ฐ์ํ ์์ฉ ํ๋ก๊ทธ๋จ์ ๋ค๋ฅธ ๊ณณ์์ Redis๋ฅผ ์ฌ์ฉํ๊ณ ์์ต๋๋ค.
๋ฐ๋ผ์ ํ์ธํด์ผ ํ ๋ ๋ค๋ฅธ ์ฌํญ์ ์ฑ์ ๋ค๋ฅธ ํญ๋ชฉ์ด Redis๋ฅผ ์ฌ์ฉ ์ค์ด๊ณ ์ด๋ฌํ ์ค๋ฅ๋ฅผ ๋ค์ ์คํํ ์ ์๋์ง ์ฌ๋ถ์ ๋๋ค.
edit ์ด ์ค๋ฅ์ ์์ธ์ด Bull์ธ ๊ฒฝ์ฐ auth_pass
๊ฐ ์๋ redis ์ฐ๊ฒฐ ๊ฐ์ฒด์์ password
๋ฅผ ์ฌ์ฉํด์ผ ํฉ๋๋ค.
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
๋๋ ๋ํ ์ฌ๊ธฐ์์ด ๋ฌธ์ ๊ฐ ์์ต๋๋ค.
์ค๋ฅ ๋ฉ์์ง:
ReplyError: NOAUTH Authentication required.
๋ฒ์ : ๋ ธ๋ Redis 3.0.0 / Redis 5.0.8