If the current ratio of red to blue to green socks is 2:3:7, then there are exactly 2x red socks, 3x blue socks and 7x green socks.
1. If amount of red socks are increased by n new socks, then there are exactly 2x+n red socks, 3x blue socks and 7x green socks and (2x+n):3x:7x=8:9:21. This means that 2x+n=8y, 3x=9y, 7x=21y. You have that x=3y and 6y+n=8y, n=2y.
2. If amount of blue socks are increased by n+2 new socks, then there are exactly 2x red socks, 3x+n+2 blue socks and 7x green socks and 2x:(3x+n+2):7x=2:4:7. This means that 2x=2t, 3x+n+2=4t, 7x=7t. Now you have that x=t and 3t+n+2=4t, n=t-2.
3. Solve x=3y, n=2y, x=t, n=t-2. You obtain that t=3y, t-2=2y. Then 3y-2=2y and y=2. Hence, x=6=t, n=6-2=4.
Answer: n=4