It appears more drastic in person. This deck railing is leaning inward, and I'm wondering how one might go about leveling it up? Willing to replace 4x4 supports if necessary. The posts towards the middle of the deck slant the most, but it is very inconsistent overall.
If you were to replace all the lag bolts, you could play around with plumb by shimming the top or bottom of the post where it sits on the rim joist. Be sure to use galvanized bolts (and healthy sized washers on both ends) that go all the way through the post and the rim joist.
A very big caveat: this might have met code where you are, but a 2x4 post -- especially an old one -- isn't the sturdiest. The IRC requires that a railing can withstand a 200 pound load in any direction. I would think seriously about replacing the posts with 4x4s securely bolted to the rim.
That does not look very sturdy. The bolted piece seems short compared to the fence. If a big guy (or 2) with a beer in his hand leaned against the top of this it would put a lot of leverage on those 2 bolts on the short side. I worry your leaning fence might be from something like this that has already happened.
You would need to take the fence down and put it back up but you could use the same wood except for longer bolted supports. Instead of the short 2x4 with the 2 bolts that attaches just to the joist, align the new bolted supports for the fence with the big 4x4 pillars below. Run the fence support down a length at least equal to the height of the fence. You could attach each support at 2 or 3 points to the pillar. It would be a lot sturdier and a good look.
Those look like 4x4 posts with the base chamfered to fit over the rim, and lag bolted to it. My deck is constructed exactly the same way, but for extra support I used Ties (https://www.lowes.com/pd/USP-1-13-16-in-x-2-1-4-in-14-Gauge-Triple-Zinc-Deck-Tie/3376812) on the top lag bolt (either 1/2" lag bolts or 5/8", I don't recall). This requires an adjacent joist to attach the tie, so I spaced the posts accordingly (making sure not to exceed the maximum rail span). This meets code in my area.
I don't clearly see a "lean" from your pictures, but if you perceive a lean or especially if they feel loose, you can replace the posts and secure them differently. Most newer decks are constructed with interior posts that fit into the corner of a joist and the rim joist and are bolted or screwed (structural/lag screws) to each member. This gives them much more strength but decreases the useful area of your deck since the rail sits inside the rim. You'd just have to remove 2-3 outer deck boards for access to the joists and then cut the decking to fit when reinstalling. Depending on spacing, you may end up replacing the rails between posts as well. I found a guide here: https://www.decks.com/how-to/248/deck-rail-post-attachment