Joab vs Abner
Joab vs.Amasa

Who was Abner, and why did Joab murder him?

Abner had been King Saul's chief army officer. After Saul was killed in battle against the Philistines, Abner supported Saul's son, Ishbosheth, as the next king of Israel, against David. In the battle between Ishbosheth vs. David, Joab's brother, Asahel, specifically targeted Abner. Abner killed Joab's brother in self defense.

However, Abner saw that Ishbosheth was an ineffective leader. And after the two of them had an argument, Abner switched his loyalty to David. Abner met privately with David to insure that other leaders of Israel joined him in supporting David as king.

However, Joab did not trust Abner. So after Abner left his meeting with David, Joab caught up with Abner, and killed him in revenge for the death of Joab's own brother. This assassination also insured that Abner, with is superior military experience, could not replace Joab as David's commanding officer.

When David heard about it, he declared, "I vow by the LORD that I and my people are innocent of this crime against Abner. Joab and his family are the guilty ones. (2 Samuel 3:28-29)
David grieved publicly and wrote a psalm in honor of Abner.
"Should Abner have died as fools die?
Your hands were not bound;
    your feet were not chained.
No, you were murdered—
    the victim of a wicked plot." (2 Samuel 3:33-34)

Then King David said to the people, "Do you not realize that a great leader and a great man has fallen today in Israel?" (2 Samuel 3:38)

Who was Amasa, and why did Joab murder him?

Amasa was Joab's cousin, who also had military experience. Amasa had joined with Absalom's rebellion against David, serving as Absalom's chief officer. After the Absalom revolt failed, David recruited Amasa to replace Joab as David's chief officer. But Amasa took too long in doing what David command. So, in urgency, David reassigned the task to Joab's other brother, Abishai. While Abishai and Joab were on their way to carry out David's order, they met Amasa who was on his way back to David. Joab faked a friendly greeting, while he stabbed Amasa to death. (2 Samuel 19 and 20)

Again, Joab's motive for assassinating Amasa was to avenge Amasa's earlier disloyalty in joining Absalom's rebellion, and to eliminate Amasa as a rival to Joab's position as David's chief officer.

After Abner's death, David said,

"And even though I am the anointed king, these two sons of Zeruiah—Joab and Abishai—are too strong for me to control. So may the LORD repay these wicked men for their wicked deeds." (2 Samuel 3:39)
Now that David was near his time to die, he assigned the tasked of punishing Joab to his son Solomon.
"Do with him what you think best, but don’t let him die in peace." (1 Kings 2:6)
After David died, Adonijah began maneuvering to lead a another revolt. Solomon had promised Adonijah could live, as long as " he proves himself to be loyal" (1 Kings 1:52). But, because Adonijah had violated the conditions of his parole, Solomon ordered his execution. When Joab heard the news, he feared for his life.
1 Kings 2:28-35 (New Living Translation)
    Although he had not followed Absalom earlier, Joab had also joined Adonijah’s revolt. When Joab heard about Adonijah’s death, he ran to the sacred tent of the Lord and caught hold of the horns of the altar. When news of this reached King Solomon, he sent Benaiah son of Jehoiada to execute him.
    Benaiah went into the sacred tent of the Lord and said to Joab, "The king orders you to come out!"
    But Joab answered, "No, I will die here."
    So Benaiah returned to the king and told him what Joab had said.
    "Do as he said," the king replied. "Kill him there beside the altar and bury him. This will remove the guilt of his senseless murders from me and from my father’s family. Then the Lord will repay him for the murders of two men who were more righteous and better than he. For my father was no party to the deaths of Abner son of Ner, commander of the army of Israel, and Amasa son of Jether, commander of the army of Judah. May Joab and his descendants be forever guilty of these murders, and may the Lord grant peace to David and his descendants and to his throne forever."
    So Benaiah son of Jehoiada returned to the sacred tent and killed Joab, and Joab was buried at his home in the wilderness. Then the king appointed Benaiah to command the army in place of Joab, and he installed Zadok the priest to take the place of Abiathar.
Solomon allowed Abiathar the priest to live, in spite of his conspiracy with Adonijah. Solomon banished him from Jerusalem and from his service as priest at the Tabernacle.

Who was Barzillai?

2 Samuel 17:24-29
…Absalom had mobilized the entire army of Israel [against David] and was leading his troops across the Jordan River. Absalom had appointed Amasa as commander of his army, replacing Joab, who had been commander under David...
David fled Jerusalem with a few loyal supporters and the rest of his family.
When David arrived at Mahanaim, he was warmly greeted by Shobi son of Nahash of Rabbah, an Ammonite, and by Makir son of Ammiel of Lo-debar, and by Barzillai of Gilead from Rogelim. They brought sleeping mats, cooking pots, serving bowls, wheat and barley flour, roasted grain, beans, lentils, honey, butter, sheep, and cheese for David and those who were with him. For they said, "You must all be very tired and hungry and thirsty after your long march through the wilderness."
After Absalom's defeat and death, David and his family returned to Jerusalem. On the way they again met people who had helped him earlier.
2 Samuel 19:31-40
    Barzillai of Gilead now arrived from Rogelim to conduct the king across the Jordan. He was very old, about eighty, and very wealthy. He was the one who had provided food for the king during his stay in Mahanaim.  "Come across with me and live in Jerusalem," the king said to Barzillai. "I will take care of you there."
    "No," he replied, "I am far too old for that. I am eighty years old today, and I can no longer enjoy anything. Food and wine are no longer tasty, and I cannot hear the musicians as they play. I would only be a burden to my lord the king. Just to go across the river with you is all the honor I need! Then let me return again to die in my own town, where my father and mother are buried. But here is my son Kimham. Let him go with you and receive whatever good things you want to give him."
    "Good," the king agreed. "Kimham will go with me, and I will do for him whatever I would have done for you." So all the people crossed the Jordan with the king. After David had blessed and embraced him, Barzillai returned to his own home. The king then went on to Gilgal, taking Kimham with him. All the army of Judah and half the army of Israel escorted him across the river.

Who was Shimei?
He was a member of King Saul's family, who resented having David as king over Israel.

This story is also from the events in Absalom's rebellion. David was fleeing from Jerusalem from his son Absalom and his army.

2 Samuel 17:5-14
    As David and his party passed Bahurim, a man came out of the village cursing them. It was Shimei son of Gera, a member of Saul’s family. He threw stones at the king and the king’s officers and all the mighty warriors who surrounded them. "Get out of here, you murderer, you scoundrel!" he shouted at David. "The Lord is paying you back for murdering Saul and his family. You stole his throne, and now the Lord has given it to your son Absalom. At last you will taste some of your own medicine, you murderer!"
    "Why should this dead dog curse my lord the king?" Abishai son of Zeruiah demanded. "Let me go over and cut off his head!"
    "No!" the king said. "What am I going to do with you sons of Zeruiah! If the Lord has told him to curse me, who am I to stop him?" Then David said to Abishai and the other officers, "My own son is trying to kill me. Shouldn’t this relative of Saul have even more reason to do so? Leave him alone and let him curse, for the Lord has told him to do it. And perhaps the Lord will see that I am being wronged and will bless me because of these curses." So David and his men continued on, and Shimei kept pace with them on a nearby hillside, cursing as he went and throwing stones at David and tossing dust into the air.
    The king and all who were with him grew weary along the way, so they rested when they reached the Jordan River.
Because David was so depressed and tired, it seems that David held no resentment against Shimei.

When David returned to Jerusalem after Absalom's defeat, Shimei met David again, begging for forgiveness.

    As the king was about to cross the river, Shimei fell down before him. "My lord the king, please forgive me," he pleaded. "Forget the terrible thing I did when you left Jerusalem. I know how much I sinned. That is why I have come here today, the very first person in all Israel to greet you."
    Then Abishai son of Zeruiah said, "Shimei should die, for he cursed the Lord’s anointed king!"
    "What am I going to do with you sons of Zeruiah!" David exclaimed. "This is not a day for execution but for celebration! I am once again the king of Israel!" Then, turning to Shimei, David vowed, "Your life will be spared."
Again, it appears that David had forgiven Shimei. But many years later, David instructs Solomon, as the new king, to punish Shimei
"I swore by the Lord that I would not kill him. But that oath does not make him innocent. You are a wise man, and you will know how to arrange a bloody death for him." (1 Kings 2:8-9)
As he did with Adonijah, Solomon put Shimei on probation. Shimei was safe as long as he stayed in Jerusalem.
    The king then sent for Shimei and told him, "Build a house here in Jerusalem and live there. But don’t step outside the city to go anywhere else. On the day you cross the Kidron Valley, you will surely die; your blood will be on your own head."
    Shimei replied, "Your sentence is fair; I will do whatever my lord the king commands." So Shimei lived in Jerusalem for a long time.
    But three years later, two of Shimei’s slaves escaped to King Achish of Gath. When Shimei learned where they were, he saddled his donkey and went to Gath to search for them. When he had found them, he took them back to Jerusalem.
    Solomon heard that Shimei had left Jerusalem and had gone to Gath and returned. So he sent for Shimei and demanded, "Didn’t I make you swear by the LORD and warn you not to go anywhere else, or you would surely die? And you replied, ‘The sentence is fair; I will do as you say.’ Then why haven’t you kept your oath to the LORD and obeyed my command?"
    The king also said to Shimei, "You surely remember all the wicked things you did to my father, King David. May the LORD punish you for them. But may I receive the LORD’s rich blessings, and may one of David’s descendants always sit on this throne." Then, at the king’s command, Benaiah son of Jehoiada took Shimei outside and killed him.
It's not a pretty story. I believe it is fair to question both David's and Solomon's motives in the way they arranged for Simei's death. It appears that bitterness and politics, not justice and mercy, were at work.